Skip to content

Commit

Permalink
Merge pull request #10 from BHSSFRC/feature/climber
Browse files Browse the repository at this point in the history
Basic climber subsystem
  • Loading branch information
c-x-berger authored Feb 2, 2019
2 parents 9bf226d + 4733c04 commit 86e0048
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/frc/robot/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/RobotMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
27 changes: 27 additions & 0 deletions src/main/java/frc/robot/commands/climb/Shift.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
7 changes: 6 additions & 1 deletion src/main/java/frc/robot/commands/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/frc/robot/subsystems/Climber.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 86e0048

Please sign in to comment.