Skip to content

Commit

Permalink
Merge pull request strongback#30 from Team3132/testOI
Browse files Browse the repository at this point in the history
Map OI buttons.
  • Loading branch information
mrwaldron authored Feb 29, 2020
2 parents 80b5a90 + a0337cf commit 92a286b
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 151 deletions.
1 change: 1 addition & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private Constants() {
* Shooter constants
*/
public static final int[] SHOOTER_TALON_CAN_ID_LIST = {30, 31, 32};
public static final int SHOOTER_HOOD_SOLENOID_PORT = 3;
public static final double SHOOTER_SPEED_TOLERANCE_RPM = 600;
public static final double SHOOTER_F = 0.18;
public static final double SHOOTER_P = 0.7;
Expand Down
129 changes: 73 additions & 56 deletions src/main/java/frc/robot/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,80 +47,95 @@ public OI(Controller controller, Subsystems subsystems, Log log) {
* (left thumbstick) (right thumbstick)
*
* Driver Controls:
* Left Flight Joystick: Back/Forward
* Right Flight Joystick: Left/Right
* Left Joystick Trigger (Button 1): Half speed mode.
* Left flight joystick: move back/forward, climb up
* Right flight joystick: left/right, climb up
* While held, right joystick top far left button (Button 5): release ratchets
* While not held, right joystick top far left button (Button 5): enable ratchets
* Right joystick top far right button (Button 6): shift PTO mode
* Right joystick trigger (Button 1): intake
* Right joystick thumb button (Button 2): vision lineup
* Left joystick trigger (Button 1): slow/half speed
*
*
* Operator Controls:
* Pushing (A) begins positional control
* Pushing (B) deploys/stows buddy climber
* Pushing (X) begins rotational control
* Pushing (Y) deploy/stow the colourwheel
* Left trigger: shoot
* Pushing left stick to the left rotates colourwheel anticlockwise
* Pushing left stick to the right rotates colourwheel clockwise
* Pushing (left bumper) sets the hood and shooter to preset shot 1
* Pushing (right bumper) sets the hood and shooter to preset shot 2
*
*
* The hat vertical controls the lift height. Repeatedly pushing makes it go to the next height.
* The hat horizontal controls the sideways scoring.
* Pushing (A) starts intaking. Releasing it, stops intaking.
* Pushing (B) does an intake eject. Releasing it, stops ejecting.
* Pushing (left bumper) does a front eject (ie the outtake opens for the cube to fall out).
* Pushing both triggers deploys the ramp (safety)
* Pushing (Y) gets the robot ready for climbing.
* While (X) is held, the robot will climb.
* (start) resets the robot lift at the bottom and intake stowed.
* The following operator buttons are unused:
* (back)(mode)(right stick up/down/left/right)(left stick up/down)(left trigger)
* (right trigger)(back)(start)(left joystick click)(right joystick click)
* (D-pad up/down/left/right)
*
* The following buttons are unused:
* (back)(mode)(left bumper).
*/
public void configureJoysticks(FlightStick driverLeft, FlightStick driverRight, InputDevice operator) {
// Left and RIght driver joysticks have separate mappings, as well as Operator controller.
// Left and Right driver joysticks have separate mappings, as well as Operator controller.
configureDriverJoystick(driverLeft, driverRight, "driverSticks");
configureOperatorJoystick(operator, "operator");
}


public void configureDriverJoystick(FlightStick leftStick, FlightStick rightStick, String name) {
private void configureDriverJoystick(FlightStick leftStick, FlightStick rightStick, String name) {

// Left Stick's onTrigger drive slowly mode is handled in Robot.java, not here
// Hatch Vision
// Intaking is on this button.

// Intake - Right Stick Button 2 (on/off)
onTriggered(rightStick.getButton(2), Sequences.startIntaking());
// Intake
onTriggered(rightStick.getButton(1), Sequences.startIntaking());
onUntriggered(rightStick.getButton(1), Sequences.stopIntaking());

onUntriggered(rightStick.getButton(2), Sequences.stopIntaking());
// Slow drive
onTriggered(leftStick.getButton(1), Sequences.startSlowDriveForward());
onUntriggered(leftStick.getButton(1), Sequences.setDrivebaseToArcade());

onTriggered(leftStick.getButton(6), Sequences.startSlowDriveForward());
onUntriggered(leftStick.getButton(6), Sequences.setDrivebaseToArcade());
// Release/enable ratchets (empty sequence)
onTriggered(rightStick.getButton(5), Sequences.releaseClimberBrake());
onUntriggered(rightStick.getButton(5), Sequences.applyClimberBrake());

onTriggered(rightStick.getButton(3), Sequences.turnToWall()); // Face the drivers station wall.
onUntriggered(rightStick.getButton(3), Sequences.setDrivebaseToArcade());
// Toggle drive / climb mode
onTriggered(rightStick.getButton(6), Sequences.toggleDriveClimbModes());

onTriggered(rightStick.getButton(12), Sequences.enableClimbMode());
onTriggered(rightStick.getButton(11), Sequences.enableDriveMode());
onTriggered(rightStick.getButton(10), Sequences.climberBrake());
onTriggered(rightStick.getButton(9), Sequences.climberStopBrake());
onTriggered(rightStick.getButton(4), Sequences.deployBuddyClimber());
onTriggered(rightStick.getButton(5), Sequences.retractBuddyClimber());
}
// Vision lineup
onTriggered(rightStick.getButton(2), Sequences.visionAim());
onUntriggered(rightStick.getButton(2), Sequences.setDrivebaseToArcade());

public void configureOperatorJoystick(InputDevice stick, String name) {
// Reset robot: intake stowed and lift at bottom.
// TODO: update
// onTriggered(stick.getButton(GamepadButtonsX.START_BUTTON), Sequences.getStartSequence());

// Intake
onTriggered(stick.getAxis(GamepadButtonsX.LEFT_TRIGGER_AXIS, GamepadButtonsX.TRIGGER_THRESHOLD),
() -> {
return Sequences.startIntaking();
});
onUntriggered(stick.getAxis(GamepadButtonsX.LEFT_TRIGGER_AXIS, GamepadButtonsX.TRIGGER_THRESHOLD), Sequences.stopIntaking());
//onTriggered(rightStick.getButton(4), Sequences.toggleBuddyClimb());
}

// Colour Wheel testing.
private void configureOperatorJoystick(InputDevice stick, String name) {
// Colourwheel positional
onTriggered(stick.getButton(GamepadButtonsX.A_BUTTON), Sequences.startColourWheelPositional(WheelColour.UNKNOWN));
onUntriggered(stick.getButton(GamepadButtonsX.A_BUTTON), Sequences.stopColourWheel());

// Colourwheel rotational
onTriggered(stick.getButton(GamepadButtonsX.X_BUTTON), Sequences.startColourWheelRotational());
onUntriggered(stick.getButton(GamepadButtonsX.X_BUTTON), Sequences.stopColourWheel());
onTriggered(stick.getButton(GamepadButtonsX.LEFT_BUMPER), Sequences.colourWheelAnticlockwise());
onUntriggered(stick.getButton(GamepadButtonsX.LEFT_BUMPER), Sequences.stopColourWheel());
onTriggered(stick.getButton(GamepadButtonsX.RIGHT_BUMPER), Sequences.colourWheelClockwise());
onUntriggered(stick.getButton(GamepadButtonsX.RIGHT_BUMPER), Sequences.stopColourWheel());

// Colourwheel manual adjust clockwise
onTriggered(stick.getAxis(GamepadButtonsX.LEFT_X_AXIS, GamepadButtonsX.AXIS_THRESHOLD), Sequences.colourWheelClockwise());
onUntriggered(stick.getAxis(GamepadButtonsX.LEFT_X_AXIS, GamepadButtonsX.AXIS_THRESHOLD), Sequences.stopColourWheel());

// Colourwheel manual adjust anticlockwise
onTriggered(stick.getAxis(GamepadButtonsX.LEFT_X_AXIS, -GamepadButtonsX.AXIS_THRESHOLD), Sequences.colourWheelAnticlockwise());
onUntriggered(stick.getAxis(GamepadButtonsX.LEFT_X_AXIS, GamepadButtonsX.AXIS_THRESHOLD), Sequences.stopColourWheel());

// Close shot
onTriggered(stick.getAxis(GamepadButtonsX.LEFT_TRIGGER_AXIS, GamepadButtonsX.TRIGGER_THRESHOLD), Sequences.startShooting(/*close=*/true));
onUntriggered(stick.getAxis(GamepadButtonsX.LEFT_TRIGGER_AXIS, GamepadButtonsX.TRIGGER_THRESHOLD), Sequences.stopShooting());

// Far shot
onTriggered(stick.getAxis(GamepadButtonsX.LEFT_TRIGGER_AXIS, GamepadButtonsX.TRIGGER_THRESHOLD), Sequences.startShooting(/*close=*/false));
onUntriggered(stick.getAxis(GamepadButtonsX.LEFT_TRIGGER_AXIS, GamepadButtonsX.TRIGGER_THRESHOLD), Sequences.stopShooting());

// Spin up shooter. Touch and release the close or far shot buttons to stop shooter wheel.
onTriggered(stick.getButton(GamepadButtonsX.RIGHT_BUMPER), Sequences.spinUpShooter());

// Buddy climb toggle
onTriggered(stick.getButton(GamepadButtonsX.B_BUTTON), Sequences.toggleBuddyClimb());
}


Expand Down Expand Up @@ -149,9 +164,9 @@ public void configureDiagBox(InputDevice box) {
// While the intake speed button is pressed, set the target speed. Does not turn off.
whileTriggered(box.getButton(OperatorBoxButtons.INTAKE_MOTOR),
() -> intakeIF.setMotorOutput(box.getAxis(OperatorBoxButtons.INTAKE_POT).read()));
onTriggered(box.getButton(OperatorBoxButtons.INTAKE_EXTEND),
onTriggered(box.getButton(OperatorBoxButtons.INTAKE_DEPLOY),
() -> intakeIF.setExtended(true));
onTriggered(box.getButton(OperatorBoxButtons.INTAKE_RETRACT),
onTriggered(box.getButton(OperatorBoxButtons.INTAKE_STOW),
() -> intakeIF.setExtended(false));


Expand All @@ -169,12 +184,14 @@ public void configureDiagBox(InputDevice box) {
onUntriggered(box.getButton(OperatorBoxButtons.LOADER_PASSTHROUGH_MOTOR),
() -> loaderIF.setTargetPassthroughMotorOutput(0));

onTriggered(box.getButton(OperatorBoxButtons.LOADER_PADDLE_BLOCKING),
() -> loaderIF.setPaddleNotBlocking(false));
onTriggered(box.getButton(OperatorBoxButtons.LOADER_PADDLE_NOTBLOCKING),
() -> loaderIF.setPaddleNotBlocking(true));
onTriggered(box.getButton(OperatorBoxButtons.LOADER_PADDLE_BLOCKING),
() -> loaderIF.setPaddleNotBlocking(false));
onTriggered(box.getButton(OperatorBoxButtons.LOADER_PADDLE_NOTBLOCKING),
() -> loaderIF.setPaddleNotBlocking(true));
}



private void mapOverrideSwitch(InputDevice box, int disableButton, int manualButton, OverridableSubsystem overrideableSubsystem) {
onTriggered(box.getButton(disableButton), () -> overrideableSubsystem.turnOff());
onTriggered(box.getButton(manualButton), () -> overrideableSubsystem.setManualMode());
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/frc/robot/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import frc.robot.interfaces.ColourWheelInterface.ColourAction;
import frc.robot.interfaces.ColourWheelInterface.ColourAction.ColourWheelType;
import frc.robot.lib.WheelColour;
import frc.robot.subsystems.ColourWheel;
import frc.robot.subsystems.Subsystems;

/**
Expand Down Expand Up @@ -124,11 +123,6 @@ public boolean isAlive() {
/**
* Does the simple, dumb and most importantly, safe thing.
*
* See the design doc before changing this.
*
* Steps through: - Wait for all subsystems to finish moving. - Deploy or
* retract the intake if necessary. -
*
* Note if the step asks for something which will cause harm to the robot, the
* request will be ignored. For example if the lift was moved into a position
* the intake could hit it and then the intake was moved into the lift, the
Expand Down Expand Up @@ -169,11 +163,24 @@ private void applyState(State desiredState) {

subsystems.colourWheel.setArmExtended(desiredState.extendColourWheel);
subsystems.colourWheel.setDesiredAction(desiredState.colourAction);

subsystems.shooter.setTargetRPM(desiredState.shooterRPM);
subsystems.shooter.setHoodExtended(desiredState.shooterHoodExtended);

// Toggle buddy climb if needed
if (desiredState.buddyClimbToggle) {
subsystems.buddyClimb.setExtended(!subsystems.buddyClimb.isExtended());
}

// Toggle between drive and climb modes if needed
if (desiredState.driveClimbModeToggle) {
subsystems.drivebase.activateClimbMode(!subsystems.drivebase.isClimbModeEnabled());
}

//subsystems.jevois.setCameraMode(desiredState.cameraMode);
maybeWaitForBalls(desiredState.expectedNumberOfBalls);
waitForIntake();
waitForShooterHood();
maybeWaitForShooter(desiredState.shooterUpToSpeed);
maybeWaitForColourWheel();
// Wait for driving to finish if needed.
Expand All @@ -200,7 +207,12 @@ private void waitForIntake() {
waitUntil(() -> subsystems.intake.isRetracted() || subsystems.intake.isExtended(), "intake to finish moving");
}


/**
* Blocks waiting till the shooter hood is in position.
*/
private void waitForShooterHood() {
waitUntil(() -> subsystems.shooter.isHoodExtended() || subsystems.shooter.isHoodRetracted(), "hood to finish moving");
}

/**
* Maybe wait for the shooter to get up to the target speed.
Expand Down
Loading

0 comments on commit 92a286b

Please sign in to comment.