Revert the new controller binding system

This commit is contained in:
nathanrsxtn
2022-04-20 16:51:50 -06:00
parent 91ab5650a3
commit af8e6dff14
+101 -150
View File
@@ -178,168 +178,119 @@ public class RobotContainer {
} }
private void configureDriverButtonBindings() { private void configureDriverButtonBindings() {
// Iterate over and assign commands to all Xbox controller buttons. /* Left Bumper > Shift Down */
for (XboxController.Button binding : XboxController.Button.values()) { new JoystickButton(getDriverController(), XboxController.Button.kLeftBumper.value)
/* ------------------------------------ Driver ------------------------------------ */ .whenPressed(() -> m_robotSwerveDrive.highSpeed(false));
JoystickButton button = new JoystickButton(getDriverController(), binding.value); /* Right Bumper > Shift Up */
if (binding == XboxController.Button.kLeftBumper) { new JoystickButton(getDriverController(), XboxController.Button.kRightBumper.value)
/* Left Bumper > Shift Down */ .whenPressed(() -> m_robotSwerveDrive.highSpeed(false));
button.whenPressed(() -> m_robotSwerveDrive.highSpeed(false)); /* Left Stick > Unbound */
} else if (binding == XboxController.Button.kRightBumper) { new JoystickButton(getDriverController(), XboxController.Button.kLeftStick.value)
/* Right Bumper > Shift Up */ .whenPressed(new PrintCommand("Unbound"));
button.whenPressed(() -> m_robotSwerveDrive.highSpeed(false)); /* Right Stick > Unbound */
} else if (binding == XboxController.Button.kLeftStick) { new JoystickButton(getDriverController(), XboxController.Button.kRightStick.value)
/* Left Stick > Unbound */ .whenPressed(new PrintCommand("Unbound"));
button.whenPressed(new PrintCommand("Unbound")); /* A > Unbound */
} else if (binding == XboxController.Button.kRightStick) { new JoystickButton(getDriverController(), XboxController.Button.kA.value)
/* Right Stick > Unbound */ .whenPressed(this::switchControlMode)
button.whenPressed(new PrintCommand("Unbound")); .whenReleased(this::switchControlMode);
} else if (binding == XboxController.Button.kA) { /* B > Unbound */
/* A > Unbound */ new JoystickButton(getDriverController(), XboxController.Button.kB.value)
button.whenPressed(this::switchControlMode); .whenPressed(this::switchDriveMode)
button.whenReleased(this::switchControlMode); .whenReleased(this::switchDriveMode);
} else if (binding == XboxController.Button.kB) { /* X > Unbound */
/* B > Unbound */ new JoystickButton(getDriverController(), XboxController.Button.kX.value)
button.whenPressed(this::switchDriveMode); .whileHeld(new RunCommand(() -> m_robotExtender.runExtender(1.0), m_robotExtender))
button.whenReleased(this::switchDriveMode); .whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
} else if (binding == XboxController.Button.kX) { /* Y > Unbound */
/* X > Unbound */ new JoystickButton(getDriverController(), XboxController.Button.kY.value)
button.whileHeld(new RunCommand(() -> m_robotExtender.runExtender(1.0), m_robotExtender)); .whileHeld(new RunCommand(() -> m_robotExtender.runExtender(-1.0), m_robotExtender))
button.whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender)); .whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
} else if (binding == XboxController.Button.kY) { /* Back > Calibrate Odometry */
/* Y > Unbound */ new JoystickButton(getDriverController(), XboxController.Button.kBack.value)
button.whileHeld(new RunCommand(() -> m_robotExtender.runExtender(-1.0), m_robotExtender)); .whenPressed(() -> resetOdometry(new Pose2d(0, 0, new Rotation2d(0))));
button.whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender)); /* Start > Calibrate Odometry */
} else if (binding == XboxController.Button.kBack) { new JoystickButton(getDriverController(), XboxController.Button.kStart.value)
/* Back > Calibrate Odometry */ .whenPressed(m_robotSwerveDrive::resetGyro);
button.whenPressed(() -> resetOdometry(new Pose2d(0, 0, new Rotation2d(0))));
} else if (binding == XboxController.Button.kStart) { /* D-pad Up > Unbound */
/* Start > Calibrate Odometry */ new POVButton(getDriverController(), 0).whenPressed(new PrintCommand("Unbound"));
button.whenPressed(m_robotSwerveDrive::resetGyro); /* D-pad Right > Unbound */
} new POVButton(getDriverController(), 90).whenPressed(new PrintCommand("Unbound"));
} /* D-pad Down > Unbound */
// Iterate over and assign commands to cardinal Xbox controller d-pad directions. new POVButton(getDriverController(), 180).whenPressed(new PrintCommand("Unbound"));
for (XboxControllerPOV binding : XboxControllerPOV.values()) { /* D-pad Left > Unbound */
POVButton button = new POVButton(getDriverController(), binding.value); new POVButton(getDriverController(), 270).whenPressed(new PrintCommand("Unbound"));
if (binding == XboxControllerPOV.kUp) {
/* D-pad Up > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxControllerPOV.kRight) {
/* D-pad Right > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxControllerPOV.kDown) {
/* D-pad Down > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxControllerPOV.kLeft) {
/* D-pad Left > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
}
}
} }
private void configureOperatorButtonBindings() { private void configureOperatorButtonBindings() {
// Iterate over and assign commands to all Xbox controller buttons. /* Left Bumper > Storage In */
for (XboxController.Button binding : XboxController.Button.values()) { new JoystickButton(getDriverController(), XboxController.Button.kLeftBumper.value).whileHeld(new RunCommand(() -> m_robotStorage.runStorage(StorageConstants.STORAGE_SPEED)))
/* ------------------------------------ Operator ------------------------------------ */ .whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0)));
JoystickButton button = new JoystickButton(getDriverController(), binding.value); /* Right Bumper > Storage Out */
if (binding == XboxController.Button.kLeftBumper) { new JoystickButton(getDriverController(), XboxController.Button.kRightBumper.value).whileHeld(new RunCommand(() -> m_robotStorage.runStorage(-StorageConstants.STORAGE_SPEED)))
/* Left Bumper > Storage In */ .whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0)));
button.whileHeld(new RunCommand(() -> m_robotStorage.runStorage(StorageConstants.STORAGE_SPEED))); /* Left Stick > Unbound */
button.whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0))); new JoystickButton(getDriverController(), XboxController.Button.kLeftStick.value).whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxController.Button.kRightBumper) { /* Right Stick > Unbound */
/* Right Bumper > Storage Out */ new JoystickButton(getDriverController(), XboxController.Button.kRightStick.value).whenPressed(new PrintCommand("Unbound"));
button.whileHeld(new RunCommand(() -> m_robotStorage.runStorage(-StorageConstants.STORAGE_SPEED))); /* A > Spit Out Ball */
button.whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0))); new JoystickButton(getDriverController(), XboxController.Button.kA.value).whileHeld(new RunCommand(m_robotTurret::gotoMidpoint, m_robotTurret))
} else if (binding == XboxController.Button.kLeftStick) { .whileHeld(new RunCommand(() -> m_robotBoomBoom.runDrumShooter(0.25)));
/* Left Stick > Unbound */ /* B > Toggle Claws */
button.whenPressed(new PrintCommand("Unbound")); new JoystickButton(getDriverController(), XboxController.Button.kB.value).whenPressed(m_robotClaws::toggleClaws, m_robotClaws);
} else if (binding == XboxController.Button.kRightStick) { /* X > Toggle Extender Deployment */
/* Right Stick > Unbound */ new JoystickButton(getDriverController(), XboxController.Button.kX.value).whenPressed(new ConditionalCommand(new DeployExtender(m_robotExtender, m_robotIntake), new RetractExtender(m_robotExtender), m_robotExtender::isRetracted));
button.whenPressed(new PrintCommand("Unbound")); /* Y > Track Target */
} else if (binding == XboxController.Button.kA) { new JoystickButton(getDriverController(), XboxController.Button.kY.value).whileHeld(new TrackTarget(m_robotVisionOdometry, m_robotTurret, m_robotHood, m_robotBoomBoom));
/* A > Spit Out Ball */ /* Back > Unbound */
button.whileHeld(new RunCommand(m_robotTurret::gotoMidpoint, m_robotTurret)); new JoystickButton(getDriverController(), XboxController.Button.kBack.value).whenPressed(new PrintCommand("Unbound"));
button.whileHeld(new RunCommand(() -> m_robotBoomBoom.runDrumShooter(0.25))); /* Start > Unbound */
} else if (binding == XboxController.Button.kB) { new JoystickButton(getDriverController(), XboxController.Button.kStart.value).whenPressed(new PrintCommand("Unbound"));
/* B > Toggle Claws */
button.whenPressed(m_robotClaws::toggleClaws, m_robotClaws); /* D-pad Up > Unbound */
} else if (binding == XboxController.Button.kX) { new POVButton(getDriverController(), 0).whenPressed(new PrintCommand("Unbound"));
/* X > Toggle Extender Deployment */ /* D-pad Right > Unbound */
button.whenPressed(new ConditionalCommand(new DeployExtender(m_robotExtender, m_robotIntake), new RetractExtender(m_robotExtender), m_robotExtender::isRetracted)); new POVButton(getDriverController(), 90).whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxController.Button.kY) { /* D-pad Down > Unbound */
/* Y > Track Target */ new POVButton(getDriverController(), 180).whenPressed(new PrintCommand("Unbound"));
button.whileHeld(new TrackTarget(m_robotVisionOdometry, m_robotTurret, m_robotHood, m_robotBoomBoom)); /* D-pad Left > Unbound */
} else if (binding == XboxController.Button.kBack) { new POVButton(getDriverController(), 270).whenPressed(new PrintCommand("Unbound"));
/* Back > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxController.Button.kStart) {
/* Start > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
}
}
// Iterate over and assign commands to cardinal Xbox controller d-pad directions.
for (XboxControllerPOV binding : XboxControllerPOV.values()) {
POVButton button = new POVButton(getDriverController(), binding.value);
if (binding == XboxControllerPOV.kUp) {
/* D-pad Up > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxControllerPOV.kRight) {
/* D-pad Right > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxControllerPOV.kDown) {
/* D-pad Down > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
} else if (binding == XboxControllerPOV.kLeft) {
/* D-pad Left > Unbound */
button.whenPressed(new PrintCommand("Unbound"));
}
}
} }
private void configureBoxButtonBindings() { private void configureBoxButtonBindings() {
// Iterate over and assign commands to all button box buttons. /* Right Switch > Unbound */
for (ButtonBox.Button binding : ButtonBox.Button.values()) { new JoystickButton(getButtonBox(), ButtonBox.Button.kRightSwitch.value).whenPressed(new PrintCommand("Unbound"));
/* ---------------------------------- Button Box ---------------------------------- */ /* Middle Switch > Climber and Shooter mode switching */
JoystickButton button = new JoystickButton(getButtonBox(), binding.value); new JoystickButton(getButtonBox(), ButtonBox.Button.kMiddleSwitch.value).whenPressed(() -> isClimberControlMode = true)
if (binding == ButtonBox.Button.kRightSwitch) { .whenReleased(() -> isClimberControlMode = false);
/* Right Switch > Unbound */ /* Left Switch > Disables soft limits on press, release resets encoders (all for turret, hood, climber, and extender) */
button.whenPressed(new PrintCommand("Unbound")); new JoystickButton(getButtonBox(), ButtonBox.Button.kLeftSwitch.value).whenPressed(() -> m_robotTurret.setTurretSoftLimits(false), m_robotTurret)
} else if (binding == ButtonBox.Button.kMiddleSwitch) { .whenPressed(() -> m_robotTurret.calibrationSpeed = 0.3, m_robotTurret);
/* Middle Switch > Climber and Shooter mode switching */
button.whenPressed(() -> isClimberControlMode = true);
button.whenReleased(() -> isClimberControlMode = false);
} else if (binding == ButtonBox.Button.kLeftSwitch) {
/* Left Switch > Disables soft limits on press, release resets encoders (all for turret, hood, climber, and extender) */
button.whenPressed(() -> m_robotTurret.setTurretSoftLimits(false), m_robotTurret);
button.whenPressed(() -> m_robotTurret.calibrationSpeed = 0.3, m_robotTurret);
button.whenPressed(() -> m_robotHood.setHoodSoftLimits(false), m_robotHood); new JoystickButton(getButtonBox(), ButtonBox.Button.kLeftSwitch.value).whenPressed(() -> m_robotHood.setHoodSoftLimits(false), m_robotHood)
button.whenPressed(() -> m_robotHood.calibrationSpeed = 0.3, m_robotHood); .whenPressed(() -> m_robotHood.calibrationSpeed = 0.3, m_robotHood);
button.whenPressed(() -> m_robotExtender.setExtenderSoftLimits(false), m_robotExtender); new JoystickButton(getButtonBox(), ButtonBox.Button.kLeftSwitch.value).whenPressed(() -> m_robotExtender.setExtenderSoftLimits(false), m_robotExtender);
button.whenReleased(() -> m_robotTurret.setTurretSoftLimits(true), m_robotTurret); new JoystickButton(getButtonBox(), ButtonBox.Button.kLeftSwitch.value).whenReleased(() -> m_robotTurret.setTurretSoftLimits(true), m_robotTurret)
button.whenReleased(() -> m_robotTurret.calibrationSpeed = 1.0, m_robotTurret); .whenReleased(() -> m_robotTurret.calibrationSpeed = 1.0, m_robotTurret);
button.whenReleased(() -> m_robotHood.setHoodSoftLimits(true), m_robotHood); new JoystickButton(getButtonBox(), ButtonBox.Button.kLeftSwitch.value).whenReleased(() -> m_robotHood.setHoodSoftLimits(true), m_robotHood)
button.whenReleased(() -> m_robotHood.calibrationSpeed = 1.0, m_robotHood); .whenReleased(() -> m_robotHood.calibrationSpeed = 1.0, m_robotHood);
button.whenReleased(() -> m_robotExtender.setExtenderSoftLimits(true), m_robotExtender); new JoystickButton(getButtonBox(), ButtonBox.Button.kLeftSwitch.value).whenReleased(() -> m_robotExtender.setExtenderSoftLimits(true), m_robotExtender);
button.whenReleased(() -> m_robotTurret.m_boomBoomRotateEncoder.setPosition(0), m_robotTurret); new JoystickButton(getButtonBox(), ButtonBox.Button.kLeftSwitch.value).whenReleased(() -> m_robotTurret.m_boomBoomRotateEncoder.setPosition(0), m_robotTurret)
button.whenReleased(() -> m_robotHood.m_angleEncoder.setPosition(0), m_robotHood); .whenReleased(() -> m_robotHood.m_angleEncoder.setPosition(0), m_robotHood)
button.whenReleased(() -> m_robotExtender.setEncoder(0), m_robotExtender); .whenReleased(() -> m_robotExtender.setEncoder(0), m_robotExtender)
button.whenReleased(() -> m_robotClimber.setEncoders(0), m_robotClimber); .whenReleased(() -> m_robotClimber.setEncoders(0), m_robotClimber);
} else if (binding == ButtonBox.Button.kRightButton) { /* Right Button > Extender Out */
/* Right Button > Extender Out */ new JoystickButton(getButtonBox(), ButtonBox.Button.kRightButton.value).whileHeld(new RunCommand(() -> m_robotExtender.runExtender(1.0), m_robotExtender))
button.whileHeld(new RunCommand(() -> m_robotExtender.runExtender(1.0), m_robotExtender)); .whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
button.whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender)); /* Left Button > Extender In */
} else if (binding == ButtonBox.Button.kLeftButton) { new JoystickButton(getButtonBox(), ButtonBox.Button.kLeftButton.value).whileHeld(new RunCommand(() -> m_robotExtender.runExtender(-1.0), m_robotExtender))
/* Left Button > Extender In */ .whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
button.whileHeld(new RunCommand(() -> m_robotExtender.runExtender(-1.0), m_robotExtender));
button.whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
}
}
} }
/** /**