Skip to content

Commit

Permalink
Fix CI build
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Feb 13, 2024
1 parent 0443317 commit 4c37f54
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,7 @@ simgui*.json
networktables.json

# Version file
src/main/java/org/littletonrobotics/frc2024/BuildConstants.java
src/main/java/org/littletonrobotics/frc2024/BuildConstants.java

# Generated paths
src/main/deploy/trajectories/*.pathblob
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
Expand All @@ -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<String, List<PathSegment>> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -55,7 +58,6 @@ public Pose2d[] getTrajectoryPoses() {
}
return poses;
}
;

public VehicleState getStartState() {
return trajectory.getStates(0).getState();
Expand Down

0 comments on commit 4c37f54

Please sign in to comment.