testing TimeDrive
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / commands / driving / TimeDrive.java
CommitLineData
78b997ee
ME
1package org.usfirst.frc.team3501.robot.commands.driving;
2
3import org.usfirst.frc.team3501.robot.Robot;
4
4d1c3598 5import edu.wpi.first.wpilibj.Timer;
78b997ee
ME
6import edu.wpi.first.wpilibj.command.Command;
7
b081e34b 8/***
f9d294b6
ME
9 * This commands make the robot drive for a specified time with the motors set
10 * at a specified value between 1 and -1
78b997ee 11 *
f9d294b6
ME
12 * parameters:
13 * time: how long the robot should drive for - in seconds
14 * motorVal: the motor input to set the motors to
b081e34b
ME
15 *
16 *
78b997ee
ME
17 */
18public class TimeDrive extends Command {
d17d868d 19 Timer timer;
20 double motorVal, time;
21
22 public TimeDrive(final double time, final double motorVal) {
23 requires(Robot.getDriveTrain());
24
25 timer = new Timer();
26 this.time = time;
27 this.motorVal = motorVal;
28 }
29
30 @Override
31 protected void initialize() {
32 timer.start();
d17d868d 33 }
34
35 @Override
36 protected void execute() {
b081e34b
ME
37 Robot.getDriveTrain().setMotorValues(motorVal, motorVal);
38
d17d868d 39 }
40
41 @Override
42 protected boolean isFinished() {
43 return timer.get() >= time;
44 }
45
46 @Override
47 protected void end() {
48 Robot.getDriveTrain().stop();
49 }
50
51 @Override
52 protected void interrupted() {
53 end();
54 }
78b997ee 55}