What is the best path following approach?

Hi,
My team is currently trying to decide which approach of the following is the best approach of path following: motion profiling, pure pursuit or the stanley method.
Does someone has any interesting thoughts that could help us decide?

Have you read the WPILib trajectory docs?

https://docs.wpilib.org/en/latest/docs/software/examples-tutorials/trajectory-tutorial/index.html

3 Likes

Yes.
My team is trying to implement a real time path following, so we can’t use the WPILIB trajectory following (it’s taking couple of seconds to generate a trajectory, and we can’t afford spending that amount of time in a match)

Are you sure the WPILib trajectoy generator takes a few seconds? From testing on my laptop, it finishes in about 10ms, and down to 2ms once the Java JIT optimizer starts. I can’t imagine it being much slower than that on the RoboRIO. In addition, to do real-time path following you don’t need to regenerate your trajectory every time, you can just look at the error between your expected robot state and your actual robot state, and correct it accordingly

3 Likes

When we tested the WPILib trajectory generator, it took us a few seconds to generate one. If someone tried to generate a trajectory using WPILib and it took him a few milliseconds, I will be happy to know.
As for the regenerating of the trajectory, I meant to say the we want to be able to generate and follow a path/trajectory during a match (based on a vision target), so we can’t know in advance how the path will look like.

Did you use wpilib trajectory generation or Pathfinder? The latter is as slow as you claim and has been superseded by wpilib trajectory generation.

I made a simple test:

public class TrajectoryTimeTest {
    public static void generateATrajectory() {
        var initalTime = System.nanoTime();
        var initialPose = new Pose2d();
        var finalPose = new Pose2d(3.0, 1.0, Rotation2d.fromDegrees(0.0));
        TrajectoryGenerator.generateTrajectory(
                List.of(initialPose, finalPose),
                new TrajectoryConfig(3.0, 3.0)
                        .setKinematics(new DifferentialDriveKinematics(0.8))
        );
        var dt = (System.nanoTime() - initalTime) / 1E6;
        System.out.println("Time: " + dt + "ms");
    }

    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            generateATrajectory();
        }
    }
}

Running it on my laptop gives this result:

Time: 89.3684ms
Time: 9.1428ms
Time: 1.9014ms
Time: 1.7713ms
Time: 1.6862ms
Time: 1.348ms
Time: 0.9471ms
Time: 0.9686ms
Time: 0.8282ms
Time: 0.9078ms
Time: 0.7901ms
Time: 0.9718ms
Time: 0.6747ms
Time: 0.757ms
Time: 0.652ms
Time: 0.9784ms
Time: 0.8024ms
Time: 0.8106ms
Time: 0.8355ms
Time: 0.9755ms

I think this is quite fast even for regenerating it in-match without knowing the path in advance

3 Likes

I ran the same code on the roboRIO and got:

Time: 403.909616ms
Time: 74.923786ms
Time: 29.402704ms
Time: 20.842647ms
Time: 18.166477ms
Time: 17.583432ms
Time: 28.532571ms
Time: 15.172629ms
Time: 13.723083ms
Time: 28.196107ms
Time: 14.582835ms
Time: 10.810659ms
Time: 10.081437ms
Time: 9.740812ms
Time: 9.383442ms
Time: 9.422004ms
Time: 10.552368ms
Time: 9.80185ms
Time: 9.988365ms
Time: 9.378285ms

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