Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit 5cb2329

Browse files
committed
change Autonomous command to use enums
if you use enums and restrict the input to only stuff you should have, there shouldn't ever be errors in the class itself.
1 parent dd7768a commit 5cb2329

1 file changed

Lines changed: 74 additions & 8 deletions

File tree

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/Autonomous.java

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.Map;
44

5-
import edu.wpi.first.wpilibj.DriverStation;
65
import edu.wpi.first.wpilibj.command.CommandGroup;
76
import edu.wpi.first.wpilibj.command.WaitCommand;
87

@@ -12,29 +11,96 @@
1211
*/
1312
public class Autonomous extends CommandGroup implements AutonomousInterface {
1413

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) {
1682
String scriptName = "";
1783

18-
scriptName += startPos.substring(0, 1);
84+
scriptName += startPos.getShortName();
1985

20-
String chosenStrat = strategies.get(fmsInput.substring(0, 2));
86+
Strategy chosenStrat = strategies.get(fmsInput.substring(0, 2));
2187

2288
// skip the next steps if robot is chosen to do nothing
23-
if (chosenStrat.equals("Do nothing"))
89+
if (chosenStrat == Strategy.NOTHING)
2490
return;
2591

2692
// 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)
2894
scriptName += fmsInput.substring(0, 1);
2995
else
3096
scriptName += "x";
3197

32-
if (chosenStrat.contains("Scale"))
98+
if (chosenStrat == Strategy.SCALE || chosenStrat == Strategy.SWITCH_SCALE)
3399
scriptName += fmsInput.substring(1, 2);
34100
else
35101
scriptName += "x";
36102

37-
if (chosenStrat.contains("Exchange"))
103+
if (chosenStrat == Strategy.EXCHANGE || chosenStrat == Strategy.SWITCH_EXCHANGE)
38104
scriptName += "E";
39105
else
40106
scriptName += "x";

0 commit comments

Comments
 (0)