From 629dd266b76cc1faa285511c7687e3b4754455a3 Mon Sep 17 00:00:00 2001 From: nlaverdure Date: Fri, 24 Jul 2026 11:12:31 -0400 Subject: [PATCH] Fix PathPlanner trajectory logging in sim Store the active path in a field and log it every periodic() rather than calling Logger.recordOutput directly from the PathPlanner callback. This ensures the output is recorded within AdvantageKit's logging window and persists the last trajectory in AdvantageScope after the path ends. Co-Authored-By: Claude Sonnet 4.6 --- src/main/java/frc/robot/subsystems/drive/Drive.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/drive/Drive.java b/src/main/java/frc/robot/subsystems/drive/Drive.java index 376aab3..f3af1b0 100644 --- a/src/main/java/frc/robot/subsystems/drive/Drive.java +++ b/src/main/java/frc/robot/subsystems/drive/Drive.java @@ -95,6 +95,9 @@ public class Drive extends SubsystemBase { }; private ChassisSpeeds chassisSpeeds; + // PathPlanner trajectory logging (stored each loop for AKit compatibility) + private Pose2d[] lastTrajectory = new Pose2d[0]; + // PID controllers for following Choreo trajectories private final PIDController xController = new PIDController(8.01, 0.0, 0.0); private final PIDController yController = new PIDController(8.01, 0.0, 0.0); @@ -132,12 +135,7 @@ public Drive( Pathfinding.setPathfinder(new LocalADStarAK()); PathPlannerLogging.setLogActivePathCallback( (activePath) -> { - Logger.recordOutput( - "Odometry/Trajectory", activePath.toArray(new Pose2d[activePath.size()])); - }); - PathPlannerLogging.setLogTargetPoseCallback( - (targetPose) -> { - Logger.recordOutput("Odometry/TrajectorySetpoint", targetPose); + if (!activePath.isEmpty()) lastTrajectory = activePath.toArray(new Pose2d[0]); }); // Configure SysId @@ -223,6 +221,9 @@ public void periodic() { gyroDisconnectedAlert.set(gyroDisconnected); Logger.recordOutput("Faults/Drive/GyroDisconnected", gyroDisconnected); + // Log PathPlanner trajectory (stored by callback, recorded here for AKit compatibility) + Logger.recordOutput("Odometry/Trajectory", lastTrajectory); + // Profiling output if (FeatureFlags.PROFILING_ENABLED) { long totalMs = (t6 - startNanos) / 1_000_000;