From aff9c73909830468d4d9df6c39aac05a1c0686cf Mon Sep 17 00:00:00 2001 From: Predaking945 Date: Tue, 28 Nov 2023 19:03:42 -0800 Subject: [PATCH] Finished Modularized Autos Code --- src/main/java/frc/team3128/Constants.java | 5 +++-- .../frc/team3128/autonomous/AutoPrograms.java | 10 ++++++---- .../frc/team3128/autonomous/Trajectories.java | 17 +++++++++++------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/frc/team3128/Constants.java b/src/main/java/frc/team3128/Constants.java index bca15cd..e65edb8 100644 --- a/src/main/java/frc/team3128/Constants.java +++ b/src/main/java/frc/team3128/Constants.java @@ -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> MODULARIZED_AUTOS = new HashMap>(); - // 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")); } } diff --git a/src/main/java/frc/team3128/autonomous/AutoPrograms.java b/src/main/java/frc/team3128/autonomous/AutoPrograms.java index 9629655..d6cc4c3 100644 --- a/src/main/java/frc/team3128/autonomous/AutoPrograms.java +++ b/src/main/java/frc/team3128/autonomous/AutoPrograms.java @@ -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" }; @@ -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()); diff --git a/src/main/java/frc/team3128/autonomous/Trajectories.java b/src/main/java/frc/team3128/autonomous/Trajectories.java index c9427d8..3d735b3 100644 --- a/src/main/java/frc/team3128/autonomous/Trajectories.java +++ b/src/main/java/frc/team3128/autonomous/Trajectories.java @@ -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))); @@ -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 stringToList(String name) { String prefix = name.split("_")[0]; String[] autoStrings = name.split("_")[1].split("&"); @@ -111,6 +115,7 @@ public static ArrayList stringToList(String name) { return ret; } + // conjoins list of strings into one complete trajectory public static CommandBase get(ArrayList names) { ArrayList curTrajectories = new ArrayList(); for (String name : names) {