--- /dev/null
+package org.usfirst.frc3501.RiceCatRobot.commands;
+
+import org.usfirst.frc3501.RiceCatRobot.Robot;
+import org.usfirst.frc3501.RiceCatRobot.RobotMap.Direction;
+
+import edu.wpi.first.wpilibj.Timer;
+import edu.wpi.first.wpilibj.command.Command;
+
+/**
+ * This command takes a time in seconds which is how long it should run
+ *
+ */
+public class DriveForTime extends Command {
+ private double seconds;
+ private Timer timer;
+ private double speed;
+
+ /***
+ * Drive at a fixed speed (speed) for a fixed time (seconds).
+ *
+ * @param seconds
+ * the number of seconds to drive
+ * @param speed
+ * a motor value in the range [-1, 1]. Negative numbers are
+ * interpreted as driving backwards. 0 is stopped.
+ */
+ public DriveForTime(double seconds, double speed) {
+ this.seconds = seconds;
+ this.speed = -speed; // note: setMotorSpeeds(-1, -1) would be
+ // forward full speed, so we take the opposite
+ // of the input to achieve this.
+ }
+
+ @Override
+ protected void initialize() {
+ this.setTimeout(seconds);
+ Robot.driveTrain.setMotorSpeeds(speed, speed);
+ }
+
+ @Override
+ protected void execute() {
+ // nothing here because motors are already set
+ }
+
+ @Override
+ protected boolean isFinished() {
+ return this.isTimedOut();
+ }
+
+ @Override
+ protected void end() {
+ Robot.driveTrain.stop();
+ }
+
+ @Override
+ protected void interrupted() {
+ end();
+ }
+}