diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba0370fa..070ea414 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,5 +14,9 @@ jobs: uses: actions/checkout@v2 - name: Grant execute permission run: chmod +x gradlew + - name: Check formatting + run: ./gradlew spotlessCheck - name: Build robot code run: ./gradlew build + env: + GENERATE_EMPTY_DRIVE_TRAJECTORIES: true diff --git a/.gitignore b/.gitignore index 6c111d80..b0ff3df3 100644 --- a/.gitignore +++ b/.gitignore @@ -175,4 +175,7 @@ simgui*.json networktables.json # Version file -src/main/java/org/littletonrobotics/frc2024/BuildConstants.java \ No newline at end of file +src/main/java/org/littletonrobotics/frc2024/BuildConstants.java + +# Generated paths +src/main/deploy/trajectories/*.pathblob \ No newline at end of file diff --git a/src/main/deploy/trajectories/.gitkeep b/src/main/deploy/trajectories/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/src/main/java/org/littletonrobotics/frc2024/RobotContainer.java b/src/main/java/org/littletonrobotics/frc2024/RobotContainer.java index 44636786..e153d679 100644 --- a/src/main/java/org/littletonrobotics/frc2024/RobotContainer.java +++ b/src/main/java/org/littletonrobotics/frc2024/RobotContainer.java @@ -197,7 +197,7 @@ public RobotContainer() { AutoCommands autoCommands = new AutoCommands(drive, superstructure); - // autoChooser.addOption("Drive Straight", autoCommands.driveStraight()); + autoChooser.addOption("Drive Straight", autoCommands.driveStraight()); // Configure the button bindings configureButtonBindings(); diff --git a/src/main/java/org/littletonrobotics/frc2024/subsystems/drive/trajectory/GenerateTrajectories.java b/src/main/java/org/littletonrobotics/frc2024/subsystems/drive/trajectory/GenerateTrajectories.java index e97a63b7..bca595a0 100644 --- a/src/main/java/org/littletonrobotics/frc2024/subsystems/drive/trajectory/GenerateTrajectories.java +++ b/src/main/java/org/littletonrobotics/frc2024/subsystems/drive/trajectory/GenerateTrajectories.java @@ -23,6 +23,12 @@ import org.littletonrobotics.frc2024.Constants; import org.littletonrobotics.frc2024.subsystems.drive.DriveConstants; import org.littletonrobotics.vehicletrajectoryservice.VehicleTrajectoryServiceGrpc; +import org.littletonrobotics.vehicletrajectoryservice.VehicleTrajectoryServiceOuterClass.PathRequest; +import org.littletonrobotics.vehicletrajectoryservice.VehicleTrajectoryServiceOuterClass.PathSegment; +import org.littletonrobotics.vehicletrajectoryservice.VehicleTrajectoryServiceOuterClass.Trajectory; +import org.littletonrobotics.vehicletrajectoryservice.VehicleTrajectoryServiceOuterClass.TrajectoryResponse; +import org.littletonrobotics.vehicletrajectoryservice.VehicleTrajectoryServiceOuterClass.VehicleModel; +import org.littletonrobotics.vehicletrajectoryservice.VehicleTrajectoryServiceOuterClass.Waypoint; public class GenerateTrajectories { public static void main(String[] args) { @@ -52,7 +58,6 @@ public static void main(String[] args) { try { InputStream fileStream = new FileInputStream(pathFile); Trajectory trajectory = Trajectory.parseFrom(fileStream); - // trajectory.getStatesC if (!trajectory.getHashCode().equals(hashCode)) { pathQueue.put(entry.getKey(), entry.getValue()); } @@ -73,30 +78,36 @@ public static void main(String[] args) { var channel = Grpc.newChannelBuilder("127.0.0.1:56328", InsecureChannelCredentials.create()).build(); var service = VehicleTrajectoryServiceGrpc.newBlockingStub(channel); + String generateEmptyFlag = System.getenv("GENERATE_EMPTY_DRIVE_TRAJECTORIES"); + boolean generateEmpty = generateEmptyFlag != null && generateEmptyFlag.length() > 0; // Generate trajectories for (Map.Entry> entry : pathQueue.entrySet()) { - PathRequest request = - PathRequest.newBuilder().setModel(model).addAllSegments(entry.getValue()).build(); - - TrajectoryResponse response = service.generateTrajectory(request); - System.out.println(response.getError()); - - String responseHashCode = getHashCode(model, entry.getValue()); - - response = - response.toBuilder() - .setTrajectory( - response.getTrajectory().toBuilder().setHashCode(responseHashCode).build()) - .build(); - + Trajectory trajectory; + if (generateEmpty) { + trajectory = Trajectory.newBuilder().build(); + } else { + // Use service for generation + PathRequest request = + PathRequest.newBuilder().setModel(model).addAllSegments(entry.getValue()).build(); + TrajectoryResponse response = service.generateTrajectory(request); + String error = response.getError().getReason(); + if (error.length() > 0) { + System.err.println( + "Got error response for trajectory \"" + entry.getKey() + "\": " + error); + System.exit(1); + } + trajectory = + response.getTrajectory().toBuilder() + .setHashCode(getHashCode(model, entry.getValue())) + .build(); + } File pathFile = Path.of("src", "main", "deploy", "trajectories", entry.getKey() + ".pathblob").toFile(); - try { OutputStream fileStream = new FileOutputStream(pathFile); System.out.println("Writing to " + pathFile.getAbsolutePath()); - response.getTrajectory().writeTo(fileStream); + trajectory.writeTo(fileStream); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/org/littletonrobotics/frc2024/util/trajectory/HolonomicTrajectory.java b/src/main/java/org/littletonrobotics/frc2024/util/trajectory/HolonomicTrajectory.java index 0829484c..40b72e5d 100644 --- a/src/main/java/org/littletonrobotics/frc2024/util/trajectory/HolonomicTrajectory.java +++ b/src/main/java/org/littletonrobotics/frc2024/util/trajectory/HolonomicTrajectory.java @@ -37,9 +37,12 @@ public HolonomicTrajectory(String name) { } public double getDuration() { - return trajectory.getStates(trajectory.getStatesCount() - 1).getTime(); + if (trajectory.getStatesCount() > 0) { + return trajectory.getStates(trajectory.getStatesCount() - 1).getTime(); + } else { + return 0.0; + } } - ; public Pose2d getStartPose() { VehicleState startState = getStartState(); @@ -55,7 +58,6 @@ public Pose2d[] getTrajectoryPoses() { } return poses; } - ; public VehicleState getStartState() { return trajectory.getStates(0).getState();