Commit | Line | Data |
---|---|---|
0781814f ME |
1 | package org.usfirst.frc.team3501.robot.commands;\r |
2 | \r | |
3 | import org.usfirst.frc.team3501.robot.Robot;\r | |
4 | \r | |
5 | import edu.wpi.first.wpilibj.Timer;\r | |
6 | import edu.wpi.first.wpilibj.command.Command;\r | |
7 | \r | |
8 | /**\r | |
5e01b2ea ME |
9 | * This command drives the robot for the specified time and specified speed. (If\r |
10 | * a speed is not specified, a default speed is used\r | |
11 | *\r | |
12 | *\r | |
13 | * dependency on subsystems: drivetrain\r | |
14 | *\r | |
15 | * pre-condition: robot is on\r | |
16 | *\r | |
17 | * post condition: robot has driven for the specified amount of time\r | |
0781814f ME |
18 | */\r |
19 | public class DriveForTime extends Command {\r | |
20 | \r | |
21 | private final static double DEFAULT_SPEED = 0.5;\r | |
22 | private double speed;\r | |
23 | private double seconds;\r | |
24 | \r | |
25 | private Timer timer;\r | |
26 | \r | |
27 | public DriveForTime(double seconds, double speed) {\r | |
28 | this.seconds = seconds;\r | |
29 | this.speed = speed;\r | |
30 | }\r | |
31 | \r | |
32 | public DriveForTime(double seconds) {\r | |
33 | this(seconds, DEFAULT_SPEED);\r | |
34 | }\r | |
35 | \r | |
36 | @Override\r | |
37 | protected void initialize() {\r | |
38 | timer = new Timer();\r | |
39 | timer.start();\r | |
40 | \r | |
41 | Robot.driveTrain.setMotorSpeeds(speed, speed);\r | |
42 | }\r | |
43 | \r | |
44 | @Override\r | |
45 | protected void execute() {\r | |
46 | }\r | |
47 | \r | |
48 | @Override\r | |
49 | protected boolean isFinished() {\r | |
50 | if (timer.get() >= seconds)\r | |
51 | return true;\r | |
52 | return false;\r | |
53 | }\r | |
54 | \r | |
55 | @Override\r | |
56 | protected void end() {\r | |
57 | Robot.driveTrain.setMotorSpeeds(0, 0);\r | |
58 | }\r | |
59 | \r | |
60 | @Override\r | |
61 | protected void interrupted() {\r | |
62 | }\r | |
63 | }\r |