FixTheRobot Explore Robotics / Navigation / M5 / M5-L4

This lab works on phones, but writing code is much easier on a laptop.

Navigation · Trajectories and Path Following · M5-L4 · Intermediate

Compare Pure Pursuit and Stanley

15:45. The tug that moves linen carts uses a front-wheel steering controller, and Scout uses pure pursuit. Facilities want one controller for the east wing: a 40 m corridor with two tight bends. Each team says theirs is better.

You will write the Stanley steering law and the two error measurements it needs, and then read three runs from the same simulation of the same corridor to see what each controller does well, where each is wrong, and what matters more than the choice between them.

Your task

    Simulation
    solution.pyLoading Python…
    Ctrl+Enter runs
    What Python can I use?

    Plain Python with math and heapq. Your code runs in a background worker: an endless loop is stopped after a few seconds and the page stays usable. It runs in your browser and is never sent anywhere.

    Hints

    What this lab teaches

    Stage 1 is the Stanley law: the heading error plus an arctangent of the cross-track error over speed, with the angle wrapped and the steering limited. Stage 2 is the measurement the law depends on: the shortest distance to a polyline path with widely spaced waypoints and the direction of the segment you measured against. Stage 3 has no code. It shows pure pursuit with two lookaheads and Stanley on the same route with the same delay, and asks you to read the traces.

    The comparison is not a contest with a winner. It is about what each controller depends on: pure pursuit on a lookahead, Stanley on a reference point and a smooth path, and both on the speed profile.

    Theory for this lab

    Trajectories and Path Following labs

    1. M5-L1: Smooth a Jagged Path
    2. M5-L2: Build a Velocity Profile
    3. M5-L3: Tune Pure Pursuit
    4. M5-L4: Compare Pure Pursuit and Stanley: this lab.

    Educational simplification: a kinematic car-like robot with a 0.8 m wheelbase and a 35 degree steering limit, a steering delay of 0.2 s, no slip, and a perfect pose estimate. The one corridor and the parameters in stage 3 are examples, not a benchmark; the results depend on the speed, the delay and the gains (lessons M5-T4, M5-T5 and M5-T7).

    Get the next lab

    Get notified when new robotics labs are released. One email per new lab, nothing else.