Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Operator board controls (#17)
Browse files Browse the repository at this point in the history
* operator board implemented

to do:
update button numbers

* updated button bindings

* Reassigned joystick mappings - Joseph An

* fix shooter subsys requirements - delaynie

* added button for reset climber

* formatting

Co-authored-by: delaynieym <[email protected]>
Co-authored-by: Delaynie McMillan <[email protected]>
Co-authored-by: --global <--global>
  • Loading branch information
3 people authored Sep 18, 2021
1 parent 401b048 commit c3b81e9
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 180 deletions.
22 changes: 19 additions & 3 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
*/
public final class Constants {

/**
* Port numbers for the buttons on the operator board.
*/
public static final class ControllerButtonPorts {
public static final int BUTTON_ONE = 1;
public static final int BUTTON_TWO = 2;
public static final int BUTTON_THREE = 3;
public static final int BUTTON_SIX = 6;
public static final int BUTTON_ELEVEN = 11;
public static final int BUTTON_TWELVE = 12;
public static final int BUTTON_THIRTEEN = 13;
public static final int BUTTON_FOURTEEN = 14;
}

/**
* Port numbers for any hardware relating to swerve modules.
*/
Expand All @@ -40,7 +54,7 @@ public static final class SwervePorts {
}

public static final class SwerveConstants {
//previously 3.627
// previously 3.627
public static final double MAX_SPEED_METERS_PER_SECOND = 3.0;
public static final double MAX_MODULE_ANGULAR_SPEED_RADIANS_PER_SECOND = 8.76;

Expand All @@ -58,7 +72,6 @@ public static final class SwerveConstants {
public static final double FRONT_RIGHT_ROTATION_OFFSET = 2.573;
public static final double BACK_RIGHT_ROTATION_OFFSET = 3.9;


// Gyro rotation rate deadzone
public static final double GYRO_RATE_DEADZONE = 0.05;
// TODO this value might need adjustment. copied from frc2020
Expand Down Expand Up @@ -93,7 +106,10 @@ public static final class IntakeConstants {
public static final int ARM_PORT = 24;
}

/** Servo positions for different climber states. Positions range between 0.0 (full left) and 1.0 (full right). */
/**
* Servo positions for different climber states. Positions range between 0.0
* (full left) and 1.0 (full right).
*/
public static final class ClimberConstants {
public static final double WINCH_RELEASE_SERVO_POSITION = 0.0;
public static final double WINCH_LOCK_SERVO_POSITION = 0.5;
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/frc/robot/HardwareMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import com.ctre.phoenix.motorcontrol.can.VictorSPX;
import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
import com.revrobotics.CANEncoder;

import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;

import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.SpeedControllerGroup;

import edu.wpi.first.wpilibj.XboxController;
import frc.robot.subsystems.SwerveModule;

Expand All @@ -22,15 +19,13 @@ public class HardwareMap {
*/
public class InputHardware {
public XboxController driveController;
public XboxController operatorController;

// public OperatorBoard operatorBoard;
// public XboxController operatorController;
public OperatorBoard operatorBoard;

public InputHardware() {
driveController = new XboxController(0);
operatorController = new XboxController(1);

// operatorBoard = new OperatorBoard(1);
// operatorController = new XboxController(1);
operatorBoard = new OperatorBoard(1);
}
}

Expand Down Expand Up @@ -203,5 +198,4 @@ public HardwareMap() {
intakeHardware = new IntakeHardware();
climberHardware = new ClimberHardware();
}

}
33 changes: 17 additions & 16 deletions src/main/java/frc/robot/OperatorBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
public class OperatorBoard {

private static Joystick HARDWARE;
public OperatorBoardButton BUTTON_ONE;
public OperatorBoardButton BUTTON_TWO;
public OperatorBoardButton BUTTON_THREE;
public OperatorBoardButton BUTTON_SIX;
public OperatorBoardButton BUTTON_ELEVEN;
public OperatorBoardButton startShooter;
public OperatorBoardButton feeder;
public OperatorBoardButton intakeForward;
public OperatorBoardButton intakeReverse;
public OperatorBoardButton releaseRatchet;
public OperatorBoardButton releaseClimber;
public OperatorBoardButton resetClimber;
public OperatorBoardButton BUTTON_TWELVE;
public OperatorBoardButton BUTTON_THIRTEEN;
public OperatorBoardButton BUTTON_FOURTEEN;
// TODO rename these, and use lowercase camel case names

/**
* Constructs one operator board. Since we only have one operator board, this
Expand All @@ -30,14 +29,14 @@ public class OperatorBoard {
public OperatorBoard(int port) {
HARDWARE = new Joystick(port);

BUTTON_ONE = new OperatorBoardButton(1);
BUTTON_TWO = new OperatorBoardButton(2);
BUTTON_THREE = new OperatorBoardButton(3);
BUTTON_SIX = new OperatorBoardButton(6);
BUTTON_ELEVEN = new OperatorBoardButton(11);
BUTTON_TWELVE = new OperatorBoardButton(12);
BUTTON_THIRTEEN = new OperatorBoardButton(13);
BUTTON_FOURTEEN = new OperatorBoardButton(14);
startShooter = new OperatorBoardButton(Constants.ControllerButtonPorts.BUTTON_SIX);
feeder = new OperatorBoardButton(Constants.ControllerButtonPorts.BUTTON_TWO);
intakeForward = new OperatorBoardButton(Constants.ControllerButtonPorts.BUTTON_THREE);
intakeReverse = new OperatorBoardButton(Constants.ControllerButtonPorts.BUTTON_ONE);
releaseRatchet = new OperatorBoardButton(Constants.ControllerButtonPorts.BUTTON_FOURTEEN);
releaseClimber = new OperatorBoardButton(Constants.ControllerButtonPorts.BUTTON_THIRTEEN);
resetClimber = new OperatorBoardButton(Constants.ControllerButtonPorts.BUTTON_ELEVEN);
BUTTON_TWELVE = new OperatorBoardButton(Constants.ControllerButtonPorts.BUTTON_TWELVE);
}

/**
Expand Down Expand Up @@ -85,6 +84,7 @@ public class OperatorBoardButton extends Button {

/**
* Constructs an OperatorBoardButton with a designated numerical ID
*
* @param button The button's number - a sort of ID
*/
public OperatorBoardButton(int button) {
Expand All @@ -93,6 +93,7 @@ public OperatorBoardButton(int button) {

/**
* Returns whether the button is being pressed.
*
* @return Whether or not the button is being pressed.
*/
@Override
Expand Down
183 changes: 88 additions & 95 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package frc.robot;

import com.revrobotics.CANSparkMax.IdleMode;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.GenericHID.Hand;
import edu.wpi.first.wpilibj.XboxController.Button;
Expand All @@ -16,10 +15,11 @@
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.commands.ClimberControllerCommand;
import frc.robot.commands.FeederCommand;
import frc.robot.commands.IntakeCommand;
import frc.robot.commands.MoveArmCommand;
import frc.robot.commands.OuttakeCommand;
import frc.robot.commands.ShooterOffCommand;
import frc.robot.commands.ReleaseRatchetCommand;
import frc.robot.commands.ShooterOnCommand;
import frc.robot.commands.SwerveJoystickCommand;
import frc.robot.subsystems.ClimberSubsystem;
Expand All @@ -36,97 +36,90 @@
* commands, and button mappings) should be declared here.
*/
public class RobotContainer {
// The robot's subsystems and commands are defined here...

private HardwareMap hardwareMap = new HardwareMap();

private XboxController m_driveController = hardwareMap.inputHardware.driveController;
private XboxController m_operatorController = hardwareMap.inputHardware.operatorController;

private ShooterSubsystem m_shooterSubsystem = new ShooterSubsystem(hardwareMap.shooterHardware);
private SwerveDriveSubsystem m_swerveSubsystem = new SwerveDriveSubsystem(hardwareMap.swerveDriveHardware);
private IntakeSubsystem m_intakeSubsystem = new IntakeSubsystem(hardwareMap.intakeHardware);
private ClimberSubsystem m_climberSubsystem = new ClimberSubsystem(hardwareMap.climberHardware);

private SwerveJoystickCommand m_swerveJoystickCommand = new SwerveJoystickCommand(m_swerveSubsystem,
m_driveController);
private MoveArmCommand m_moveArmCommand = new MoveArmCommand(m_operatorController, m_intakeSubsystem);
private ClimberControllerCommand m_climberControllerCommand = new ClimberControllerCommand(m_climberSubsystem,
m_operatorController);

/**
* The container for the robot. Contains subsystems, OI devices, and commands.
*/
public RobotContainer() {
configureButtonBindings();
m_swerveSubsystem.setDefaultCommand(m_swerveJoystickCommand);
m_intakeSubsystem.setDefaultCommand(m_moveArmCommand);
m_climberSubsystem.setDefaultCommand(m_climberControllerCommand);
}

/**
* Use this method to define your button->command mappings. Buttons can be
* created by instantiating a {@link GenericHID} or one of its subclasses
* ({@link edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then
* passing it to a {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {

// turns on shooter when Left Bumper is pressed
new JoystickButton(m_operatorController, Button.kBumperLeft.value)
.whenPressed(new ShooterOnCommand(m_shooterSubsystem));

// turns off shooter when Right Bumper is pressed
new JoystickButton(m_operatorController, Button.kBumperRight.value)
.whenPressed(new ShooterOffCommand(m_shooterSubsystem));

// turns on Feeder when B button is pressed and shoots ball
new JoystickButton(m_operatorController, Button.kB.value)
.whenPressed(new RunCommand(() -> m_shooterSubsystem.turnFeederOn(), m_shooterSubsystem))
.whenReleased(new RunCommand(() -> m_shooterSubsystem.turnFeederOff(), m_shooterSubsystem));

// runs the intake while the left trigger is held on the operator controller
new Trigger(() -> m_operatorController.getTriggerAxis(Hand.kLeft) > 0.5)
.whileActiveOnce(new IntakeCommand(m_intakeSubsystem));

// runs the outtake while the right trigger is held
new Trigger(() -> m_operatorController.getTriggerAxis(Hand.kRight) > 0.5)
.whileActiveOnce(new OuttakeCommand(m_intakeSubsystem));

// locks ratchet when Y button pressed so it cannot extend, only retract
// (press when hooked on and want to raise bot)
new JoystickButton(m_operatorController, Button.kY.value)
.whenPressed(new InstantCommand(m_climberSubsystem::lockRatchet, m_climberSubsystem));

// release ratchet when X button pressed so it can extend and retract
new JoystickButton(m_operatorController, Button.kX.value)
.whenPressed(new InstantCommand(m_climberSubsystem::releaseRatchet, m_climberSubsystem));

// releases the Climber when Start is pressed
new JoystickButton(m_operatorController, Button.kStart.value)
.whenPressed(new InstantCommand(m_climberSubsystem::releaseClimber, m_climberSubsystem));

// resets the gyro when the Start button is pressed
new JoystickButton(m_driveController, Button.kStart.value)
.whenPressed(new InstantCommand(m_swerveSubsystem::resetGyro, m_swerveSubsystem));

// Sets brake and coast mode with left bumper
new JoystickButton(m_driveController, Button.kBumperLeft.value)
.whenPressed(() -> m_swerveSubsystem.setDriveIdleMode(IdleMode.kCoast))
.whenReleased(() -> m_swerveSubsystem.setDriveIdleMode(IdleMode.kBrake));

new JoystickButton(m_driveController, Button.kA.value)
.whileHeld(new VisionAimingCommand(m_swerveSubsystem, m_driveController));

}

/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
// An ExampleCommand will run in autonomous
return null;
}
// The robot's subsystems and commands are defined here...

private HardwareMap hardwareMap = new HardwareMap();

private XboxController m_driveController = hardwareMap.inputHardware.driveController;
private OperatorBoard m_operatorController = hardwareMap.inputHardware.operatorBoard;

private ShooterSubsystem m_shooterSubsystem = new ShooterSubsystem(hardwareMap.shooterHardware);
private SwerveDriveSubsystem m_swerveSubsystem = new SwerveDriveSubsystem(hardwareMap.swerveDriveHardware);
private IntakeSubsystem m_intakeSubsystem = new IntakeSubsystem(hardwareMap.intakeHardware);
private ClimberSubsystem m_climberSubsystem = new ClimberSubsystem(hardwareMap.climberHardware);

private SwerveJoystickCommand m_swerveJoystickCommand = new SwerveJoystickCommand(m_swerveSubsystem,
m_driveController);
private MoveArmCommand m_moveArmCommand = new MoveArmCommand(m_operatorController, m_intakeSubsystem);
private ClimberControllerCommand m_climberControllerCommand = new ClimberControllerCommand(m_climberSubsystem,
m_operatorController);

/**
* The container for the robot. Contains subsystems, OI devices, and commands.
*/
public RobotContainer() {
configureButtonBindings();
m_swerveSubsystem.setDefaultCommand(m_swerveJoystickCommand);
m_intakeSubsystem.setDefaultCommand(m_moveArmCommand);
m_climberSubsystem.setDefaultCommand(m_climberControllerCommand);
}

/**
* Use this method to define your button->command mappings. Buttons can be
* created by instantiating a {@link GenericHID} or one of its subclasses
* ({@link edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then
* passing it to a {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {

// turns on shooter when Left Bumper is pressed
m_operatorController.startShooter.toggleWhenPressed(
new ShooterOnCommand(m_shooterSubsystem, m_operatorController.startShooter));

// turns on Feeder while button is held so balls will be shot
m_operatorController.feeder
.whileHeld(new FeederCommand(m_shooterSubsystem, m_operatorController.feeder));

// runs the intake while the button is held
m_operatorController.intakeForward
.whileHeld(new IntakeCommand(m_intakeSubsystem, m_operatorController.intakeForward));

// runs the intake backwards while the button is held
m_operatorController.intakeReverse
.whileHeld(new OuttakeCommand(m_intakeSubsystem, m_operatorController.intakeReverse));

// press to release ratchet. press again to lock ratchet.
m_operatorController.releaseRatchet.toggleWhenPressed(
new ReleaseRatchetCommand(m_climberSubsystem, m_operatorController.releaseRatchet));

// releases the Climber when button is pressed
m_operatorController.releaseClimber.whenPressed(
new InstantCommand(m_climberSubsystem::releaseClimber, m_climberSubsystem));

// set climber servo to reseting position
m_operatorController.resetClimber.whenPressed(() -> m_climberSubsystem.resetClimber());

// resets the gyro when the Start button is pressed
new JoystickButton(m_driveController, Button.kStart.value)
.whenPressed(new InstantCommand(m_swerveSubsystem::resetGyro, m_swerveSubsystem));

// Sets brake and coast mode with left bumper
new JoystickButton(m_driveController, Button.kBumperLeft.value)
.whenPressed(() -> m_swerveSubsystem.setDriveIdleMode(IdleMode.kCoast))
.whenReleased(() -> m_swerveSubsystem.setDriveIdleMode(IdleMode.kBrake));

new JoystickButton(m_driveController, Button.kA.value)
.whileHeld(new VisionAimingCommand(m_swerveSubsystem, m_driveController));

}

/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
// An ExampleCommand will run in autonomous
return null;
}
}
16 changes: 8 additions & 8 deletions src/main/java/frc/robot/commands/ClimberControllerCommand.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.GenericHID.Hand;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.Constants;
import frc.robot.OperatorBoard;
import frc.robot.Utils;
import frc.robot.subsystems.ClimberSubsystem;

public class ClimberControllerCommand extends CommandBase{
public class ClimberControllerCommand extends CommandBase {
private ClimberSubsystem m_climberSubsystem;
private XboxController m_controller;
private OperatorBoard m_controller;

public ClimberControllerCommand(ClimberSubsystem climberSubsystem, XboxController xboxController){
public ClimberControllerCommand(ClimberSubsystem climberSubsystem, OperatorBoard operatorBoard) {
m_climberSubsystem = climberSubsystem;
m_controller = xboxController;
m_controller = operatorBoard;
addRequirements(m_climberSubsystem);
}

@Override
public void execute(){
m_climberSubsystem.climb(Utils.deadZones(-m_controller.getY(Hand.kRight), Constants.ClimberConstants.CLIMBER_CONTROL_SPEED_DEADZONE));
public void execute() {
m_climberSubsystem.climb(Utils.deadZones(-m_controller.getLeftJoystickY(),
Constants.ClimberConstants.CLIMBER_CONTROL_SPEED_DEADZONE));
}
}
Loading

0 comments on commit c3b81e9

Please sign in to comment.