Commit | Line | Data |
---|---|---|
59cf03f0 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 | import org.usfirst.frc3501.RiceCatRobot.subsystems.DriveTrain; | |
6 | ||
7 | import edu.wpi.first.wpilibj.Timer; | |
8 | import edu.wpi.first.wpilibj.command.Command; | |
9 | ||
10 | /** | |
11 | * This command will drive the specified distance at specified speed. | |
12 | * | |
13 | */ | |
14 | public class DriveDistance extends Command { | |
15 | private double distance; // in units of cm | |
16 | private double speed; | |
17 | ||
18 | public DriveDistance(double distance, double speed) { | |
19 | // Since negative values in setMotorSpeeds(...) are forwards, we reverse | |
20 | // speed here so positive input values will move the robot forwards. | |
21 | this.speed = -speed; | |
22 | this.distance = distance; | |
23 | } | |
24 | ||
25 | @Override | |
26 | protected void initialize() { | |
27 | Robot.driveTrain.resetEncoders(); | |
28 | Robot.driveTrain.setMotorSpeeds(speed, speed); | |
29 | } | |
30 | ||
31 | @Override | |
32 | protected void execute() { | |
33 | // nothing to do since motor speeds already set | |
34 | } | |
35 | ||
36 | @Override | |
37 | protected boolean isFinished() { | |
38 | return Robot.driveTrain.getLeftDistance() >= distance | |
39 | && Robot.driveTrain.getRightDistance() >= distance; | |
40 | } | |
41 | ||
42 | @Override | |
43 | protected void end() { | |
44 | Robot.driveTrain.stop(); | |
45 | } | |
46 | ||
47 | @Override | |
48 | protected void interrupted() { | |
49 | end(); | |
50 | } | |
51 | } |