Commit | Line | Data |
---|---|---|
78b997ee ME |
1 | package org.usfirst.frc.team3501.robot.commands.driving; |
2 | ||
3 | import org.usfirst.frc.team3501.robot.Robot; | |
4 | ||
4d1c3598 | 5 | import edu.wpi.first.wpilibj.Timer; |
78b997ee ME |
6 | import edu.wpi.first.wpilibj.command.Command; |
7 | ||
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 | |
78b997ee ME |
15 | */ |
16 | public class TimeDrive extends Command { | |
d17d868d | 17 | Timer timer; |
18 | double motorVal, time; | |
19 | ||
20 | public TimeDrive(final double time, final double motorVal) { | |
21 | requires(Robot.getDriveTrain()); | |
22 | ||
23 | timer = new Timer(); | |
24 | this.time = time; | |
25 | this.motorVal = motorVal; | |
26 | } | |
27 | ||
28 | @Override | |
29 | protected void initialize() { | |
30 | timer.start(); | |
31 | Robot.getDriveTrain().setMotorValues(motorVal, motorVal); | |
32 | } | |
33 | ||
34 | @Override | |
35 | protected void execute() { | |
36 | } | |
37 | ||
38 | @Override | |
39 | protected boolean isFinished() { | |
40 | return timer.get() >= time; | |
41 | } | |
42 | ||
43 | @Override | |
44 | protected void end() { | |
45 | Robot.getDriveTrain().stop(); | |
46 | } | |
47 | ||
48 | @Override | |
49 | protected void interrupted() { | |
50 | end(); | |
51 | } | |
78b997ee | 52 | } |