Lane Keeping Lab (2D)

Top-down view of two generic cars following a lane with pure pursuit and the Stanley controller: steering delay, camera noise, Kalman filter and tyre grip limits.

Switch to 3D

Presets

Playback

Track

Pick a road, or use a preset above.

Controllers

Which law steers car A (cyan) and car B (orange).

Vehicle and controller

Speed, look-ahead, Stanley gain, latency, noise and grip.

Options

Layers

Model checks

The science

What this is

A classroom model of lane keeping: a generic car must follow the centre line of a lane. Two path-tracking laws steer it: pure pursuit and the Stanley controller. Everything is a textbook model with made-up, plausible numbers (1500 kg, 2.7 m wheelbase). It says nothing about how any real vehicle or product behaves.

Vehicle models

Kinematic bicycle (no tyre forces, valid at low lateral acceleration). State: rear-axle position (x, y), heading ψ, speed v, front steering angle δ, wheelbase L:

x' = v cosψ y' = v sinψ ψ' = v tanδ / L

Constant δ drives a circle of radius L / tanδ. The simulator reproduces this to better than 0.01 %.

Dynamic bicycle (two axles, three states: forward speed vx, lateral speed vy, yaw rate r). Slip angles αf = δ − atan((vy + a r)/vx) and αr = −atan((vy − b r)/vx). Each axle makes a lateral force with a saturating law:

Fy = Fmax tanh(Cα α / Fmax), Fmax = √((μ Fz)² − Fx²)

The square root is the friction circle: braking or driving force on an axle leaves less grip for cornering. Linear at small slip, flat at the limit. When the front axle saturates first the car understeers (runs wide); when the rear does (for example while accelerating out of a bend) it oversteers. Simplifications: no load transfer sideways, simple tanh instead of a full Pacejka tyre, rear-wheel drive, constant mass, flat road, no suspension (the body roll you see is cosmetic).

Path trackers

Pure pursuit (Coulter 1992): choose the path point a look-ahead distance Ld ahead of the rear axle; if it lies at angle α to the heading, the circular arc through it needs

δ = atan( 2 L sinα / Ld )

A long Ld is smooth but cuts corners; a short one is tight but nervous and, with delay, unstable.

Stanley (Hoffmann, Thrun et al., Stanford 2005 race entry; analysed by Snider, CMU 2009): measured at the front axle, with heading error ψe and cross-track error efa:

δ = −ψe − atan( k efa / (v + ks) )

Optional curvature feed-forward adds atan(Lκ). Positive e means left of the path, so a car on the left steers right. Gain k trades speed of correction against overshoot; the 1/v inside the arctan makes the correction rate independent of speed in the small-error limit.

Actuator, latency, perception

Steering is a command that passes through a pure delay and a rate limit before it reaches the wheels. The speed controller is a PI loop (acceleration limited to 0.9 μg). The controller does not see the true pose: it sees lateral offset and heading error from a simulated lane camera, delayed by the perception latency and corrupted by Gaussian noise σ (heading noise 0.15 σ rad). The optional Kalman filter estimates [e, ψe] with the kinematic model e' = v sinψe, ψe' = v tanδ/L − vκ, and first advances each delayed measurement by the latency with the same model. Noise levels are tuned by hand, not identified from data.

Why delay is dangerous (Experiment 2)

Linearise pure pursuit for small errors with delay τ. With a = v / Ld the characteristic equation is s² + 2a (s + a) e−sτ = 0. It is neutrally stable at ω = √(2+2√2) a with tan(ωτ) = ω/a, which gives

vmax = 0.521 Ld / τ

The prediction adds the discrete loop's own 24 ms (half a 30 Hz camera frame plus control sampling). Above that speed any small offset grows into a weave. Longer look-ahead buys speed margin; the rate limit and the vehicle's own lag only make it worse. Stanley has no such closed form here; the sweep measures it.

Steady offset on a circle (Experiment 1)

For a kinematic car a rear axle on the path circle is an exact steady state of pure pursuit, so the only offset is the geometric one (the CG sits 1.5 m ahead of the rear axle). With real tyres, turning needs slip angles and the car settles on a different circle. The prediction solves the steady-turn force balance with the same tyre law, then finds the circle radius at which the controller's steering equals the steering the car needs. The time-domain simulation is the independent check. Delay and rate limit do not change a steady answer, only how it is approached.

Sources and limits

  • R. C. Coulter, Implementation of the Pure Pursuit Path Tracking Algorithm, CMU-RI-TR-92-01, 1992.
  • G. Hoffmann, C. Tomlin, M. Montemerlo, S. Thrun, Autonomous Automobile Trajectory Tracking for Off-Road Driving, ACC 2007.
  • J. M. Snider, Automatic Steering Methods for Autonomous Automobile Path Tracking, CMU-RI-TR-09-01, 2009.
  • R. Rajamani, Vehicle Dynamics and Control, Springer (bicycle models, slip angles).
  • R. E. Kalman, 1960, a new approach to linear filtering and prediction problems.

Not modelled: load transfer, tyre relaxation, steering torque, road camber, road friction changes, real sensor error models, planning or obstacle avoidance. Educational control theory only.

What to try
  • Start with Step offset: pure pursuit (cyan) overshoots the centre line a little, Stanley (orange) does not but steers harder at first.
  • Raise the steering delay above 300 ms at 18 m/s and watch the weave grow; the lower-right graph shows the operating point crossing the stability limit.
  • Pick Hairpin, wet, then tick Slow down for curves: the friction-circle graph shows the grip use drop from 100 % to about 60 %.
  • Add camera noise, then toggle the Kalman filter and compare steering activity.
  • Run Check 3 (delay sweep) to see simulated stability limits against the 0.52 Ld/τ line.
Cross-track error of the centre of gravity (m)
Front steering angle (deg)
Friction circle: lateral vs longitudinal acceleration
Stability limit: speed vs total latency