dd016bd2 |
1 | package org.usfirst.frc.team3501.robot.commands.driving; |
2 | |
3 | import org.usfirst.frc.team3501.robot.Robot; |
4 | |
ba083d18 |
5 | import edu.wpi.first.wpilibj.command.Command; |
dd016bd2 |
6 | |
ba083d18 |
7 | public class DriveStraight extends Command { |
dd016bd2 |
8 | |
ba083d18 |
9 | double speedL, speedR, tempSpeedR, seconds; |
10 | // double moveR = Robot.getDriveTrain().getLeftSpeed(); |
11 | // double moveL = Robot.getDriveTrain().getRightSpeed(); |
12 | |
13 | public DriveStraight(double seconds) { |
14 | this.seconds = seconds; |
15 | requires(Robot.getDriveTrain()); |
16 | speedL = Robot.getDriveTrain().getLeftSpeed(); |
17 | speedR = Robot.getDriveTrain().getRightSpeed(); |
18 | } |
19 | |
20 | @Override |
21 | public void initialize() { |
22 | this.setTimeout(seconds); |
dd016bd2 |
23 | } |
24 | |
ba083d18 |
25 | @Override |
26 | public void execute() { |
27 | Double mvR = null, mvL = null; |
28 | final double maxSpeedOneR = 16.1; |
29 | final double maxSpeedTwoR = 49; |
30 | final double maxSpeedThreeR = 75.2; |
31 | final double maxSpeedOneL = 13.8; |
32 | final double maxSpeedTwoL = 46.9; |
33 | final double maxSpeedThreeL = 74; |
34 | speedL = Robot.getDriveTrain().getLeftSpeed(); |
35 | speedR = Robot.getDriveTrain().getRightSpeed(); |
36 | tempSpeedR = speedR; |
37 | speedR = speedL; |
38 | speedL = tempSpeedR; |
39 | if (speedR <= maxSpeedOneR) { |
40 | mvR = speedR / maxSpeedOneR * 5; |
41 | } else if (speedR <= maxSpeedTwoR) { |
42 | mvR = speedR / maxSpeedTwoR * 2.5; |
43 | } else if (speedR <= maxSpeedThreeR) { |
44 | mvR = speedR / maxSpeedThreeR * 1.66; |
45 | } |
46 | if (speedL <= maxSpeedOneL) { |
47 | mvL = speedL / maxSpeedOneL * 5; |
48 | } else if (speedL <= maxSpeedTwoL) { |
49 | mvL = speedL / maxSpeedTwoL * 2.5; |
50 | } else if (speedL <= maxSpeedThreeL) { |
51 | mvL = speedL / maxSpeedThreeL * 1.66; |
dd016bd2 |
52 | } |
ba083d18 |
53 | if (mvR != null && mvL != null) { |
54 | Robot.getDriveTrain().setMotorValues(mvR, mvL); // we changed move to // |
55 | // speed |
56 | } |
57 | } |
58 | |
59 | @Override |
60 | public boolean isFinished() { |
61 | return this.isTimedOut(); |
62 | } |
dd016bd2 |
63 | |
ba083d18 |
64 | @Override |
65 | public void end() { |
66 | Robot.getDriveTrain().stop(); |
dd016bd2 |
67 | } |
68 | } |