overload constructor
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / commands / driving / TurnForTime.java
index f87ec65dd676dbff81e9d98d0d588938205a038a..3ec3974d7b1fb9e9d64338cf4cad744c3a22e7da 100755 (executable)
@@ -1,37 +1,68 @@
 package org.usfirst.frc.team3501.robot.commands.driving;
 
 import org.usfirst.frc.team3501.robot.Constants.Direction;
+import org.usfirst.frc.team3501.robot.Robot;
 
+import edu.wpi.first.wpilibj.Timer;
 import edu.wpi.first.wpilibj.command.Command;
 
+/***
+ * This command turns the robot in a specified direction for a specified
+ * duration in seconds.
+ *
+ * pre-condition: robot is on a flat surface
+ *
+ * post-condition: robot has turned in the specified direction for the specified
+ * time
+ *
+ * @author Meryem, Avi, and Sarvesh
+ *
+ */
+
 public class TurnForTime extends Command {
+  private static final double DEFAULT_SPEED = 0.5;
+  private Direction direction;
+  private double seconds;
+  private Timer timer;
+  private double speed;
+
+  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, DEFAULT_SPEED);
   }
 
   @Override
   protected void initialize() {
+    timer = new Timer();
+    timer.start();
+
+    if (direction == Direction.RIGHT) {
+      Robot.driveTrain.setMotorSpeeds(speed, -speed);
+    } else if (direction == Direction.LEFT) {
+      Robot.driveTrain.setMotorSpeeds(-speed, speed);
+    }
   }
 
   @Override
   protected void execute() {
-    /*
-     * if direction is right make the left motor run forward make the right
-     * motor run backward if direction is left make right motor run forward make
-     * the left motor run backward
-     */
+
   }
 
   @Override
   protected boolean isFinished() {
-    /*
-     * when time is up return true
-     */
+    if (timer.get() >= seconds)
+      return true;
     return false;
   }
 
   @Override
   protected void end() {
+    Robot.driveTrain.setMotorSpeeds(0, 0);
   }
 
   @Override