1
1
package org .usfirst .frc .team2363 .robot .commands .autonomous ;
2
2
3
- import java .util .HashMap ;
4
- import java .util .Map ;
5
-
3
+ import org .iif .th .util .logger .HelixEvents ;
6
4
import org .usfirst .frc .team2363 .robot .subsystems .Elevator .Height ;
5
+ import org .usfirst .frc .team319 .models .GameState ;
6
+ import org .usfirst .frc .team319 .models .GameState .Side ;
7
7
import org .usfirst .frc .team319 .models .SrxTrajectory ;
8
- import org .usfirst .frc .team319 .utils .SrxTrajectoryImporter ;
8
+ import org .usfirst .frc .team319 .paths .CenterSwitch ;
9
+ import org .usfirst .frc .team319 .paths .OppositeSideScale ;
10
+ import org .usfirst .frc .team319 .paths .SameSideScale ;
11
+ import org .usfirst .frc .team319 .paths .SameSideSwitch ;
9
12
10
13
import edu .wpi .first .wpilibj .DigitalInput ;
11
14
import edu .wpi .first .wpilibj .DriverStation ;
12
- import edu .wpi .first .wpilibj .smartdashboard . SmartDashboard ;
15
+ import edu .wpi .first .wpilibj .command . Command ;
13
16
14
17
public class AutoRoutines {
15
18
16
19
// AutoType Order must match paths order below.
17
20
public enum AutoType {
18
- CENTER_SWITCH ("CameraSwitch" ),
19
- SAME_SIDE_SWITCH ("SameSideSwitch" ),
20
- SAME_SIDE_SCALE ("SameSideScale" ),
21
- OPPOSITE_SIDE_SCALE ("OpposideSideScale" ),
22
- BASELINE ("Baseline" ),
23
- PATH_TO_CUBE ("PathToCube" ),
24
- SHORT_PATH ("ShortPath" );
21
+ CENTER_SWITCH (Height .SWITCH , 0 , null ),
22
+ SAME_SIDE_SWITCH (Height .SWITCH , 0 , null ),
23
+ SAME_SIDE_SCALE (Height .SWITCH , 0 , null ),
24
+ OPPOSITE_SIDE_SCALE (Height .SWITCH , 0 , null ),
25
+ BASELINE (Height .GROUND , 0 , null );
26
+
27
+ private Height height ;
28
+ private double delay ;
29
+ private Command phase2 ;
30
+
31
+ private AutoType (Height height , double delay , Command phase2 ) {
32
+ this .height = height ;
33
+ this .delay = delay ;
34
+ this .phase2 = phase2 ;
35
+ }
25
36
26
- private String fileName ;
37
+ public Height getHeight () {
38
+ return height ;
39
+ }
27
40
28
- AutoType ( String fileName ) {
29
- this . fileName = fileName ;
41
+ public double getDelay ( ) {
42
+ return delay ;
30
43
}
31
44
32
- public String getFileName () {
33
- return fileName ;
45
+ public Command getPhase2 () {
46
+ return phase2 ;
34
47
}
35
48
}
36
49
37
- private SrxTrajectoryImporter importer = new SrxTrajectoryImporter ("/home/lvuser" );
38
-
39
- private AutoType autoType = AutoType .BASELINE ;
40
- private String gameData ;
41
- char ourSwitch , opponentSwitch , scale , robotPosition ;
42
- private Height height ;
43
- private Boolean reverse = false ;
44
-
45
- // Hash map allowing look ups of path object based on autonomous path file name.
46
- Map <AutoType , SrxTrajectory > autoMap = new HashMap <AutoType , SrxTrajectory >();
47
-
48
- public AutoRoutines () {
49
- loadPaths ();
50
+ enum AutoMode {
51
+ CENTER_SWITCH ,
52
+ OUR_SIDE_ONLY ,
53
+ SWITCH_SCALE_SCALE ,
54
+ SCALE_ONLY ;
50
55
}
51
56
52
- /*
53
- * Read the autonomous digital switch selections & Load all the autonomous paths to save time during autonomous.
54
- * This routine should be called in RobotInit.
55
- */
56
- public void loadPaths () {
57
- try {
58
- for (AutoType path : AutoType .values ()) {
59
- autoMap .put (path , importer .importSrxTrajectory (path .getFileName ()));
60
- }
61
- } catch (Exception e ) {
62
- e .printStackTrace ();
63
- }
64
- }
57
+ private static DigitalInput left = new DigitalInput (0 );
58
+ private static DigitalInput right = new DigitalInput (1 );
59
+ private static DigitalInput centerSwitch = new DigitalInput (2 );
60
+ private static DigitalInput ourSideOnly = new DigitalInput (3 );
61
+ private static DigitalInput switchScaleScale = new DigitalInput (4 );
62
+ private static DigitalInput scaleOnly = new DigitalInput (5 ); // default
65
63
66
- /*
67
- * Get the locations of the switches and scale with respect to our alliance wall.
68
- */
69
- public void obtainPlateStates () {
70
-
71
- gameData = DriverStation .getInstance ().getGameSpecificMessage ();
72
-
73
- ourSwitch = gameData .charAt (0 );
74
- scale = gameData .charAt (1 );
75
- opponentSwitch = gameData .charAt (2 );
76
-
77
-
78
- // Read the switch setting and plan auto routes based on plate locations above.
79
- determineAutoRoute ();
80
-
81
- updateSmartDashboard ();
82
-
83
- }
84
64
85
65
/*
86
66
* Base on Robot Position on the alliance wall & plates states, determines
87
67
* which auto routine to run, gripper height, and whether left & right motion
88
68
* profiles need to be reverse base on field symmetry.
89
69
*
90
70
*/
91
- public void determineAutoRoute () {
92
-
93
- DigitalInput Left = new DigitalInput (0 );
94
- DigitalInput Right = new DigitalInput (1 );
95
- DigitalInput CenterSwitch = new DigitalInput (2 );
96
- DigitalInput OurSideOnly = new DigitalInput (3 );
97
- DigitalInput SwitchScaleScale = new DigitalInput (4 );
98
- DigitalInput ScaleOnly = new DigitalInput (5 ); // default
99
-
100
- /*
101
- * Switch left & right motor profiles, if robot is on right side of the alliance
102
- * wall, when facing the field OR if robot is at center of alliance wall & our
103
- * switch plate is on the right.
104
- */
105
- if (Left .get ()) {
106
- robotPosition = 'L' ;
107
- reverse = false ;
108
- } else if (Right .get ()) {
109
- robotPosition = 'R' ;
110
- reverse = true ;
111
- } else { // Center Switch
112
- // Motor profile reverse is based on switch location in CenterSwitch case
113
- reverse = (ourSwitch == 'R' )? true : false ;
114
- }
115
-
116
- height = Height .SWITCH ;
117
-
118
- if (CenterSwitch .get ()) {
119
- autoType = AutoType .CENTER_SWITCH ;
120
- } else if (OurSideOnly .get ()) { // Our Side only auto
121
- if (ourSwitch == robotPosition ) {
122
- // Switch is on our side. Go for the switch first over the scale.
123
- autoType = AutoType .SAME_SIDE_SWITCH ;
124
- } else if (scale == robotPosition ) {
125
- // Switch is not on our side, but scale is.
126
- autoType = AutoType .SAME_SIDE_SCALE ;
127
- height = Height .SCALE ;
128
- } else {
129
- // Neither the Switch nor the Scale are on our side.
130
- autoType = AutoType .BASELINE ;
131
- height = Height .GROUND ;
132
- }
133
- } else if (SwitchScaleScale .get ()) {
134
- if (ourSwitch == robotPosition ) {
135
- // Switch is on our side. Go for the switch first over the scale.
136
- autoType = AutoType .SAME_SIDE_SWITCH ;
137
- } else if (scale == robotPosition ){
138
- // Switch is not on our side, but scale is. Go for scale.
139
- autoType = AutoType .SAME_SIDE_SCALE ;
140
- height = Height .SCALE ;
141
- } else {
142
- // Neither the Switch nor the Scale are on our side. Go for opposite side scale.
143
- autoType = AutoType .OPPOSITE_SIDE_SCALE ;
144
- height = Height .SCALE ;
145
- }
146
- } else { // ScaleOnly run
147
- height = Height .SCALE ;
148
- if (scale == robotPosition ){
149
- autoType = AutoType .SAME_SIDE_SCALE ;
150
- } else {
151
- autoType = AutoType .OPPOSITE_SIDE_SCALE ;
152
- }
153
- }
71
+ public static AutoGroup getAutoRoute () {
72
+ GameState state = new GameState (DriverStation .getInstance ().getGameSpecificMessage ());
73
+ Side robotSide = getRobotSide (state );
74
+ AutoType selectedAutoType = getAutoType (getSelectedAutoMode (), state , robotSide );
75
+ HelixEvents .addEvent ("Selected Auto Mode: " + selectedAutoType .name () + ", flipped: " + (robotSide == Side .RIGHT ));
76
+ return new AutoGroup (
77
+ getPath (selectedAutoType , robotSide == Side .RIGHT ),
78
+ selectedAutoType .getHeight (),
79
+ selectedAutoType .getDelay (),
80
+ selectedAutoType .getPhase2 ());
154
81
}
155
82
156
- public SrxTrajectory getPath () {
157
- return autoMap .get (autoType );
158
- }
159
-
160
- public SrxTrajectory getPath (AutoType autoType ) {
161
- return autoMap .get (autoType );
83
+ private static Side getRobotSide (GameState state ) {
84
+ if (centerSwitch .get ()) {
85
+ return state .mySwitchSide ;
86
+ } else {
87
+ if (left .get ()) {
88
+ return Side .LEFT ;
89
+ } else {
90
+ return Side .RIGHT ;
91
+ }
92
+ }
162
93
}
163
94
164
- public Height getHeight () {
165
- return height ;
95
+ private static AutoMode getSelectedAutoMode () {
96
+ if (centerSwitch .get ()) {
97
+ return AutoMode .CENTER_SWITCH ;
98
+ } else if (ourSideOnly .get ()) { // Our Side only auto
99
+ return AutoMode .OUR_SIDE_ONLY ;
100
+ } else if (switchScaleScale .get ()) {
101
+ return AutoMode .SWITCH_SCALE_SCALE ;
102
+ } else { // ScaleOnly run
103
+ return AutoMode .SCALE_ONLY ;
104
+ }
166
105
}
167
106
168
- public boolean getReverse () {
169
- return reverse ;
107
+ static AutoType getAutoType (AutoMode selectedAutoMode , GameState state , Side robotSide ) {
108
+ switch (selectedAutoMode ) {
109
+ case CENTER_SWITCH :
110
+ return AutoType .CENTER_SWITCH ;
111
+ case OUR_SIDE_ONLY :
112
+ if (state .mySwitchSide == robotSide ) {
113
+ // Switch is on our side. Go for the switch first over the scale.
114
+ return AutoType .SAME_SIDE_SWITCH ;
115
+ } else if (state .scaleSide == robotSide ) {
116
+ // Switch is not on our side, but scale is.
117
+ return AutoType .SAME_SIDE_SCALE ;
118
+ } else {
119
+ // Neither the Switch nor the Scale are on our side.
120
+ return AutoType .BASELINE ;
121
+ }
122
+ case SWITCH_SCALE_SCALE :
123
+ if (state .mySwitchSide == robotSide ) {
124
+ // Switch is on our side. Go for the switch first over the scale.
125
+ return AutoType .SAME_SIDE_SWITCH ;
126
+ } else if (state .scaleSide == robotSide ){
127
+ // Switch is not on our side, but scale is. Go for scale.
128
+ return AutoType .SAME_SIDE_SCALE ;
129
+ } else {
130
+ // Neither the Switch nor the Scale are on our side. Go for opposite side scale.
131
+ return AutoType .OPPOSITE_SIDE_SCALE ;
132
+ }
133
+ default :
134
+ if (state .scaleSide == robotSide ) {
135
+ return AutoType .SAME_SIDE_SCALE ;
136
+ } else {
137
+ return AutoType .OPPOSITE_SIDE_SCALE ;
138
+ }
139
+ }
170
140
}
171
141
172
- private void updateSmartDashboard () {
173
-
174
- SmartDashboard .putString ("Game Specific Message" , gameData );
175
- SmartDashboard .putString ("Our Switch Location" , (ourSwitch == 'L' )? "Left" : "Right" );
176
- SmartDashboard .putString ("Scale Location" , (scale == 'L' )? "Left" : "Right" );
177
- SmartDashboard .putString ("Opponent Switch Location" , (opponentSwitch == 'L' )? "Left" : "Right" );
178
-
179
- SmartDashboard .putString ("Robot Position" , (robotPosition == 'L' )? "Left" : (robotPosition == 'R' )? "Right" : "Center" );
180
- SmartDashboard .putString ("Auto Routine Chosen" , autoType .getFileName ());
181
- SmartDashboard .putString ("Gripper Height" , height .toString ());
142
+ private static SrxTrajectory getPath (AutoType autoType , boolean flipped ) {
143
+ switch (autoType ) {
144
+ case CENTER_SWITCH :
145
+ return new CenterSwitch ();
146
+ case OPPOSITE_SIDE_SCALE :
147
+ return new OppositeSideScale (flipped );
148
+ case SAME_SIDE_SCALE :
149
+ return new SameSideScale (flipped );
150
+ case SAME_SIDE_SWITCH :
151
+ return new SameSideSwitch (flipped );
152
+ default :
153
+ break ;
154
+ }
155
+ return null ;
182
156
}
183
157
}
0 commit comments