Finish implementing MaintainClimbedPosition
authorShivani Ghanta <shivani.oghanta@gmail.com>
Tue, 31 Jan 2017 03:57:58 +0000 (19:57 -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/MaintainClimbedPosition.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/commands/climber/MaintainWinchSpeed.java [deleted file]
src/org/usfirst/frc/team3501/robot/commands/climber/RunWinch.java
src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java

index 2a81945e7c70409c50e30e52fb2fddd490cb2edb..d34f79a5ce64caa239e25929ddf57744e1ebfd9e 100644 (file)
@@ -53,13 +53,6 @@ public class Constants {
     public static final SPI.Port GYRO_PORT = SPI.Port.kOnboardCS0;
   }
 
-  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;
 
diff --git a/src/org/usfirst/frc/team3501/robot/commands/climber/MaintainClimbedPosition.java b/src/org/usfirst/frc/team3501/robot/commands/climber/MaintainClimbedPosition.java
new file mode 100644 (file)
index 0000000..1ddde59
--- /dev/null
@@ -0,0 +1,65 @@
+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;
+
+/**
+ * This command runs the winch at a specified speed and time in seconds when the
+ * robot has completed the climb and 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 have
+ * completed climbing.
+ *
+ * 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 MaintainClimbedPosition extends Command {
+  private double time;
+
+  /**
+   * See JavaDoc comment in class for details
+   *
+   * @param time
+   *          time in seconds to run the winch
+   */
+  public MaintainClimbedPosition(double time) {
+    requires(Robot.getDriveTrain());
+    this.time = time;
+  }
+
+  @Override
+  protected void initialize() {
+  }
+
+  @Override
+  protected void execute() {
+    Robot.getDriveTrain().setMotorValues(DriveTrain.MAINTAIN_CLIMBED_POSITION,
+        DriveTrain.MAINTAIN_CLIMBED_POSITION);
+
+  }
+
+  @Override
+  protected boolean isFinished() {
+    return timeSinceInitialized() >= time;
+  }
+
+  @Override
+  protected void end() {
+    Robot.getDriveTrain().stop();
+  }
+
+  @Override
+  protected void interrupted() {
+    end();
+  }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/commands/climber/MaintainWinchSpeed.java b/src/org/usfirst/frc/team3501/robot/commands/climber/MaintainWinchSpeed.java
deleted file mode 100644 (file)
index 9741eac..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-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) {
-    timer = new Timer();
-    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();
-  }
-}
index 2428aff2345244364035e842c40042626d27c74d..7858384dac649f30555d40761e6fa52b6e09ebd5 100644 (file)
@@ -2,7 +2,6 @@ package org.usfirst.frc.team3501.robot.commands.climber;
 
 import org.usfirst.frc.team3501.robot.Robot;
 
-import edu.wpi.first.wpilibj.Timer;
 import edu.wpi.first.wpilibj.command.Command;
 
 /**
@@ -24,7 +23,6 @@ import edu.wpi.first.wpilibj.command.Command;
  */
 
 public class RunWinch extends Command {
-  Timer timer;
   private double time;
   private double motorVal;
 
@@ -34,18 +32,16 @@ public class RunWinch extends Command {
    * @param time
    *          time in seconds to run the winch
    * @param motorVal
-   *          value range is from -1 to 1
+   *          value range is frosm -1 to 1
    */
   public RunWinch(double time, double motorVal) {
     requires(Robot.getDriveTrain());
-    timer = new Timer();
     this.time = time;
     this.motorVal = motorVal;
   }
 
   @Override
   protected void initialize() {
-    timer.start();
   }
 
   @Override
@@ -56,7 +52,7 @@ public class RunWinch extends Command {
 
   @Override
   protected boolean isFinished() {
-    return timer.get() >= time;
+    return timeSinceInitialized() >= time;
   }
 
   @Override
index 29dc7121ead6f0b2f67cbe0e42e218e49c1a5a02..5c94e53e2b6e63f8c99215fa0bc9f71355fbd8cd 100644 (file)
@@ -22,8 +22,9 @@ public class DriveTrain extends Subsystem {
   public static final int ENCODER_PULSES_PER_REVOLUTION = 256;
   public static final double INCHES_PER_PULSE = WHEEL_DIAMETER * Math.PI
       / ENCODER_PULSES_PER_REVOLUTION;
-
+  public static final int MAINTAIN_CLIMBED_POSITION = 1;
   private static DriveTrain driveTrain;
+
   private final CANTalon frontLeft, frontRight, rearLeft, rearRight;
   private final RobotDrive robotDrive;
   private final Encoder leftEncoder, rightEncoder;