Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[choreolib] fix trajectoryCmd #1160

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions choreolib/src/main/java/choreo/auto/AutoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void reset() {}

@Override
public Trigger active() {
return new Trigger(this.loop(), () -> false);
return new Trigger(this.loop(), () -> true);
}
};
}
Expand Down Expand Up @@ -207,7 +207,7 @@ public AutoRoutine newRoutine(String name) {
*
* @see AutoRoutine#trajectory(String)
*/
AutoTrajectory trajectory(String trajectoryName, AutoRoutine routine) {
AutoTrajectory trajectory(String trajectoryName, AutoRoutine routine, boolean useBindings) {
Optional<? extends Trajectory<?>> optTrajectory =
trajectoryCache.loadTrajectory(trajectoryName);
Trajectory<?> trajectory;
Expand All @@ -216,7 +216,7 @@ AutoTrajectory trajectory(String trajectoryName, AutoRoutine routine) {
} else {
trajectory = new Trajectory<SwerveSample>(trajectoryName, List.of(), List.of(), List.of());
}
return trajectory(trajectory, routine);
return trajectory(trajectory, routine, useBindings);
}

/**
Expand All @@ -225,7 +225,8 @@ AutoTrajectory trajectory(String trajectoryName, AutoRoutine routine) {
*
* @see AutoRoutine#trajectory(String, int)
*/
AutoTrajectory trajectory(String trajectoryName, final int splitIndex, AutoRoutine routine) {
AutoTrajectory trajectory(
String trajectoryName, final int splitIndex, AutoRoutine routine, boolean useBindings) {
Optional<? extends Trajectory<?>> optTrajectory =
trajectoryCache.loadTrajectory(trajectoryName, splitIndex);
Trajectory<?> trajectory;
Expand All @@ -234,7 +235,7 @@ AutoTrajectory trajectory(String trajectoryName, final int splitIndex, AutoRouti
} else {
trajectory = new Trajectory<SwerveSample>(trajectoryName, List.of(), List.of(), List.of());
}
return trajectory(trajectory, routine);
return trajectory(trajectory, routine, useBindings);
}

/**
Expand All @@ -245,7 +246,7 @@ AutoTrajectory trajectory(String trajectoryName, final int splitIndex, AutoRouti
*/
@SuppressWarnings("unchecked")
<ST extends TrajectorySample<ST>> AutoTrajectory trajectory(
Trajectory<ST> trajectory, AutoRoutine routine) {
Trajectory<ST> trajectory, AutoRoutine routine, boolean useBindings) {
// type solidify everything
final Trajectory<ST> solidTrajectory = trajectory;
final Consumer<ST> solidController = (Consumer<ST>) this.controller;
Expand All @@ -259,7 +260,7 @@ <ST extends TrajectorySample<ST>> AutoTrajectory trajectory(
(TrajectoryLogger<ST>) trajectoryLogger,
driveSubsystem,
routine,
bindings);
useBindings ? bindings : new AutoBindings());
}

/**
Expand All @@ -277,10 +278,7 @@ <ST extends TrajectorySample<ST>> AutoTrajectory trajectory(
* @return A new {@link AutoTrajectory}.
*/
public Command trajectoryCmd(String trajectoryName) {
AutoRoutine routine = newRoutine("Routine");
AutoTrajectory trajectory = routine.trajectory(trajectoryName);
routine.active().onTrue(trajectory.cmd());
return routine.cmd().until(trajectory.done());
return trajectory(trajectoryName, voidRoutine, false).cmd();
}

/**
Expand All @@ -299,10 +297,7 @@ public Command trajectoryCmd(String trajectoryName) {
* @return A new {@link AutoTrajectory}.
*/
public Command trajectoryCmd(String trajectoryName, final int splitIndex) {
AutoRoutine routine = newRoutine("Routine");
AutoTrajectory trajectory = routine.trajectory(trajectoryName, splitIndex);
routine.active().onTrue(trajectory.cmd());
return routine.cmd().until(trajectory.done());
return trajectory(trajectoryName, splitIndex, voidRoutine, false).cmd();
}

/**
Expand All @@ -322,7 +317,7 @@ public Command trajectoryCmd(String trajectoryName, final int splitIndex) {
* @return A new {@link AutoTrajectory}.
*/
public <ST extends TrajectorySample<ST>> Command trajectoryCmd(Trajectory<ST> trajectory) {
return trajectory(trajectory, voidRoutine).cmd();
return trajectory(trajectory, voidRoutine, false).cmd();
}

/**
Expand All @@ -332,7 +327,7 @@ public <ST extends TrajectorySample<ST>> Command trajectoryCmd(Trajectory<ST> tr
* @return A command that resets the robot's odometry.
*/
public Command resetOdometry(String trajectoryName) {
return trajectory(trajectoryName, voidRoutine).resetOdometry();
return trajectory(trajectoryName, voidRoutine, false).resetOdometry();
}

/**
Expand All @@ -343,7 +338,7 @@ public Command resetOdometry(String trajectoryName) {
* @return A command that resets the robot's odometry.
*/
public Command resetOdometry(String trajectoryName, final int splitIndex) {
return trajectory(trajectoryName, splitIndex, voidRoutine).resetOdometry();
return trajectory(trajectoryName, splitIndex, voidRoutine, false).resetOdometry();
}

/**
Expand All @@ -355,7 +350,7 @@ public Command resetOdometry(String trajectoryName, final int splitIndex) {
* @return A command that resets the robot's odometry.
*/
public <ST extends TrajectorySample<ST>> Command resetOdometry(Trajectory<ST> trajectory) {
return trajectory(trajectory, voidRoutine).resetOdometry();
return trajectory(trajectory, voidRoutine, false).resetOdometry();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions choreolib/src/main/java/choreo/auto/AutoRoutine.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AutoRoutine {
private final AllianceContext allianceCtx;

/** A boolean utilized in {@link #active()} to resolve trueness */
private boolean isActive = false;
boolean isActive = false;

/** A boolean that is true when the loop is killed */
boolean isKilled = false;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void kill() {
* @return A new {@link AutoTrajectory}.
*/
public AutoTrajectory trajectory(String trajectoryName) {
return factory.trajectory(trajectoryName, this);
return factory.trajectory(trajectoryName, this, true);
}

/**
Expand All @@ -153,7 +153,7 @@ public AutoTrajectory trajectory(String trajectoryName) {
* @return A new {@link AutoTrajectory}.
*/
public AutoTrajectory trajectory(String trajectoryName, final int splitIndex) {
return factory.trajectory(trajectoryName, splitIndex, this);
return factory.trajectory(trajectoryName, splitIndex, this, true);
}

/**
Expand All @@ -165,7 +165,7 @@ public AutoTrajectory trajectory(String trajectoryName, final int splitIndex) {
*/
public <SampleType extends TrajectorySample<SampleType>> AutoTrajectory trajectory(
Trajectory<SampleType> trajectory) {
return factory.trajectory(trajectory, this);
return factory.trajectory(trajectory, this, true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion choreolib/src/main/java/choreo/auto/AutoTrajectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void cmdEnd(boolean interrupted) {
}

private boolean cmdIsFinished() {
return timer.get() > trajectory.getTotalTime() || !routine.active().getAsBoolean();
return timer.get() > trajectory.getTotalTime() || !routine.isActive;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion choreolib/src/test/java/choreo/auto/DoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testExecution() {
Trajectory<SwerveSample> trajectory =
TrajectoryTestHelper.linearTrajectory("test", start, end, 3.0, SwerveSample.class);
AutoRoutine routine = factory.newRoutine("test");
AutoTrajectory traj = factory.trajectory(trajectory, routine);
AutoTrajectory traj = factory.trajectory(trajectory, routine, true);

BooleanSupplier done = traj.done();
BooleanSupplier doneDelayed = traj.done(2);
Expand Down
Loading