Implement MaintainWinchSpeed
authorShivani Ghanta <shivani.oghanta@gmail.com>
Sat, 28 Jan 2017 19:54:22 +0000 (11:54 -0800)
committerCindy Zhang <cindyzyx9@gmail.com>
Sat, 4 Feb 2017 19:10:35 +0000 (11:10 -0800)
src/org/usfirst/frc/team3501/robot/Constants.java
src/org/usfirst/frc/team3501/robot/commands/climber/MaintainWinchSpeed.java [new file with mode: 0644]

index 4f5d9e9602c3b2f7cfda0c029e61abf808576704..2a81945e7c70409c50e30e52fb2fddd490cb2edb 100644 (file)
@@ -56,10 +56,13 @@ public class Constants {
   public static class Climber {
     // MOTOR CONTROLLERS
     public static final int MOTOR_VAL = 1;
+    public static final int MAINTAIN_MOTOR_VAL = 1;
+
   }
 
   public static class Intake {
     public static final int INTAKE_ROLLER_PORT = 0;
+
   }
 
   public static enum Direction {
diff --git a/src/org/usfirst/frc/team3501/robot/commands/climber/MaintainWinchSpeed.java b/src/org/usfirst/frc/team3501/robot/commands/climber/MaintainWinchSpeed.java
new file mode 100644 (file)
index 0000000..6d11b64
--- /dev/null
@@ -0,0 +1,71 @@
+package org.usfirst.frc.team3501.robot.commands.climber;
+
+import org.usfirst.frc.team3501.robot.Constants;
+import org.usfirst.frc.team3501.robot.Robot;
+
+import edu.wpi.first.wpilibj.Timer;
+import edu.wpi.first.wpilibj.command.Command;
+
+/**
+ * This command runs the winch at a specified speed and time in seconds when the
+ * button triggering it is pressed. This command also makes the drive train
+ * motors run because the winch is controlled by the drive train.
+ *
+ * pre-condition: This command is run by a button in OI. The robot must be
+ * attached to the rope.
+ *
+ * post-condition: Winch motor set to a specified speed for a specified time.
+ *
+ * @param motorVal
+ *          value range is from -1 to 1
+ * @param time
+ *          in seconds
+ * @author shivanighanta
+ *
+ */
+public class MaintainWinchSpeed extends Command {
+  Timer timer;
+  private double time;
+  private double motorVal;
+
+  /**
+   * See JavaDoc comment in class for details
+   *
+   * @param time
+   *          time in seconds to run the winch
+   * @param motorVal
+   *          value range is from -1 to 1
+   */
+  public MaintainWinchSpeed(double time, double motorVal) {
+    requires(Robot.getDriveTrain());
+    this.time = time;
+    this.motorVal = motorVal;
+  }
+
+  @Override
+  protected void initialize() {
+    timer.start();
+  }
+
+  @Override
+  protected void execute() {
+    Robot.getDriveTrain().setMotorValues(Constants.Climber.MAINTAIN_MOTOR_VAL,
+        Constants.Climber.MAINTAIN_MOTOR_VAL);
+
+  }
+
+  @Override
+  protected boolean isFinished() {
+    return timer.get() >= time;
+  }
+
+  @Override
+  protected void end() {
+    Robot.getDriveTrain().stop();
+  }
+
+  @Override
+  protected void interrupted() {
+    end();
+  }
+}