add javadocs for DriveStraightForTime and include timer code
authorMeryem Esa <meresa14@gmail.com>
Sat, 21 Jan 2017 19:32:25 +0000 (11:32 -0800)
committerjessicabhalerao <jessicabhalerao@gmail.com>
Fri, 27 Jan 2017 03:40:29 +0000 (19:40 -0800)
src/org/usfirst/frc/team3501/robot/commands/driving/DriveStraightForTime.java [new file with mode: 0755]

diff --git a/src/org/usfirst/frc/team3501/robot/commands/driving/DriveStraightForTime.java b/src/org/usfirst/frc/team3501/robot/commands/driving/DriveStraightForTime.java
new file mode 100755 (executable)
index 0000000..c1bf1b7
--- /dev/null
@@ -0,0 +1,57 @@
+package org.usfirst.frc.team3501.robot.commands.driving;
+
+import org.usfirst.frc.team3501.robot.Robot;
+
+import edu.wpi.first.wpilibj.Timer;
+import edu.wpi.first.wpilibj.command.Command;
+
+/**
+ * This command drives the robot for a specified time while adjusting the right
+ * and left motor values so that the robot will drive straight
+ *
+ * parameters:
+ * time in seconds
+ * motorVal
+ *
+ * @author Meryem
+ * @author Niyati
+ *
+ */
+public class DriveStraightForTime extends Command {
+  Timer timer;
+  double time, motorVal;
+
+  public DriveStraightForTime(double time, double motorVal) {
+    requires(Robot.getDriveTrain());
+
+    timer = new Timer();
+    this.time = time;
+
+    this.motorVal = motorVal;
+
+  }
+
+  @Override
+  protected void initialize() {
+    timer.start();
+  }
+
+  @Override
+  protected void execute() {
+  }
+
+  @Override
+  protected boolean isFinished() {
+    return timer.get() >= time;
+  }
+
+  @Override
+  protected void end() {
+    Robot.getDriveTrain().stop();
+  }
+
+  @Override
+  protected void interrupted() {
+    end();
+  }
+}