add DriveForTime command
authorDavid <david.dobervich@gmail.com>
Fri, 20 Nov 2015 18:42:23 +0000 (10:42 -0800)
committerDavid <david.dobervich@gmail.com>
Fri, 20 Nov 2015 18:42:23 +0000 (10:42 -0800)
src/org/usfirst/frc3501/RiceCatRobot/commands/DriveFor.java [deleted file]
src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTime.java [new file with mode: 0644]
src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTimesSequence.java

diff --git a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveFor.java b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveFor.java
deleted file mode 100644 (file)
index b614a07..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.usfirst.frc3501.RiceCatRobot.commands;
-
-import org.usfirst.frc3501.RiceCatRobot.Robot;
-import org.usfirst.frc3501.RiceCatRobot.RobotMap.Direction;
-import org.usfirst.frc3501.RiceCatRobot.subsystems.DriveTrain;
-
-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 DriveFor extends Command {
-  private double seconds;
-  private double speed;
-  private Timer timer;
-  private Direction direction;
-
-  public DriveFor(double seconds, double speed, Direction direction) {
-    // limit speed to the range [0, MOTOR_MAX_VAL]
-    this.speed = Math.max(speed, -speed);
-    this.speed = Math.min(speed, DriveTrain.MOTOR_MAX_VAL);
-
-    this.seconds = seconds;
-    this.direction = direction;
-  }
-
-  @Override
-  protected void initialize() {
-    timer = new Timer();
-    timer.reset();
-    timer.start();
-  }
-
-  @Override
-  protected void execute() {
-    if (direction == Direction.FORWARD) {
-      Robot.driveTrain.setMotorSpeeds(-speed, -speed);
-    } else if (direction == Direction.BACKWARD) {
-      Robot.driveTrain.setMotorSpeeds(speed, speed);
-    }
-  }
-
-  @Override
-  protected boolean isFinished() {
-    return timer.get() > seconds;
-  }
-
-  @Override
-  protected void end() {
-    Robot.driveTrain.setMotorSpeeds(0, 0);
-  }
-
-  @Override
-  protected void interrupted() {
-    end();
-  }
-}
\ No newline at end of file
diff --git a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTime.java b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTime.java
new file mode 100644 (file)
index 0000000..9f7d91b
--- /dev/null
@@ -0,0 +1,59 @@
+package org.usfirst.frc3501.RiceCatRobot.commands;
+
+import org.usfirst.frc3501.RiceCatRobot.Robot;
+import org.usfirst.frc3501.RiceCatRobot.RobotMap.Direction;
+import org.usfirst.frc3501.RiceCatRobot.subsystems.DriveTrain;
+
+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 double speed;
+  private Timer timer;
+  private Direction direction;
+
+  public DriveForTime(double seconds, double speed, Direction direction) {
+    // limit speed to the range [0, MOTOR_MAX_VAL]
+    this.speed = Math.max(speed, -speed);
+    this.speed = Math.min(speed, DriveTrain.MOTOR_MAX_VAL);
+
+    this.seconds = seconds;
+    this.direction = direction;
+  }
+
+  @Override
+  protected void initialize() {
+    timer = new Timer();
+    timer.reset();
+    timer.start();
+  }
+
+  @Override
+  protected void execute() {
+    if (direction == Direction.FORWARD) {
+      Robot.driveTrain.setMotorSpeeds(-speed, -speed);
+    } else if (direction == Direction.BACKWARD) {
+      Robot.driveTrain.setMotorSpeeds(speed, speed);
+    }
+  }
+
+  @Override
+  protected boolean isFinished() {
+    return timer.get() > seconds;
+  }
+
+  @Override
+  protected void end() {
+    Robot.driveTrain.setMotorSpeeds(0, 0);
+  }
+
+  @Override
+  protected void interrupted() {
+    end();
+  }
+}
\ No newline at end of file
index d5d4b449292ec9879895768989f6c6fe1226c9df..8b1321df4cbf8cf8cabd2fb02631d074bda27f9a 100644 (file)
@@ -31,7 +31,7 @@ public class DriveForTimesSequence extends CommandGroup {
       double time = timings[i][0];
       double speed = timings[i][1];
 
-      addSequential(new DriveFor(time, speed, direction));
+      addSequential(new DriveForTime(time, speed, direction));
     }
   }
 }
\ No newline at end of file