Skip to content

Commit 0a38149

Browse files
Update auto routines and add java paths
1 parent d80bb63 commit 0a38149

20 files changed

+6521
-178
lines changed

Diff for: jackson-annotations-2.9.4.jar

65.4 KB
Binary file not shown.

Diff for: jackson-core-2.9.4.jar

313 KB
Binary file not shown.

Diff for: jackson-databind-2.9.4.jar

1.28 MB
Binary file not shown.

Diff for: json-simple-1.1.jar

15.7 KB
Binary file not shown.

Diff for: src/org/usfirst/frc/team2363/robot/commands/autonomous/AutoGroup.java

+22-10
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,36 @@
22

33
import org.usfirst.frc.team2363.robot.commands.elevator.RaiseElevator;
44
import org.usfirst.frc.team2363.robot.commands.gripper.EjectCube;
5-
import org.usfirst.frc.team2363.robot.commands.gripper.LowerWrist;
65
import org.usfirst.frc.team2363.robot.subsystems.Elevator.Height;
6+
import org.usfirst.frc.team319.models.SrxTrajectory;
7+
import org.usfirst.frc.team319.robot.commands.FollowTrajectory;
78

9+
import edu.wpi.first.wpilibj.command.Command;
810
import edu.wpi.first.wpilibj.command.CommandGroup;
11+
import edu.wpi.first.wpilibj.command.WaitCommand;
912
/**
1013
*
1114
*/
1215
public class AutoGroup extends CommandGroup {
16+
17+
public AutoGroup(SrxTrajectory path, Height elevatorHeight, double elevatorDelay) {
18+
this(path, elevatorHeight, elevatorDelay, null);
19+
}
1320

14-
public AutoGroup(String path, Height elevatorHeight) {
15-
addParallel(new RaiseElevator(elevatorHeight));
16-
addParallel(new LowerWrist());
17-
// addSequential(new PathRunner(path));
21+
public AutoGroup(SrxTrajectory path, Height elevatorHeight, double elevatorDelay, Command phase2) {
22+
addParallel(new ElevatorCommand(elevatorHeight, elevatorDelay));
23+
addSequential(new FollowTrajectory(path));
1824
addSequential(new EjectCube());
25+
if (phase2 != null) {
26+
addSequential(phase2);
27+
}
28+
}
29+
30+
private class ElevatorCommand extends CommandGroup {
31+
32+
public ElevatorCommand(Height height, double delay) {
33+
addSequential(new WaitCommand(delay));
34+
addSequential(new RaiseElevator(height));
35+
}
1936
}
20-
// public AutoGroup(BoTHTrajectory path, Height elevatorHeight, boolean reverse) {
21-
// addParallel(new RaiseElevator(elevatorHeight));
22-
// addSequential(new PathRunner(path, reverse));
23-
// addSequential(new EjectCube());
24-
// }
2537
}
Original file line numberDiff line numberDiff line change
@@ -1,183 +1,157 @@
11
package org.usfirst.frc.team2363.robot.commands.autonomous;
22

3-
import java.util.HashMap;
4-
import java.util.Map;
5-
3+
import org.iif.th.util.logger.HelixEvents;
64
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;
77
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;
912

1013
import edu.wpi.first.wpilibj.DigitalInput;
1114
import edu.wpi.first.wpilibj.DriverStation;
12-
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
15+
import edu.wpi.first.wpilibj.command.Command;
1316

1417
public class AutoRoutines {
1518

1619
// AutoType Order must match paths order below.
1720
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+
}
2536

26-
private String fileName;
37+
public Height getHeight() {
38+
return height;
39+
}
2740

28-
AutoType(String fileName) {
29-
this.fileName = fileName;
41+
public double getDelay() {
42+
return delay;
3043
}
3144

32-
public String getFileName() {
33-
return fileName;
45+
public Command getPhase2() {
46+
return phase2;
3447
}
3548
}
3649

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;
5055
}
5156

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
6563

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-
}
8464

8565
/*
8666
* Base on Robot Position on the alliance wall & plates states, determines
8767
* which auto routine to run, gripper height, and whether left & right motion
8868
* profiles need to be reverse base on field symmetry.
8969
*
9070
*/
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());
15481
}
15582

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+
}
16293
}
16394

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+
}
166105
}
167106

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+
}
170140
}
171141

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;
182156
}
183157
}

Diff for: src/org/usfirst/frc/team2363/robot/commands/autonomous/PathTesting.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
package org.usfirst.frc.team2363.robot.commands.autonomous;
22

3+
import org.usfirst.frc.team319.paths.SameSideScale;
4+
import org.usfirst.frc.team319.paths.SameSideScalePart2;
5+
import org.usfirst.frc.team319.paths.SameSideScalePart3;
6+
import org.usfirst.frc.team319.paths.SameSideScalePart4;
7+
import org.usfirst.frc.team319.paths.SameSideScalePart5;
38
import org.usfirst.frc.team319.robot.commands.FollowTrajectory;
4-
import org.usfirst.frc.team319.utils.SrxTrajectoryImporter;
59

610
import edu.wpi.first.wpilibj.command.CommandGroup;
711
/**
812
*
913
*/
1014
public class PathTesting extends CommandGroup {
1115

12-
private static final SrxTrajectoryImporter importer = new SrxTrajectoryImporter("/home/lvuser/Autos");
13-
1416
public PathTesting() {
1517
try {
1618
// addSequential(new FollowTrajectory(importer.importSrxTrajectory("OppositeSideScale"), false));
1719
// addSequential(new FollowTrajectory(importer.importSrxTrajectory("OppositeSideScalePart2"), false));
18-
addSequential(new FollowTrajectory(importer.importSrxTrajectory("SameSideScale"), false));
19-
addSequential(new FollowTrajectory(importer.importSrxTrajectory("SameSideScalePart2"), false));
20-
addSequential(new FollowTrajectory(importer.importSrxTrajectory("SameSideScalePart3"), false));
21-
addSequential(new FollowTrajectory(importer.importSrxTrajectory("SameSideScalePart4"), false));
22-
addSequential(new FollowTrajectory(importer.importSrxTrajectory("SameSideScalePart5"), false));
20+
addSequential(new FollowTrajectory(new SameSideScale()));
21+
addSequential(new FollowTrajectory(new SameSideScalePart2()));
22+
addSequential(new FollowTrajectory(new SameSideScalePart3()));
23+
addSequential(new FollowTrajectory(new SameSideScalePart4()));
24+
addSequential(new FollowTrajectory(new SameSideScalePart5()));
2325
} catch (Exception e) {
2426
e.printStackTrace();
2527
}

Diff for: src/org/usfirst/frc/team319/models/SrxTrajectory.java

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
public class SrxTrajectory {
77
public SrxMotionProfile leftProfile;
88
public SrxMotionProfile rightProfile;
9+
10+
public SrxTrajectory() { }
911

1012
public SrxTrajectory(SrxMotionProfile left, SrxMotionProfile right) {
1113
this.leftProfile = left;

0 commit comments

Comments
 (0)