Commit | Line | Data |
---|---|---|
de4f822f D |
1 | package org.usfirst.frc3501.RiceCatRobot.commands; |
2 | ||
3 | import org.usfirst.frc3501.RiceCatRobot.Robot; | |
4 | import org.usfirst.frc3501.RiceCatRobot.RobotMap.Direction; | |
5 | ||
6 | import edu.wpi.first.wpilibj.Timer; | |
7 | import edu.wpi.first.wpilibj.command.Command; | |
8 | ||
9 | /** | |
10 | * This command takes a time in seconds which is how long it should run | |
11 | * | |
12 | */ | |
13 | public class DriveForTime extends Command { | |
14 | private double seconds; | |
15 | private Timer timer; | |
16 | private double speed; | |
17 | ||
18 | /*** | |
19 | * Drive at a fixed speed (speed) for a fixed time (seconds). | |
20 | * | |
21 | * @param seconds | |
22 | * the number of seconds to drive | |
23 | * @param speed | |
24 | * a motor value in the range [-1, 1]. Negative numbers are | |
25 | * interpreted as driving backwards. 0 is stopped. | |
26 | */ | |
27 | public DriveForTime(double seconds, double speed) { | |
28 | this.seconds = seconds; | |
29 | this.speed = -speed; // note: setMotorSpeeds(-1, -1) would be | |
30 | // forward full speed, so we take the opposite | |
31 | // of the input to achieve this. | |
32 | } | |
33 | ||
34 | @Override | |
35 | protected void initialize() { | |
36 | this.setTimeout(seconds); | |
37 | Robot.driveTrain.setMotorSpeeds(speed, speed); | |
38 | } | |
39 | ||
40 | @Override | |
41 | protected void execute() { | |
42 | // nothing here because motors are already set | |
43 | } | |
44 | ||
45 | @Override | |
46 | protected boolean isFinished() { | |
47 | return this.isTimedOut(); | |
48 | } | |
49 | ||
50 | @Override | |
51 | protected void end() { | |
52 | Robot.driveTrain.stop(); | |
53 | } | |
54 | ||
55 | @Override | |
56 | protected void interrupted() { | |
57 | end(); | |
58 | } | |
59 | } |