Skip to content

Commit 7408441

Browse files
nlaverdureclaude
andauthored
Log AutoSelector trajectory and pose only on change (#164)
* Log AutoSelector trajectory and pose only on change AutonomousInitialTrajectory (SwerveSample[]) was being written every disabled cycle, wasting ~9 MB per session. AutonomousInitialPose added another ~0.45 MB. Both are now guarded to only call Logger.recordOutput when the value changes — trajectory by AutoOption reference identity, pose by Pose2d.equals(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * formatting --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6441e72 commit 7408441

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

src/main/java/frc/lib/AutoSelector.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class AutoSelector implements Supplier<Optional<AutoOption>> {
2222
private List<AutoOption> autoOptions = new ArrayList<>();
2323
private EventLoop eventLoop = new EventLoop();
2424
private BooleanEvent autoSelectionChanged;
25+
private Pose2d lastLoggedInitialPose = null;
26+
private AutoOption lastLoggedTrajectoryOption = null;
2527

2628
/**
2729
* Constructs an autonomous selector switch
@@ -87,15 +89,28 @@ public void disabledPeriodic() {
8789
currentAutoOption.ifPresentOrElse(
8890
ao -> {
8991
Logger.recordOutput("AutoSelector/SelectedAutoMode", ao.getName());
90-
ao.getInitialTrajectory()
91-
.ifPresent(
92-
traj -> Logger.recordOutput("AutoSelector/AutonomousInitialTrajectory", traj));
92+
if (ao != lastLoggedTrajectoryOption) {
93+
lastLoggedTrajectoryOption = ao;
94+
ao.getInitialTrajectory()
95+
.ifPresent(
96+
traj -> Logger.recordOutput("AutoSelector/AutonomousInitialTrajectory", traj));
97+
}
9398
ao.getInitialPose()
94-
.ifPresent(pose -> Logger.recordOutput("AutoSelector/AutonomousInitialPose", pose));
99+
.ifPresent(
100+
pose -> {
101+
if (!pose.equals(lastLoggedInitialPose)) {
102+
lastLoggedInitialPose = pose;
103+
Logger.recordOutput("AutoSelector/AutonomousInitialPose", pose);
104+
}
105+
});
95106
},
96107
() -> {
97108
Logger.recordOutput("AutoSelector/SelectedAutoMode", "No auto mode assigned");
98-
Logger.recordOutput("AutoSelector/AutonomousInitialPose", Pose2d.kZero);
109+
lastLoggedTrajectoryOption = null;
110+
if (!Pose2d.kZero.equals(lastLoggedInitialPose)) {
111+
lastLoggedInitialPose = Pose2d.kZero;
112+
Logger.recordOutput("AutoSelector/AutonomousInitialPose", Pose2d.kZero);
113+
}
99114
});
100115
}
101116

0 commit comments

Comments
 (0)