Skip to content

Commit

Permalink
Finish mapping buttons.
Browse files Browse the repository at this point in the history
Some functionality had to be switched to toggle to match the button
design.
  • Loading branch information
mrwaldron committed Feb 29, 2020
1 parent 61a6a8f commit 91d09bb
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 165 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
108 changes: 30 additions & 78 deletions src/main/java/frc/robot/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public OI(Controller controller, Subsystems subsystems, Log log) {
*
* Driver Controls:
* Left flight joystick: move back/forward, climb up
* Right flight joystick: left/right
* 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
Expand Down Expand Up @@ -82,97 +82,60 @@ public void configureJoysticks(FlightStick driverLeft, FlightStick driverRight,
}


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

// Intake
onTriggered(rightStick.getButton(1), Sequences.startIntaking());
onUntriggered(rightStick.getButton(1), Sequences.stopIntaking());

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

// release/enable ratchets (empty sequence)
onTriggered(rightStick.getButton(5), Sequences.getEmptySequence());
onUntriggered(rightStick.getButton(5), Sequences.getEmptySequence());
// Release/enable ratchets (empty sequence)
onTriggered(rightStick.getButton(5), Sequences.releaseClimberBrake());
onUntriggered(rightStick.getButton(5), Sequences.applyClimberBrake());

// shift PTO mode, toggle (empty sequence)
onTriggered(rightStick.getButton(6), Sequences.getEmptySequence());
onUntriggered(rightStick.getButton(6), Sequences.getEmptySequence());
// Toggle drive / climb mode
onTriggered(rightStick.getButton(6), Sequences.toggleDriveClimbModes());

// Vision lineup
onTriggered(rightStick.getButton(2), Sequences.visionAim());
onUntriggered(rightStick.getButton(2), Sequences.getEmptySequence());
onUntriggered(rightStick.getButton(2), Sequences.setDrivebaseToArcade());

//onTriggered(rightStick.getButton(4), Sequences.deployBuddyClimber());
//onTriggered(rightStick.getButton(5), Sequences.retractBuddyClimber());
//onTriggered(rightStick.getButton(4), Sequences.toggleBuddyClimb());
}

public void configureOperatorJoystick(InputDevice stick, String name) {
// i dont know what the text below is for, its from 2019
//onTriggered(stick.getButton(GamepadButtonsX.START_BUTTON), Sequences.getStartSequence());

//lucas pls finish the colourwheel stuff amogh is confused

//note: manual adjust doesnt have an untriggered stop on it
//note: drop colourwheel has a seperate button (Y)


//colourwheel positional
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
// Colourwheel rotational
onTriggered(stick.getButton(GamepadButtonsX.X_BUTTON), Sequences.startColourWheelRotational());
onUntriggered(stick.getButton(GamepadButtonsX.X_BUTTON), Sequences.stopColourWheel());

//manual adjust clockwise
onTriggered(stick.getAxis(GamepadButtonsX.LEFT_X_AXIS, GamepadButtonsX.AXIS_THRESHOLD),
() -> {
return Sequences.colourWheelClockwise();
});
onUntriggered(stick.getAxis(GamepadButtonsX.LEFT_X_AXIS, GamepadButtonsX.AXIS_THRESHOLD), Sequences.getEmptySequence());

//manual adjust anticlockwise
onTriggered(stick.getAxis(GamepadButtonsX.LEFT_X_AXIS, -GamepadButtonsX.AXIS_THRESHOLD),
() -> {
return Sequences.colourWheelAnticlockwise();
});
onUntriggered(stick.getAxis(GamepadButtonsX.LEFT_X_AXIS, GamepadButtonsX.AXIS_THRESHOLD), Sequences.getEmptySequence());

//deploy/stow colourwheel, toggle (empty sequence)
onTriggered(stick.getButton(GamepadButtonsX.Y_BUTTON), Sequences.getEmptySequence());

//shoot (empty sequence)
onTriggered(stick.getAxis(GamepadButtonsX.LEFT_TRIGGER_AXIS, GamepadButtonsX.TRIGGER_THRESHOLD),
() -> {
return Sequences.getEmptySequence();
});
onUntriggered(stick.getAxis(GamepadButtonsX.LEFT_TRIGGER_AXIS, GamepadButtonsX.TRIGGER_THRESHOLD), Sequences.getEmptySequence());

//shot 1 (empty sequence)
onTriggered(stick.getButton(GamepadButtonsX.LEFT_BUMPER), Sequences.getEmptySequence());
onUntriggered(stick.getButton(GamepadButtonsX.LEFT_BUMPER), Sequences.getEmptySequence());
// 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());

//shot 2 (empty sequence)
onTriggered(stick.getButton(GamepadButtonsX.RIGHT_BUMPER), Sequences.getEmptySequence());
onUntriggered(stick.getButton(GamepadButtonsX.RIGHT_BUMPER), Sequences.getEmptySequence());
// 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());

//buddy climb, toggle (empty sequence)
onTriggered(stick.getButton(GamepadButtonsX.B_BUTTON), Sequences.getEmptySequence());
onUntriggered(stick.getButton(GamepadButtonsX.B_BUTTON), Sequences.getEmptySequence());
// 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());

// Colour Wheel testing.
onTriggered(stick.getButton(GamepadButtonsX.A_BUTTON), Sequences.startColourWheelPositional(WheelColour.UNKNOWN));
onUntriggered(stick.getButton(GamepadButtonsX.A_BUTTON), Sequences.stopColourWheel());
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());
// 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 @@ -225,18 +188,7 @@ public void configureDiagBox(InputDevice box) {
() -> loaderIF.setPaddleNotBlocking(false));
onTriggered(box.getButton(OperatorBoxButtons.LOADER_PADDLE_NOTBLOCKING),
() -> loaderIF.setPaddleNotBlocking(true));

//might be outdated already
/*
ClimberInterface climberIF = subsystems.climberOverride.getOverrideInterface();
// Setup the switch for manual/auto/off modes.
mapOverrideSwitch(box, OperatorBoxButtons.CLIMBER_DISABLE, OperatorBoxButtons.CLIMBER_MANUAL, subsystems.climberOverride);
onTriggered(box.getButton(OperatorBoxButtons.CLIMBER_EXTEND),
() -> climberIF.setDesiredAction(new ClimberAction(Type.SET_BOTH_HEIGHT,
0.2*box.getAxis(OperatorBoxButtons.CLIMBER_POT).read())));
*/

}
}



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
93 changes: 56 additions & 37 deletions src/main/java/frc/robot/controller/Sequences.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Sequences for doing most actions on the robot.
*
* If you add a new sequence, add it to allSequences at the end of this file.
*
* Design doc:
* https://docs.google.com/document/d/1IBAw5dKG8hiahRkd8FzU75j3yF6No33oQXtNEKi3LXc/edit#
*/
package frc.robot.controller;

Expand Down Expand Up @@ -93,7 +90,10 @@ public static Sequence startSlowDriveForward() {

public static Sequence setDrivebaseToArcade() {
Sequence seq = new Sequence("Arcade");
seq.add().doArcadeDrive();
seq.add().doArcadeDrive()
.setShooterRPM(0) // Turn off everything that may be on.
.retractShooterHood()
.setLoaderSpinnerMotorRPM(0);
return seq;
}

Expand Down Expand Up @@ -161,36 +161,53 @@ public static Sequence startLoaderTest() {

// Testing methods
public static Sequence startIntakingOnly() {
Sequence seq = new Sequence("start Intaking");
Sequence seq = new Sequence("start intaking");
seq.add().deployIntake();
seq.add().setIntakeMotorOutput(INTAKE_MOTOR_CURRENT).deployIntake();
return seq;
}

public static Sequence stopIntakingOnly() {
Sequence seq = new Sequence("stop Intaking");
Sequence seq = new Sequence("stop intaking");
seq.add().setIntakeMotorOutput(0.0);
seq.add().stowIntake();
return seq;
}

// This is to test the Loader system
public static Sequence startLoader() {
Sequence seq = new Sequence("start Loader");
Sequence seq = new Sequence("start loader");
seq.add().setLoaderSpinnerMotorRPM(LOADER_MOTOR_RPM);
return seq;
}

public static Sequence stopLoader() {
Sequence seq = new Sequence("stop Loader");
Sequence seq = new Sequence("stop loader");
seq.add().setLoaderSpinnerMotorRPM(0.0);
return seq;
}

public static Sequence startShooting() {

/**
* As the shooter takes time to spin up, enable spinning
* it up in advance.
* Touch the startShooting() sequences to halt.
*/
public static Sequence spinUpShooter() {
Sequence seq = new Sequence("spin up shooter");
seq.add().setShooterRPM(SHOOTER_TARGET_SPEED_RPM);
return seq;
}

public static Sequence startShooting(boolean closeToGoal) {
Sequence seq = new Sequence("start shooting");
seq.add().setShooterRPM(SHOOTER_TARGET_SPEED_RPM);
// Give the shooter wheel time to spin up.
seq.add().setDelayDelta(2);
if (closeToGoal) {
// Shooting from just below the goal straight up.
seq.add().retractShooterHood();
} else {
// Shooting from far from the goal at a flat angle.
seq.add().extendShooterHood();
}
// Start the loader to push the balls.
seq.add().setLoaderSpinnerMotorRPM(LOADER_MOTOR_RPM);
// Wait for the shooter wheel to settle.
Expand Down Expand Up @@ -233,9 +250,22 @@ public static Sequence stopDriveByVision() {
public static Sequence visionAim(){
Sequence seq = new Sequence("vision aim");
seq.add().setShooterRPM(SHOOTER_TARGET_SPEED_RPM);
// Start the loader to push the balls.
seq.add().setLoaderSpinnerMotorRPM(LOADER_MOTOR_RPM);
seq.add().extendShooterHood();
// Allow the robot to move to aim to the vision target while
// the shooter wheel spins up.
seq.add().doVisionAim();
// Wait for the shooter wheel to settle if it hasn't already.
seq.add().waitForShooter();
// Back to normal driving so it can be adjusted while shooting.
seq.add().doArcadeDrive();
// Let the balls out of the loader and into the shooter.
seq.add().unblockShooter();
// Wait for all of the balls to leave.
seq.add().waitForBalls(0);
// Turn off everything.
seq.add().setShooterRPM(0).setLoaderPassthroughMotorOutput(0).setLoaderSpinnerMotorRPM(0).blockShooter();
return seq;
}

Expand Down Expand Up @@ -276,41 +306,29 @@ public static Sequence colourWheelClockwise() {
return seq;
}

// Climber
public static Sequence enableClimbMode() {
Sequence seq = new Sequence("Enable climb mode");
seq.add().enableClimbMode();
// Drive / climb mode.
public static Sequence toggleDriveClimbModes() {
Sequence seq = new Sequence("toggle drive / climb modes");
seq.add().toggleDriveClimbMode();
return seq;
}

public static Sequence enableDriveMode() {
Sequence seq = new Sequence("Enable drive mode");
seq.add().enableDriveMode();
return seq;
}

public static Sequence climberBrake() {
Sequence seq = new Sequence("Climber brake apply");
public static Sequence applyClimberBrake() {
Sequence seq = new Sequence("apply climber brake");
seq.add().applyClimberBrake();
return seq;
}

public static Sequence climberStopBrake() {
Sequence seq = new Sequence("Climber brake release");
public static Sequence releaseClimberBrake() {
Sequence seq = new Sequence("release climber brake");
seq.add().releaseClimberBrake();
return seq;
}

// Buddy Climb
public static Sequence deployBuddyClimber() {
Sequence seq = new Sequence("Deploying buddy climb attatchment");
seq.add().deployBuddyClimb();
return seq;
}

public static Sequence retractBuddyClimber() {
Sequence seq = new Sequence("Retracting buddy climb attatchment");
seq.add().retractBuddyClimb();
// Toggle buddy climb (deploy / retract)
public static Sequence toggleBuddyClimb() {
Sequence seq = new Sequence("toggle buddy climb attatchment");
seq.add().toggleBuddyClimb();
return seq;
}

Expand All @@ -322,13 +340,14 @@ public static Sequence retractBuddyClimber() {
getResetSequence(),
startIntaking(),
stopIntaking(),
startShooting(),
startShooting(true),
stopShooting(),
startIntakingOnly(),
stopIntakingOnly(),
getDriveToWaypointSequence(0, 12, 0),
startLoader(),
stopLoader(),
toggleBuddyClimb(),
visionAim(),
};
}
Loading

0 comments on commit 91d09bb

Please sign in to comment.