Navigation · Theory · M5
M5-T5 — Stanley and Cross-Track Control
Steer the front wheels to remove the heading error, plus a term that brings the front axle back onto the line.
Pure pursuit needs a lookahead and a point ahead. Stanley, the controller of the car that won the 2005 DARPA Grand Challenge, needs neither. It measures two errors at the front axle and steers against both. Its behaviour is easy to analyse, which is why it is the textbook companion to pure pursuit.
Learning objectives
After this lesson, you should be able to:
- Write the Stanley steering law from the heading error and the cross-track error.
- Explain the role of speed and of the softening constant, and show that the cross-track error decays exponentially.
- State what reference point Stanley uses and what that does on a bend.
- Compare Stanley with pure pursuit on what each needs from the path and the speed.
The intuition
Suppose the front wheels point exactly along the path but sit a little to its left. To get back, you steer slightly right. The further away you are, the harder you steer, but never so hard that you turn across the path: the steering from the offset alone tops out at 90°. Now suppose you are on the line but pointing away from it. Steer back by exactly the angle you are off. Stanley adds the two.
The offset term is divided by the speed. At high speed a small steering angle moves the robot sideways quickly, so less steering is needed for the same correction; at low speed it takes more.
The mathematics
The law
- ψ
- heading error: path direction minus robot heading, wrapped into −π..π.
- e
- cross-track error: the distance of the front axle from the nearest point of the path, positive when the path is on the robot’s left.
- v
- speed in m/s.
- k
- gain of the cross-track term, in 1/s. Larger values converge faster.
- ks
- softening constant, in m/s, so that the formula stays finite at v = 0.
The sign convention is what makes the law work. With e positive when the path is on the left, both terms steer left when the robot needs to go left. Using the opposite convention for e needs a minus sign in front of the arctangent.
Why the error decays
When the heading error is zero, the front axle moves sideways at a rate ė = −v·sin(δ). With δ = atan(k e / (ks + v)):
So the error decays exponentially with rate k·v/(ks + v), which is close to k at high speed. For a large error the sine saturates at 1 and the robot closes in at a speed of at most v.
Measuring the errors
Find the nearest point of the path as a polyline (not the nearest waypoint) and take the direction of that segment. With sparse waypoints, a distance to the nearest waypoint can be metres off (lab M5-L4, stage 2). The heading difference must be wrapped; subtracting angles without wrapping makes the robot steer hard the wrong way near ±π (stage 1).
The reference point
Stanley is defined for the front axle of a car-like robot. If the pose you track is the rear axle (as in most odometry), compute the front axle position as the rear axle plus the wheelbase along the heading. If the front axle follows a circle of radius Rf, the rear axle follows a smaller one:
A worked example
One command. Heading error ψ = 0.10 rad, cross-track error e = 0.30 m, speed v = 1.0 m/s, k = 1.5 1/s and ks = 0.5 m/s:
At a standstill (v = 0) with the same errors the cross-track term is atan(0.45 / 0.5) = 0.733 rad = 42.0°. That is beyond a 35° steering limit, so the command is clamped. Without ks the term would be atan(∞) = 90° for any error at all.
How fast does it converge? At v = 1.0 m/s the rate is 1.5 × 1.0 / 1.5 = 1.0 per second, a time constant of one second, one metre of travel. Starting 0.5 m off the line, three time constants (3 s, 3 m) leave 0.5 × e−3 = 0.025 m. Integrating the full nonlinear equation gives 0.026 m. At 2 m/s the rate is 1.2 per second: a time constant of 0.83 s, but 1.7 m of travel, so a faster robot needs more room to settle.
On a bend. Scout’s tug has a wheelbase of 0.8 m. If its front axle runs along a bend of radius 1.5 m, the rear axle runs on a radius of sqrt(1.5² − 0.8²) = 1.269 m, which is 0.231 m inside (the approximation gives 0.213 m). In the simulation of lab M5-L4, with Stanley on a 1.5 m bend at 1.5 m/s, the rear axle peaks 0.18 m from the centre line, against 0.09 m for pure pursuit with a 1.5 m lookahead. Both are small on a 2 m corridor. If the pose reference is the rear axle, track the rear axle or plan with the offset in mind.
Engineering implications and limitations
Pure pursuit or Stanley?
| Pure pursuit | Stanley | |
|---|---|---|
| Main tuning knob | Lookahead distance (depends on speed and latency) | Gain k and softening ks |
| Reference point | Rear axle (or robot centre) | Front axle |
| Path it needs | Any polyline, even rough | A path with continuous heading, or the heading error jumps at corners |
| Behaviour on bends | Cuts them as the lookahead grows | Front axle accurate, rear axle inside |
| Typical home | Differential-drive indoor robots | Car-like vehicles at higher speed |
Smooth the path first
At a polyline vertex the path heading jumps by the corner angle. Stanley’s heading error then jumps too, and the command goes to the steering limit at once. Smooth the path (lesson M5-T2) before using Stanley.
Reverse and low speed
The law is defined for forward driving. In reverse the signs change, and near zero speed ks alone decides how hard the robot steers. Test the controller at the slowest speed the stack will use.
Pick gains from a step response
Start the robot 0.5 m off the line on a straight, and read the error. A time constant of about a second is a reasonable first target; ringing means the gain is too high for the latency (lesson M5-T7).
Common misconceptions
“Stanley needs no tuning.”
It has two gains, and the right values depend on speed, latency and the steering rate limit.
“The cross-track term can steer by any amount.”
The arctangent bounds it by 90°, and the clamp bounds the total by the steering limit.
“Stanley follows the rear axle.”
It follows the front axle. Tracked at the rear axle the result is inside every bend.
“Heading error is just the difference of two headings.”
It is the shortest turn between them. Without wrapping, a pair of headings either side of ±π looks like a 2π error.
Engineering takeaways
- Stanley: δ = ψ + atan(k·e / (ks + v)), clamped to the steering limit.
- Positive e means the path is on the left; both terms then steer left.
- With zero heading error the cross-track error decays exponentially at about k·v/(ks + v).
- It controls the front axle, so a rear-axle pose cuts bends by about wheelbase²/(2R).
- It needs a path with continuous heading; smooth the path first.
References and further reading
The controller of the Stanley vehicle, and a comparison with other path-tracking methods.
- G. M. Hoffmann, C. J. Tomlin, M. Montemerlo and S. Thrun, “Autonomous Automobile Trajectory Tracking for Off-Road Driving: Controller Design, Experimental Validation and Racing”, American Control Conference, 2007.
- S. Thrun et al., “Stanley: The Robot that Won the DARPA Grand Challenge”, Journal of Field Robotics, 23(9), 2006.
- J. M. Snider, “Automatic Steering Methods for Autonomous Automobile Path Tracking”, Carnegie Mellon University Robotics Institute, Technical Report CMU-RI-TR-09-08, 2009.
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
ψ = 0, e = 0.5 m, v = 2.0 m/s, k = 1.0, ks = 0.5. What is the steering angle?
Explanation
atan(1.0 × 0.5 / 2.5) = atan(0.2) = 0.197 rad = 11.3°.
Question 2
Heading is 3.0 rad and the path direction is −3.0 rad. What is ψ?
Explanation
The difference −6.0 rad wraps to −6.0 + 2π = 0.283 rad. The robot needs a small left turn, not a large right one.
Question 3
Why is the softening constant ks needed?
Explanation
Without it, the cross-track term is atan(k·e / v), which is 90° for any error at v = 0, and 0/0 when both are zero. ks keeps the law finite and gentle at a standstill.
What’s next
Next: controllers that use a model of the robot to choose the steering, and can respect limits.
Related content
Nothing below is required to finish this lesson.
- BeforeM5-T4: Pure Pursuit
Derive the pure-pursuit steering command and explain how lookahead distance trades smoothness for corner cutting.
- LabM5-L4: Compare Pure Pursuit and Stanley
Run both controllers on the same route and decide which suits a long straight corridor with tight bends.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.