create and implement code for DriveForTime command
authorMeryem Esa <meresa14@gmail.com>
Wed, 10 Feb 2016 05:57:38 +0000 (21:57 -0800)
committerKevin Zhang <icestormf1@gmail.com>
Tue, 16 Feb 2016 19:37:01 +0000 (11:37 -0800)
src/org/usfirst/frc/team3501/robot/commands/DriveForTime.java [new file with mode: 0755]

diff --git a/src/org/usfirst/frc/team3501/robot/commands/DriveForTime.java b/src/org/usfirst/frc/team3501/robot/commands/DriveForTime.java
new file mode 100755 (executable)
index 0000000..c44590a
--- /dev/null
@@ -0,0 +1,55 @@
+package org.usfirst.frc.team3501.robot.commands;\r
+\r
+import org.usfirst.frc.team3501.robot.Robot;\r
+\r
+import edu.wpi.first.wpilibj.Timer;\r
+import edu.wpi.first.wpilibj.command.Command;\r
+\r
+/**\r
+ * This command\r
+ */\r
+public class DriveForTime extends Command {\r
+\r
+  private final static double DEFAULT_SPEED = 0.5;\r
+  private double speed;\r
+  private double seconds;\r
+\r
+  private Timer timer;\r
+\r
+  public DriveForTime(double seconds, double speed) {\r
+    this.seconds = seconds;\r
+    this.speed = speed;\r
+  }\r
+\r
+  public DriveForTime(double seconds) {\r
+    this(seconds, DEFAULT_SPEED);\r
+  }\r
+\r
+  @Override\r
+  protected void initialize() {\r
+    timer = new Timer();\r
+    timer.start();\r
+\r
+    Robot.driveTrain.setMotorSpeeds(speed, speed);\r
+  }\r
+\r
+  @Override\r
+  protected void execute() {\r
+  }\r
+\r
+  @Override\r
+  protected boolean isFinished() {\r
+    if (timer.get() >= seconds)\r
+      return true;\r
+    return false;\r
+  }\r
+\r
+  @Override\r
+  protected void end() {\r
+    Robot.driveTrain.setMotorSpeeds(0, 0);\r
+  }\r
+\r
+  @Override\r
+  protected void interrupted() {\r
+  }\r
+}\r