Commit | Line | Data |
---|---|---|
c9ab1206 KZ |
1 | package org.usfirst.frc3501.RiceCatRobot.commands; |
2 | ||
4b8a525f | 3 | import org.usfirst.frc3501.RiceCatRobot.robot.Robot; |
ba4d69ce | 4 | import org.usfirst.frc3501.RiceCatRobot.subsystems.DriveTrain; |
c9ab1206 KZ |
5 | |
6 | import edu.wpi.first.wpilibj.command.Command; | |
7 | ||
8 | public class MoveDistance extends Command { | |
aa9c330e D |
9 | private double distance; // in units of TODO |
10 | private double minSpeed; // in range (0, 1] | |
11 | private double maxSpeed; // in range (0, 1] | |
12 | ||
13 | public MoveDistance(double distance, double minSpeed, double maxSpeed) { | |
14 | requires(Robot.driveTrain); | |
15 | this.distance = distance; | |
16 | this.minSpeed = Math.min(minSpeed, maxSpeed); | |
17 | this.maxSpeed = Math.max(minSpeed, maxSpeed); | |
18 | } | |
19 | ||
20 | @Override | |
21 | protected void initialize() { | |
22 | Robot.driveTrain.resetEncoders(); | |
23 | } | |
24 | ||
25 | @Override | |
26 | protected void execute() { | |
27 | // TODO: create a math helper library and move this function there | |
28 | double speed = 4 * (minSpeed - maxSpeed) | |
29 | * Math.pow((Robot.driveTrain.getAverageSpeed() / distance - 0.5), 2) | |
30 | + maxSpeed; | |
31 | Robot.driveTrain.setMotorSpeeds(speed, speed); | |
32 | } | |
33 | ||
34 | @Override | |
35 | protected boolean isFinished() { | |
36 | return Robot.driveTrain.getLeftDistance() > distance | |
37 | && Robot.driveTrain.getRightDistance() > distance; | |
38 | } | |
39 | ||
40 | @Override | |
41 | protected void end() { | |
42 | Robot.driveTrain.stop(); | |
43 | } | |
44 | ||
45 | @Override | |
46 | protected void interrupted() { | |
47 | end(); | |
48 | } | |
c9ab1206 | 49 | } |