streamline isFinished
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / commands / driving / TurnForTime.java
index 82dff37237ebbecd43458157343dbf16748c43bf..6401fb141a99aa44d7c674e6016eef02a3e9119a 100755 (executable)
@@ -1,5 +1,6 @@
 package org.usfirst.frc.team3501.robot.commands.driving;
 
+import org.usfirst.frc.team3501.robot.Constants.DeadReckoning;
 import org.usfirst.frc.team3501.robot.Constants.Direction;
 import org.usfirst.frc.team3501.robot.Robot;
 
@@ -8,52 +9,61 @@ import edu.wpi.first.wpilibj.command.Command;
 
 /***
  * This command turns the robot in a specified direction for a specified
- * duration.
+ * duration in seconds.
  *
  * pre-condition: robot is on a flat surface
  *
  * post-condition: robot has turned in the specified direction for the specified
  * time
  *
+ * TODO: test for speed/ time constants for specific angles (ex. 30 degrees, 60
+ * degrees, 90 degrees)
+ *
  * @author Meryem, Avi, and Sarvesh
  *
  */
 
 public class TurnForTime extends Command {
-  private final double SPEED = 0.5;
   private Direction direction;
   private double seconds;
   private Timer timer;
+  private double speed;
 
-  public TurnForTime(double seconds, Direction direction) {
+  public TurnForTime(double seconds, Direction direction, double speed) {
     this.seconds = seconds;
     this.direction = direction;
+    this.speed = speed;
+  }
+
+  public TurnForTime(double seconds, Direction direction) {
+    this(seconds, direction, DeadReckoning.DEFAULT_SPEED);
   }
 
   @Override
   protected void initialize() {
     timer = new Timer();
     timer.start();
-  }
 
-  @Override
-  protected void execute() {
     if (direction == Direction.RIGHT) {
-      Robot.driveTrain.setMotorSpeeds(SPEED, -SPEED);
+      Robot.driveTrain.setMotorSpeeds(speed, -speed);
     } else if (direction == Direction.LEFT) {
-      Robot.driveTrain.setMotorSpeeds(-SPEED, SPEED);
+      Robot.driveTrain.setMotorSpeeds(-speed, speed);
     }
   }
 
+  @Override
+  protected void execute() {
+
+  }
+
   @Override
   protected boolean isFinished() {
-    if (timer.get() >= seconds)
-      return true;
-    return false;
+    return (timer.get() >= seconds);
   }
 
   @Override
   protected void end() {
+    Robot.driveTrain.setMotorSpeeds(0, 0);
   }
 
   @Override