diff --git a/src/main/java/frc/robot/OI.java b/src/main/java/frc/robot/OI.java index 5f9236f..71c41bc 100644 --- a/src/main/java/frc/robot/OI.java +++ b/src/main/java/frc/robot/OI.java @@ -8,6 +8,8 @@ package frc.robot; import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.buttons.JoystickButton; +import frc.robot.commands.climb.Shift; /** * This class is the glue that binds the controls on the physical operator @@ -47,10 +49,18 @@ public class OI { private Joystick leftFlight; private Joystick rightFlight; + private JoystickButton engageButton; + private JoystickButton disengageButton; + private OI() { // construct joysticks, buttons here and bind buttons to actions leftFlight = new Joystick(RobotMap.LEFT_JOY); rightFlight = new Joystick(RobotMap.RIGHT_JOY); + + engageButton = new JoystickButton(leftFlight, RobotMap.SHIFT_ENGAGE_BUTTON); + engageButton.whenPressed(new Shift(true)); + disengageButton = new JoystickButton(leftFlight, RobotMap.SHIFT_DISENGAGE_BUTTON); + disengageButton.whenPressed(new Shift(false)); } public double removeDeadband(double y) { diff --git a/src/main/java/frc/robot/RobotMap.java b/src/main/java/frc/robot/RobotMap.java index 223ba38..b51320b 100644 --- a/src/main/java/frc/robot/RobotMap.java +++ b/src/main/java/frc/robot/RobotMap.java @@ -38,8 +38,15 @@ public class DRIVETRAIN { } //gear ratio is 7.58:12:15 + public class CLIMBER { + public static final int SHIFTER_CHANNEL = 0; + } + public static final int LEFT_JOY = 0; public static final int RIGHT_JOY = 1; + public static final int SHIFT_ENGAGE_BUTTON = 5; + public static final int SHIFT_DISENGAGE_BUTTON = 11; + public static final int PRESSURE_SENSOR_PORT = 0; } diff --git a/src/main/java/frc/robot/commands/climb/Shift.java b/src/main/java/frc/robot/commands/climb/Shift.java new file mode 100644 index 0000000..45a415a --- /dev/null +++ b/src/main/java/frc/robot/commands/climb/Shift.java @@ -0,0 +1,27 @@ +package frc.robot.commands.climb; + +import edu.wpi.first.wpilibj.command.Command; +import frc.robot.subsystems.Climber; + +/** + * Command to shift the climber in or out. + */ +public class Shift extends Command { + + private boolean value; + + public Shift(boolean engaged) { + requires(Climber.getInstance()); + this.value = engaged; + } + + @Override + protected void execute() { + Climber.getInstance().setShifter(this.value); + } + + @Override + protected boolean isFinished() { + return true; + } +} diff --git a/src/main/java/frc/robot/commands/drive/Drive.java b/src/main/java/frc/robot/commands/drive/Drive.java index 9bc5645..7b96e76 100644 --- a/src/main/java/frc/robot/commands/drive/Drive.java +++ b/src/main/java/frc/robot/commands/drive/Drive.java @@ -2,6 +2,7 @@ import edu.wpi.first.wpilibj.command.Command; import frc.robot.OI; +import frc.robot.subsystems.Climber; import frc.robot.subsystems.Drivetrain; public class Drive extends Command { @@ -15,7 +16,11 @@ protected void execute() { double left = OI.getInstance().getLeftY(); double right = OI.getInstance().getRightY(); - Drivetrain.getInstance().tankDrive(left, right); + if (!Climber.getInstance().isEngaged()) { + Drivetrain.getInstance().tankDrive(left, right); + } else { + Drivetrain.getInstance().tankDrive(left, left); + } } @Override diff --git a/src/main/java/frc/robot/subsystems/Climber.java b/src/main/java/frc/robot/subsystems/Climber.java new file mode 100644 index 0000000..7e5cf92 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/Climber.java @@ -0,0 +1,37 @@ +package frc.robot.subsystems; + +import edu.wpi.first.wpilibj.Solenoid; +import edu.wpi.first.wpilibj.command.Subsystem; +import frc.robot.RobotMap; + +public class Climber extends Subsystem { + + private Solenoid shifter; + + private static Climber INSTANCE = new Climber(); + + private Climber() { + this.shifter = new Solenoid(RobotMap.CLIMBER.SHIFTER_CHANNEL); + } + + public void setShifter(boolean engaged) { + this.shifter.set(engaged); + } + + public boolean isEngaged() { + return this.shifter.get(); + } + + public static Climber getInstance() { + return INSTANCE; + } + + @Override + protected void initDefaultCommand() { + } + + @Override + protected Object clone() throws CloneNotSupportedException { + throw new CloneNotSupportedException(); + } +}