Skip to content

Commit

Permalink
Finished Modularized Autos Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Predaking945 committed Nov 29, 2023
1 parent 5323e48 commit aff9c73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/main/java/frc/team3128/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ public static class AutoConstants {
public static final double RAMP_THRESHOLD = 9; //8, 10
public static final double DRIVE_SPEED = Units.inchesToMeters(30); //30, 40

// HashMap to convert auto name into a list of modularized autos
public static final HashMap<String, ArrayList<String>> MODULARIZED_AUTOS = new HashMap<String, ArrayList<String>>();

// TODO: finish all autos
// Put other autos when needed
static {
MODULARIZED_AUTOS.put("b-cable_1Cone+1Cube", Trajectories.stringToList("b-cable_pickup-Cube1&score-Cube1"));
// MODULARIZED_AUTOS.put()
MODULARIZED_AUTOS.put("b_hp_1Cone+1.5Cube", Trajectories.stringToList("b-hp_pickup-Cube4&score-Cube4&pickup-Cube3&return-Cube3"));
}

}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/frc/team3128/autonomous/AutoPrograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ public AutoPrograms() {
initAutoSelector();
}


// String of auto names to be listed in Narwhal Dashboard
private void initAutoSelector() {
final String[] autoStrings = new String[] {
//Blue Autos
//Cable
"cable_1Cone+1Cube", "cable_1Cone+1.5Cube","cable_1Cone+2Cube", "cable_1Cone+1.5Cube+Climb", "cable_pickup_Cube1", "cable_score_Cube1","cable_pickup_Cube2","cable_return_Cube2",
"cable_1Cone+1Cube", "cable_1Cone+1.5Cube","cable_1Cone+2Cube", "cable_1Cone+1.5Cube+Climb",
//Mid
"mid_1Cone+Climb","mid_1Cone+0.5Cube+Climb", "mid_1Cone+1Cube+Climb","mid_pickup_Cube2","mid_score_Cube2","mid_balance",
"mid_1Cone+Climb","mid_1Cone+0.5Cube+Climb", "mid_1Cone+1Cube+Climb",
//Hp
"hp_1Cone+1Cube","hp_pickup_Cube4","hp_score_Cube4","hp_pickup_Cube3","hp_return_Cube3",
"hp_1Cone+1Cube",

"scuffedClimb"
};
Expand All @@ -58,7 +60,7 @@ else if (selectedAutoName == "scuffedClimb") {

else {
selectedAutoName = ((DriverStation.getAlliance() == Alliance.Red) ? "r_" : "b_") + selectedAutoName;
autoCommand = Trajectories.get(MODULARIZED_AUTOS.get("b-cable_1Cone+1Cube"));
autoCommand = Trajectories.get(MODULARIZED_AUTOS.get(selectedAutoName));
}

return autoCommand.beforeStarting(Trajectories.resetAuto());
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/frc/team3128/autonomous/Trajectories.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@ public class Trajectories {
private static SwerveAutoBuilder builder;

public static void initTrajectories() {
// modularized autos
final String[] trajectoryNames = {
//Blue Autos
//Cable
"b_cable_1Cone+1Cube", "b_cable_1Cone+1.5Cube","b_cable_1Cone+2Cube", "b_cable_1Cone+1.5Cube+Climb", "b_cable_pickup_Cube1", "b_cable_score_Cube1","b_cable_pickup_Cube2","b_cable_return_Cube2",
"b-cable_pickup-Cube1", "b-cable_score-Cube1","b-cable_pickup-Cube2","b-cable_return-Cube2",
//Mid
"b_mid_1Cone+Climb","b_mid_1Cone+0.5Cube+Climb", "b_mid_1Cone+1Cube+Climb","b_mid_pickup_Cube2","b_mid_score_Cube2","b_mid_balance",
"b-mid_pickup-Cube2","b-mid_score-Cube2","b-mid_balance",
//Hp
"b_hp_1Cone+1Cube","b_hp_pickup_Cube4","b_hp_score_Cube4","b_hp_pickup_Cube3","b_hp_return_Cube3",
"b-hp_pickup-Cube4","b-hp_score-Cube4","b-hp_pickup-Cube3","b-hp_return-Cube3",

//Red Autos
// add autos if needed
//Cable
"r_cable_1Cone+1Cube", "r_cable_1Cone+1.5Cube","r_cable_1Cone+2Cube", "r_cable_1Cone+1.5Cube+Climb",
"r-cable_pickup-Cube1",
//Mid
"r_mid_1Cone+Climb","r_mid_1Cone+0.5Cube+Climb","r_mid_1Cone+1Cube+Climb",
"r-mid_pickup-Cube2",
//Hp
"r_hp_1Cone+1Cube",
"r-hp_pickup-Cube4",
};

CommandEventMap.put("ScoreConeHigh", sequence(score(Position.HIGH_CONE, true)));
Expand Down Expand Up @@ -101,6 +103,8 @@ public static CommandBase generateAuto(PathPlannerTrajectory trajectory) {
return builder.fullAuto(trajectory);
}

// Separates auto strings into a list of strings containing the prefix (e.g. b-hp) along with as many suffixes (e.g. pickup-Cube1)
// Ex: "b-cable_pickup-Cube1&score-Cube1" -> {"b-cable_pickup-Cube1", "b-cable_score-Cube1"}
public static ArrayList<String> stringToList(String name) {
String prefix = name.split("_")[0];
String[] autoStrings = name.split("_")[1].split("&");
Expand All @@ -111,6 +115,7 @@ public static ArrayList<String> stringToList(String name) {
return ret;
}

// conjoins list of strings into one complete trajectory
public static CommandBase get(ArrayList<String> names) {
ArrayList<PathPlannerTrajectory> curTrajectories = new ArrayList<PathPlannerTrajectory>();
for (String name : names) {
Expand Down

0 comments on commit aff9c73

Please sign in to comment.