Generating Trajectories at runtime with Wpilib, latency

Per a great suggestion on here, our team generates a trajectory at runtime to help us ‘backtrack’.

We use our vision system to drive us to the ball, and then taking the starting pose, and our ending pose (no points in between), generate a trajectory.

This works great. However I’ve noticed some latency on the call to do this. It seems that it takes the TrajectoryGenerator’s generate function at least a second to run, which normally isn’t a big deal, but we are in a stage where seconds matter!

Is that normal? Even though its more or less generating a straight line I’m assuming its a fairly complex calculation. Does anyone have any experience with this?

Are you generating any trajectories at robot startup? Typically the first call to TrajectoryGenerator takes longer but once the JIT compiler kicks in most calls are <100ms. Someone did a benchmark test on the roborio and posted about it recently, if anyone wants to find the post.

If you’re not generating any trajectories before you run your auto, I would try generating a dud trajectory during robotInit so that the JIT compiler can optimize future calls.

3 Likes

Interesting! Good to know! I’m not generating any trajectories other than this one, but I’ll generate a few dud trajectories.

Makes sense. Java is so fast, especially with the JIT it felt odd for any latency

1 Like

Anyone know where that benchmark post is? I’m struggling to find it!

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