implement ToggleWinch command
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / commands / climber / ToggleWinch.java
diff --git a/src/org/usfirst/frc/team3501/robot/commands/climber/ToggleWinch.java b/src/org/usfirst/frc/team3501/robot/commands/climber/ToggleWinch.java
new file mode 100644 (file)
index 0000000..3e60406
--- /dev/null
@@ -0,0 +1,49 @@
+package org.usfirst.frc.team3501.robot.commands.climber;
+
+import org.usfirst.frc.team3501.robot.Robot;
+import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
+
+import edu.wpi.first.wpilibj.command.Command;
+
+/**
+ *
+ */
+public class ToggleWinch extends Command {
+  DriveTrain driveTrain = Robot.getDriveTrain();
+  private double climbingSpeed;
+  private double maintainPositionSpeed;
+
+  public ToggleWinch() {
+    requires(driveTrain);
+    climbingSpeed = driveTrain.CLIMBER_SPEED;
+    maintainPositionSpeed = driveTrain.MAINTAIN_CLIMBED_POSITION;
+  }
+
+  @Override
+  protected void initialize() {
+  }
+
+  @Override
+  protected void execute() {
+    if (driveTrain.shouldBeClimbing) {
+      driveTrain.setMotorValues(climbingSpeed, climbingSpeed);
+    } else {
+      driveTrain.setMotorValues(maintainPositionSpeed, maintainPositionSpeed);
+    }
+  }
+
+  @Override
+  protected boolean isFinished() {
+    return false;
+  }
+
+  @Override
+  protected void end() {
+    driveTrain.shouldBeClimbing = !driveTrain.shouldBeClimbing;
+  }
+
+  @Override
+  protected void interrupted() {
+    end();
+  }
+}