PathPlanner Initial Lag after Deploying Code

The first time we run a PathPlanner auto after a new code deploy or restarting the robot there is always a lag of around 0.5 seconds. This causes a huge decrease in path accuracy; however, as soon as we run it again it works perfectly fine. This leads to inconsistent path following and it not traveling to the desired distance (way undershooting).

Our robot code is here: https://github.com/Spectrum3847/2024-Ultraviolet.

Here is a picture of the telemetry output on PathPlanner:

The middle portion of the data is when robot code was running for the first time, and the others were before or after the new code deploy.

Does this happen with all autos or just this one?

Does this happen in simulation too? When I run your simulation it is completely broken.

What are the other velocities we see in your chart?

Does this happen when dropping into teleop the first time too or just auto?

Do you get any errors/warnings at this time? Posting logs might give us something to look at.

It happens in all autos.

We haven’t configured it to run in simulation yet, so we can’t test it there.

4 m/s^2 acceleration and 3 m/s velocity.

We tried mapping the PathPlanner command to a button in teleop and it resulted in the same error (this happened regardless of when we hit the button in teleop, so it still occurred after moving the drivetrain).

Here is a photo of our logs:


It looks like it might be a loop overrun issue with the first time autos are run (1 Meter Auto.execute takes 0.038 seconds to run, causing the loop overrun).

Thank you for your help.

I don’t see anything obvious here are a few things to try (not solutions just trying to narrow down the problem):

  1. Try commenting out the named commands and rotation target override.
  2. Try using buildAutoChooser
  3. What is the state of testing for your drivetrain code? Seems very similar to CTRE swerve is there a reason to not use that?
  4. Try without advantagekit

There is a lot going on in the project (even though what is running should be simple)

We tried all of these options, but everything produced similar lag.

We were able to take data from our initial code and it produced similar lag every time. Here is a screenshot of our spreadsheet below (PathPlannerAutoName.execute always took the most amount of time by a significant magnitude).

Here is a slow-mo video of our robot running the auto the first time after a code deploy:

Here is a slow-mo video of our robot running the auto a second time after a code deploy:

It looks like the robot starts to move in auto as soon as the Loop Overrun message appears (around 14.8 seconds or so). In the second video it appears to happen immediately.

EDIT: Also, adding a 0.2 second wait command in the PathPlanner auto didn’t fix anything.

Java loads classes “on demand” (the first time a function is called in a class, the class is loaded). This means the first call may take significantly longer than later calls, particularly for cases when there’s a lot of static construction or the function pulls in many other classes, such as loading json does. There’s really not a good workaround for this other than trying to find ways to exercise the code path in disabled; I was doing some work in the offseason on a (conservative) class preloader but the Rio really doesn’t have enough memory for that.

1 Like

We were able to run a PathPlanner Auto in disabled and this fixed most of our issues. We also added a 0.01 second delay to our all of our Autos and it seemed to fix a small swerve delay that was also causing issues after implementing this fix.

Thank you to everyone for their help.

Here is our Robot.java code that has the fixes talked about above:

Specifically we changed disabledInit to run a PathPlanner Auto with these lines:
Command autonInitCommand = new PathPlannerAuto("1 Meter Auto").ignoringDisable(true);
autonInitCommand.schedule();

We added a simple WaitCommand in our autonomousInit like this:
Command autonCommand = new WaitCommand(0.01).andThen(Auton.getAutonomousCommand());

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.