b614a076416dde37517d9670a15d047fa8bee1b2
1 package org
.usfirst
.frc3501
.RiceCatRobot
.commands
;
3 import org
.usfirst
.frc3501
.RiceCatRobot
.Robot
;
4 import org
.usfirst
.frc3501
.RiceCatRobot
.RobotMap
.Direction
;
5 import org
.usfirst
.frc3501
.RiceCatRobot
.subsystems
.DriveTrain
;
7 import edu
.wpi
.first
.wpilibj
.Timer
;
8 import edu
.wpi
.first
.wpilibj
.command
.Command
;
11 * This command takes a time in seconds which is how long it should run
14 public class DriveFor
extends Command
{
15 private double seconds
;
18 private Direction direction
;
20 public DriveFor(double seconds
, double speed
, Direction direction
) {
21 // limit speed to the range [0, MOTOR_MAX_VAL]
22 this.speed
= Math
.max(speed
, -speed
);
23 this.speed
= Math
.min(speed
, DriveTrain
.MOTOR_MAX_VAL
);
25 this.seconds
= seconds
;
26 this.direction
= direction
;
30 protected void initialize() {
37 protected void execute() {
38 if (direction
== Direction
.FORWARD
) {
39 Robot
.driveTrain
.setMotorSpeeds(-speed
, -speed
);
40 } else if (direction
== Direction
.BACKWARD
) {
41 Robot
.driveTrain
.setMotorSpeeds(speed
, speed
);
46 protected boolean isFinished() {
47 return timer
.get() > seconds
;
51 protected void end() {
52 Robot
.driveTrain
.setMotorSpeeds(0, 0);
56 protected void interrupted() {