Change turning to using arcade drive turning to be smoother
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / commands / driving / TurnForTime.java
index d184f58c1208d9543496aaa2badb55add3d62aa7..f0f2ecf6fca6c79e39d7879010832abcbd1506a3 100755 (executable)
@@ -1,30 +1,75 @@
 package org.usfirst.frc.team3501.robot.commands.driving;
 
+import org.usfirst.frc.team3501.robot.Constants;
+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
+ *
+ * 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 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, Constants.Auton.DEFAULT_SPEED);
+  }
+
+  @Override
+  protected void initialize() {
+    timer = new Timer();
+    timer.start();
 
-       public TurnForTime(double seconds) {
-       }
+    if (direction == Direction.RIGHT) {
+      // Robot.driveTrain.drive(speed, -speed);
+      Robot.driveTrain.arcadeDrive(0, speed);
+    } else if (direction == Direction.LEFT) {
+      // Robot.driveTrain.drive(-speed, speed);
+      Robot.driveTrain.arcadeDrive(0, speed);
+    }
+  }
 
-       @Override
-       protected void initialize() {
-       }
+  @Override
+  protected void execute() {
 
-       @Override
-       protected void execute() {
-       }
+  }
 
-       @Override
-       protected boolean isFinished() {
-               return false;
-       }
+  @Override
+  protected boolean isFinished() {
+    return (timer.get() >= seconds);
+  }
 
-       @Override
-       protected void end() {
-       }
+  @Override
+  protected void end() {
+    Robot.driveTrain.drive(0, 0);
+  }
 
-       @Override
-       protected void interrupted() {
-       }
+  @Override
+  protected void interrupted() {
+    end();
+  }
 }