Learning roadmapIntermediate

Path Following for Robots: A Learning Roadmap

Hand a robot a list of waypoints and have it drive them, and be able to say in metres how well it did.

Planning and following are different problems, and most robotics material teaches only the first. A* gives you a route; nothing in it tells the wheels what to do. This path is that missing rung — everything between a list of waypoints and a robot that actually drives them.

Work through the nodes in order. Each one is a thing the next assumes, and skipping any of them produces a robot that wanders for a reason you cannot isolate.

Before you start

You need a differential-drive robot you can already command — two motors, a driver, and a loop that runs at a steady rate. The motor control path covers all of that and this one expects it first. No control theory is required; pure pursuit is geometry, not a PID.

What you will be able to do

  • Convert wheel encoder counts into a pose, and say how far that pose drifts per metre driven on your own floor.
  • Fuse a gyro with an absolute reference into a heading that does not walk away over a mission.
  • Implement pure pursuit from the curvature formula, in about a dozen lines, and explain every one of them.
  • Choose a lookahead distance from your robot’s measured control lag rather than by trial and error, and schedule it on speed.
  • Measure cross-track error against ground truth and report RMS, worst case, and where along the path the error lives.
  • Say why the same controller is fourteen times worse on a raw GPS fix, and fix it without changing the controller.

Where people get stuck

Tuning the controller when the estimate is the problem. If the robot thinks it is on the path, it reports zero error and steers confidently into a hedge. Measure against something external before touching a gain — a tape measure counts.

Believing a simulation with no lag. A perfectly kinematic pure pursuit gets better as the lookahead shrinks, so a lag-free model recommends the one setting that oscillates on real hardware. Put a steering time constant and a sensing delay into any model you tune against.

A global nearest-point search. It is the obvious implementation and it fails silently on any path that doubles back, matching a segment the robot drove a minute ago. Track arc length, search a window around it, and never let progress run backwards.

Resolving a vertex tie to the incoming segment. Past a corner, both adjacent segments project to the same point at the same distance. Keep the wrong one and a controller that steers on heading and lateral error sees approximately zero of both while driving straight off the course. It is the quietest bug on this page.

Build it as the GPS waypoint rover, which follows this sequence exactly — indoors on encoders first, outdoors on a fused fix second.

What you need

What Why this path needs it Notes
Encoders on both wheels The pose estimate everything else consumes Not optional here — this path is about knowing where you are
A gyro or IMU Wheels cannot measure a rotation they slipped through MPU-6050 is enough
A steady loop Both the estimator and the controller integrate over time Fixed interval, or pass real elapsed time
Something to measure against You cannot tune tracking without ground truth Chalk line and a tape measure beats any amount of telemetry
A GPS module (outdoor half only) The last two nodes Indoors it will not fix at all

Why the path runs in this order

This path is unusual in that the first five nodes are not about steering at all. They build the pose estimate, because a path controller acting on a wrong pose fails in a way that looks exactly like a badly tuned controller — the robot reports zero error while driving into a hedge. Getting the estimate right first means that when you finally tune a gain, you can believe what you measure.

Encoders, then odometry, then slip, in that order. Each corrects the previous one’s optimism. Encoders tell you the wheel turned; odometry turns two wheel motions into a pose; slip tells you how much of that pose is fiction, and specifically that systematic error grows linearly with distance while random error grows only as its square root.

The IMU joins before the controller because heading is the part of the pose that matters most to a path follower and is the part wheels are worst at. A pivot turn scrubs both tyres almost by definition, so the one manoeuvre that changes heading most is the one odometry measures worst. A complementary filter fuses a gyro’s good short-term rate with an absolute reference’s good long-term average, and the result is a heading that does not walk away.

Motion profiles come before pure pursuit because a path follower commands speed continuously, and a speed command that steps produces a robot that lurches and slips — re-introducing exactly the odometry error you just spent three nodes controlling.

Pure pursuit, then the lab, then cross-track error. The controller is about a dozen lines and its geometry is easy; what is hard is choosing the lookahead and knowing whether the result is good. The lab exists so you can watch the lookahead trade-off happen, and the cross-track node exists so “it drives well” becomes a number with an RMS and a worst case.

GPS last, and only last. It changes nothing about the controller and everything about the estimate. Doing it last means that when tracking gets fourteen times worse, you already know for certain that the controller is not the reason.

Checkpoints: how to know a stage landed

Stage The check What a pass looks like
Encoders Push the robot 2 m by hand along a chalk line Counts convert to 2000 mm within 2%, both wheels
Odometry Drive a 1 m square and return to the start The reported pose closes within a few centimetres, and you can state the error per metre
Slip Do a pivot turn and compare gyro heading against odometry heading They disagree, and you can say by how much — that gap is the scrub
IMU fusion Rotate the robot 360° slowly, then leave it still for two minutes Heading returns to its start, and does not drift while stationary
Motion profiles Command a step speed change, then a profiled one The profiled move does not chirp the tyres; the step one does
Pure pursuit Follow a straight line with a 0.5 m offset start It converges without overshoot, and you can name your lookahead in metres
Lookahead tuning Halve the lookahead deliberately It oscillates — now you know the failure mode, and why a lag-free simulator hides it
Cross-track error Drive a figure-of-eight and log error against ground truth You can report RMS and worst-case error, and say where along the path the worst lives
GPS Log a static fix for ten minutes without moving You can see the wander, in metres, that your controller would otherwise chase

Where this path stops

This path takes a given path and drives it. It does not produce the path — that is path planning and mapping, and the two together are the complete navigation stack.

It also stops short of three things. Obstacle avoidance while following — reacting to something that appears on a path you already committed to — needs a local planner running underneath the follower, and that is a genuinely harder problem than either half alone. Ackermann and omnidirectional steering change the geometry: pure pursuit adapts to a car-like robot readily, but the curvature-to-wheel-speed step here is specifically differential drive — for a base that can strafe, start at holonomic drive, and note that a holonomic robot can do strictly better than either controller here because it can correct position without spending heading. And RTK GPS, which brings the outdoor fix from metres to centimetres, is the thing that makes outdoor path following genuinely precise — worth knowing exists before you conclude that outdoor navigation is simply inaccurate.

Learning roadmap

The path

Follow the nodes in order—each unlocks the next once you have done it. Your progress saves on this device.

0 / 11 done

100%
Goal

Drive a mission

Skill unlocked

Common questions

Frequently asked questions

What is the difference between path planning and path following?

Planning produces a route; following makes the wheels drive it. A* hands you a list of waypoints and says nothing whatsoever about steering, speed, or what to do when the robot ends up half a metre to the left of where it meant to be. Path following is that missing half: given where the robot believes it is and where the path goes, decide what the wheels should do this instant. Most robotics material teaches planning thoroughly and following barely at all, which is why a robot with a correct plan so often wanders.

How do I choose a pure pursuit lookahead distance?

From your robot's measured control lag, not by trial and error. The lookahead has to be far enough ahead that the robot can physically get there given how long its steering takes to respond—too short and it oscillates, too long and it cuts corners. Measure the time between commanding a turn and the robot actually turning, multiply by your speed, and start there. Then schedule it on speed: the same robot needs a longer lookahead at 1 m/s than at 0.2 m/s, because the lag buys more distance.

Why does my path follower work in simulation but oscillate on the robot?

Almost certainly because the simulation has no lag. A purely kinematic pure pursuit model gets monotonically better as the lookahead shrinks, so tuning against it recommends the shortest lookahead—which is exactly the setting that oscillates on hardware. Any model you tune against must include a steering time constant and a sensing delay, or it will confidently teach you the opposite of what the real robot needs.

Pure pursuit or Stanley — which path controller should I use?

Pure pursuit for differential-drive robots and smooth paths; Stanley when tracking accuracy at the front axle matters more than smoothness. Pure pursuit steers toward a point ahead on the path, which makes it forgiving and naturally smooth, at the cost of cutting corners. Stanley combines heading error and cross-track error directly, which tracks tighter but is less tolerant of a noisy pose estimate. For a small indoor robot, pure pursuit is almost always the right first choice.

Why is my robot's tracking so much worse outdoors on GPS?

Because the controller is fine and the pose estimate is not. A consumer GPS fix is accurate to a few metres and updates at 1–10 Hz, while wheel odometry is accurate to centimetres and updates as fast as you read it. Feed the same controller a fix that jumps two metres between updates and it will chase the jumps. The fix is not in the controller—it is fusing the GPS with odometry and a heading source so the pose the controller sees is smooth, and letting GPS correct the slow drift rather than drive the fast loop.

Why does my robot steer off course right after a corner?

This is the vertex tie, and it is the quietest bug on the whole path. Just past a corner, both adjacent path segments project to the same point at the same distance, so a naive nearest-point search can match the segment the robot has already finished. A controller steering on heading and lateral error then sees approximately zero of both while driving straight off the course, reporting perfect tracking the entire time. Track arc length along the path, search only a window around your last position, and never let progress run backwards.