|
2 | 2 |
|
3 | 3 | import java.util.Map; |
4 | 4 |
|
5 | | -import edu.wpi.first.wpilibj.DriverStation; |
6 | 5 | import edu.wpi.first.wpilibj.command.CommandGroup; |
7 | 6 | import edu.wpi.first.wpilibj.command.WaitCommand; |
8 | 7 |
|
|
12 | 11 | */ |
13 | 12 | public class Autonomous extends CommandGroup implements AutonomousInterface { |
14 | 13 |
|
15 | | - public Autonomous(String startPos, Map<String, String> strategies, double delay, String fmsInput) { |
| 14 | + /** |
| 15 | + * The starting position of the robot relative to alliance member robots |
| 16 | + */ |
| 17 | + public enum Position { |
| 18 | + LEFT ("Left", "L"), |
| 19 | + CENTER ("Center", "C"), |
| 20 | + RIGHT ("Right", "R") |
| 21 | + ; |
| 22 | + |
| 23 | + private final String sdName; |
| 24 | + private final String shortName; |
| 25 | + Position (String sdName, String shortName) { |
| 26 | + this.sdName= sdName; |
| 27 | + this.shortName = shortName; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @return the name that should display on SmartDashboard |
| 32 | + */ |
| 33 | + public String getSDName() { |
| 34 | + return sdName; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @return the short name of the position used in the name of scripts |
| 39 | + */ |
| 40 | + public String getShortName() { |
| 41 | + return shortName; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Strategy chosen by Manipulator before the match starts |
| 47 | + */ |
| 48 | + public enum Strategy { |
| 49 | + AUTO_LINE ("Cross Auto Line"), |
| 50 | + SWITCH ("Switch"), |
| 51 | + SCALE ("Scale"), |
| 52 | + EXCHANGE ("Exchange"), |
| 53 | + SWITCH_SCALE ("Switch and Scale"), |
| 54 | + SWITCH_EXCHANGE ("Switch and Exchange"), |
| 55 | + NOTHING ("Do nothing") |
| 56 | + ; |
| 57 | + |
| 58 | + private final String sdName; |
| 59 | + Strategy (String sdName) { |
| 60 | + this.sdName = sdName; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @return the name that should display on SmartDashboard |
| 65 | + */ |
| 66 | + public String getSDName () { |
| 67 | + return sdName; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Based on the input given, generates a unique script name and executes RunScript with it |
| 73 | + * |
| 74 | + * @param startPos starting position of the robot, either Left, Center, or Right |
| 75 | + * @param strategies a map of the chosen strategies (check robotInit in Robot.java for specifics), with keys being |
| 76 | + * LL, LR, RR, and RL representing the switch and the scale locations respectively |
| 77 | + * @param delay seconds of delay before executing the script. Used for coordinating with alliance partners |
| 78 | + * @param fmsInput A three character String representing the FMS input of the positions of our side switch, scale, |
| 79 | + * and other side switch, respectively |
| 80 | + */ |
| 81 | + public Autonomous(Position startPos, Map<String, Strategy> strategies, double delay, String fmsInput) { |
16 | 82 | String scriptName = ""; |
17 | 83 |
|
18 | | - scriptName += startPos.substring(0, 1); |
| 84 | + scriptName += startPos.getShortName(); |
19 | 85 |
|
20 | | - String chosenStrat = strategies.get(fmsInput.substring(0, 2)); |
| 86 | + Strategy chosenStrat = strategies.get(fmsInput.substring(0, 2)); |
21 | 87 |
|
22 | 88 | // skip the next steps if robot is chosen to do nothing |
23 | | - if (chosenStrat.equals("Do nothing")) |
| 89 | + if (chosenStrat == Strategy.NOTHING) |
24 | 90 | return; |
25 | 91 |
|
26 | 92 | // add switch, switch, and exchange location if going for them, "x" if not |
27 | | - if (chosenStrat.contains("Switch")) |
| 93 | + if (chosenStrat == Strategy.SWITCH || chosenStrat == Strategy.SWITCH_EXCHANGE || chosenStrat == Strategy.SWITCH_SCALE) |
28 | 94 | scriptName += fmsInput.substring(0, 1); |
29 | 95 | else |
30 | 96 | scriptName += "x"; |
31 | 97 |
|
32 | | - if (chosenStrat.contains("Scale")) |
| 98 | + if (chosenStrat == Strategy.SCALE || chosenStrat == Strategy.SWITCH_SCALE) |
33 | 99 | scriptName += fmsInput.substring(1, 2); |
34 | 100 | else |
35 | 101 | scriptName += "x"; |
36 | 102 |
|
37 | | - if (chosenStrat.contains("Exchange")) |
| 103 | + if (chosenStrat == Strategy.EXCHANGE || chosenStrat == Strategy.SWITCH_EXCHANGE) |
38 | 104 | scriptName += "E"; |
39 | 105 | else |
40 | 106 | scriptName += "x"; |
|
0 commit comments