Algorithmintro
Pure pursuit
Also called pure pursuit path tracking.
Steers along the circular arc that meets the path at a lookahead distance ahead of the vehicle.
- Time
- O(n) worst
- Space
- O(1) extra
- Where
- n = the number of vertices of the path polyline; the bounds are for one control step
- Model
- Real RAM
- Properties
- deterministicnot exactonlinenot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- R. Craig Coulter, 1992
Pure pursuit is a steering law for a wheeled vehicle that follows a given path. At each control step it picks a goal point on the path, at a fixed distance (the lookahead) ahead of the vehicle. It then computes the circle arc that starts at the rear axle, is tangent to the current heading and passes through the goal point, and it steers the wheels to drive on that arc. The curvature of the arc is , where is the angle of the goal point seen from the heading, and the steering angle of a car with wheelbase is . The law is a heuristic: it has one tuning parameter, needs no model of the dynamics, and is used on many robots and autonomous cars at low and medium speed.
In plain words
Look at a point on the road some meters ahead of you. Turn the wheel so that, if you kept it still, the car would drive a smooth curve that hits that point. A moment later, look again at a point the same distance ahead, and correct the wheel. Repeat.
If you look far ahead, the car turns gently and smoothly, but it cuts corners. If you look close, the car follows the road more tightly, but it can weave from side to side. The look-ahead distance is the only knob.
The problem
The model. The vehicle is the kinematic bicycle model with the reference point at the center of the rear axle: , , , with the speed given by another loop and the steering angle in . A unicycle or a differential drive robot uses the same law with in place of the steering angle. The path is a polyline in the plane. Arithmetic, square roots and trigonometric functions cost one step each, as in the real RAM.
Input. The path as a list of points in meters, the current pose of the rear axle, the lookahead in meters and the wheelbase in meters.
Output. A steering angle in radians for the next control period.
How it differs from close pages. The Stanley controller uses the front axle, the closest point instead of a point ahead, and the heading error of the path; it reacts more directly to the cross-track error and needs a positive speed. Model predictive control optimizes the steering over a horizon with a model and constraints, at a much higher cost per step. A PID controller on the cross-track error has no geometry and needs tuning of three gains. The dynamic window approach chooses velocities to avoid obstacles and does not follow a given path.
The algorithm
PURE-PURSUIT(path, (x, y, θ), ℓd, L, δmax)- 1
(i, u) ← the point of the path closest to (x, y), searching from the last index onward - 2
g ← the first point of the path after (i, u) at distance ℓd from (x, y), or the last point of the path - 3
(xg, yg) ← g in the vehicle frame: xg = cos θ (gx - x) + sin θ (gy - y), yg = -sin θ (gx - x) + cos θ (gy - y) - 4
κ ← 2 yg / (xg^2 + yg^2) - 5
δ ← clamp(arctan(κ L), -δmax, δmax) - 6
apply δ for one control period dt - 7
the vehicle moves; repeat from L1 at the next period
Line L2 intersects the circle of radius around the rear axle with each segment, from the closest point onward, and takes the exit point of the circle on the first segment that has one. Searching only from the last closest index stops the vehicle from jumping back to an earlier part of a path that crosses itself. Line L4 is the curvature of the arc of Lemma 1 of the proof; when the goal point is at distance , it equals . In the implementation, line L7 integrates the model with the classical Runge-Kutta method and held constant, so the simulation is exact to about m and the only error is the zero-order hold of the controller.
Example
Let m, m/s and m. The path is the axis, and the car starts at : 1 m to the left of the path, with the heading of the path.
Line L1 gives the closest point . Line L2 gives the goal point . In the vehicle frame it is , so line L4 gives 1/m, a right turn of radius 12.5 m. Line L5 gives rad, which is degrees.
For a small error, the linear analysis of the proof gives with 1/s. The error crosses zero at s and reaches its least value m at s, an overshoot of . Measured: the simulation with m and a step of 1 ms crosses zero at 2.352 s, reaches m at 3.137 s, and stays within 0.001 m of the linear formula for 6 s. Even at m, the error is small compared with .
The lookahead sets the trade-off. Measured with the same start and a step of 10 ms:
| (m) | Largest steering (rad) | Time until the error stays within 5 cm (s) | Overshoot (m) |
|---|---|---|---|
| 2 | 0.896 | 0.81 | 0.044 |
| 5 | 0.197 | 2.05 | 0.043 |
| 10 | 0.050 | 4.13 | 0.043 |
The time scales with and the overshoot does not change, as the theorem says: the damping ratio is for every .
Correctness
Pure pursuit is a heuristic, so its correctness is a set of narrower claims, proved in the proof. Lemma 1 is geometric: among circles tangent to the heading at the rear axle, exactly one passes through the goal point, and its curvature is . Lemma 2: the steering angle makes the rear axle of the kinematic bicycle drive on that circle. Theorem 1 (local): on a straight path, the linearized closed loop is , with damping ratio , so the path is locally exponentially stable with rate . Theorem 2: on a circle of radius , a car that starts on the circle stays on it with . There is no global guarantee.
Proof: Pure pursuit steers along the arc through the goal point and converges on a straight pathfull
Line numbers refer to the pseudocode on the pure pursuit page. The vehicle is the rear-axle kinematic bicycle model: , , . Pure pursuit is a heuristic for path tracking: it does not minimize a cost, and nothing guarantees that it tracks every path. This proof shows three things that do hold. Lemma 1 and Lemma 2 say that lines L3 to L5 do what the page says. Theorem 1 gives the local behavior on a straight path, and Theorem 2 shows that a circle is tracked with zero error.
Lemma 1 (the arc through the goal point). Let the goal point have coordinates in the vehicle frame of line L3, with . The circle that passes through the rear axle, is tangent to the heading there and passes through the goal point has signed curvature . If and , the arc is the straight line, with .
Proof. In the vehicle frame the rear axle is the origin and the heading is the axis. A circle tangent to the axis at the origin has its center at for a signed radius , with for a left turn. The goal point is on it when , that is . If , then and . If , no circle of finite radius passes through with , and the line does.
When the goal point is at the lookahead distance, , and with the angle of the goal point seen from the heading, , so , the form of Coulter's report. At the end of the path the goal point can be closer than ; the code uses , so Lemma 1 still holds.
Lemma 2 (the steering angle). With held constant, the rear axle moves on a circle of curvature .
Proof. The curvature of the rear axle path is for , which is when .
So, if the steering acted at once and the vehicle were exactly the model, the rear axle would leave each pose along the arc of Lemma 1. The test test_the_arc_passes_through_the_goal_point checks Lemma 1 on 2000 random cases, and test_rk4_follows_the_exact_arc checks that the integrator of line L7 reproduces the circle of Lemma 2 to m.
Theorem 1 (local behavior on a straight path). Let the path be the axis, let be constant and let the steering be updated continuously (the limit of lines L6 and L7 as the time step goes to 0). Let be the cross-track error of the rear axle and the heading error. The linearization of the closed loop at is
with natural frequency and damping ratio . The origin is locally exponentially stable, with rate , and with the linear solution is , .
Proof. Near the origin the closest point is and the goal point is . In the vehicle frame its lateral coordinate is , and . To first order, , so line L4 gives . Lemma 2 gives exactly, and . Then . The characteristic roots of are . Both have real part , so the linearization is exponentially stable, and by the Jacobian linearization principle the nonlinear origin is locally exponentially stable. Matching and gives the stated values. The general solution is ; gives , and gives .
The test test_small_error_matches_the_linear_closed_form runs the code with m/s, m, mm and a time step of 1 ms, and finds the simulated error within of of the formula for 6 s. The residual comes from the zero-order hold of line L6. The theorem is local. With a steering limit, a large heading error, or a path with corners, the closed loop is not covered by it.
Theorem 2 (a circle is tracked exactly). Let the path be a circle of radius with , and let the rear axle be on the circle with the heading of the circle, driving forward. Then line L5 returns , and the vehicle stays on the circle.
Proof. The goal point is on the circle, at distance ahead, so it exists because . The path circle passes through the rear axle, is tangent to the heading there and passes through the goal point. By the uniqueness in Lemma 1 it is the arc of line L4, so with the sign of the turn, and by Lemma 2 the vehicle moves on it. Its pose then stays on the circle with the same heading, so the same argument holds at every later time.
The test test_tracks_a_circle_exactly drives 25 m on a polyline of 4000 chords around a circle of radius 10 m and finds a radial error below m and a steering angle within rad of rad.
What is not proved. Pure pursuit has no global guarantee. A steering limit can saturate line L5, a corner of the path can make the goal point jump, and a vehicle far from the path can choose a goal point behind a bend. The choice of is a tuning decision, not a result; see the page.
Complexity
- Time per step. Line L1 and line L2 scan the segments from the last closest index, so a step costs in the worst case for a path of vertices. A search window of a few segments around the last index makes it when the vehicle moves less than a segment per step. The rest is . Measured: one call to the steering function takes 2 to 4 microseconds in CPython on a laptop, for a path of two points.
- Space. beyond the path.
Properties
- Geometric and model-light. The law uses only the geometry of the path and the wheelbase. It does not use the speed, the mass or the tires.
- Corner cutting. On a curve, the goal point is inside the curve, and the vehicle cuts it. On a circle the cut is zero only when the vehicle is already on the circle (Theorem 2); at a corner of the path, the vehicle starts to turn up to before the corner.
- Smooth steering. The steering angle changes continuously with the pose when the goal point moves continuously along the path.
- Speed scaling. With a fixed , the closed loop gets faster with (rate ), and at high speed the steering becomes too aggressive for the real tires. A lookahead proportional to the speed, , keeps the response in distance the same.
- Not exact. The vehicle does not converge to the path in finite time, and on a curved path with a varying curvature there is a steady error.
Variants and improvements
- Speed-dependent lookahead. , clamped to a range. Snider's report uses this form with a lower and an upper limit, and tunes on the vehicle. The value of is chosen by experiment, not derived.
- Adaptive pure pursuit. Change with the curvature of the path ahead: shorter on tight curves, longer on straight parts.
- Regulated pure pursuit. Reduce the speed when the curvature of the arc is large or an obstacle is near. The ROS 2 Nav2 stack uses a variant of this kind.
- Vector pursuit. Also matches the heading of the path at the goal point, with screw theory.
- Front-axle or center reference. Using another reference point changes the arc and the steering formula; the rear axle is the point where the kinematic bicycle has no side slip.
When to use it
Use it to follow a path at low or moderate speed, when the path is smooth and a simple, robust law is enough: field robots, warehouse vehicles, small cars and course tracking in research. It handles noisy poses well, because a long lookahead averages them. For high speed or tight tracking, use a controller with a dynamic model, such as the Stanley controller at moderate speed or model predictive control. For reverse motion, run the law on the mirrored vehicle.
Pitfalls
- Lookahead tuning. Too short gives oscillation and, with a time delay in the steering actuator, instability. Too long cuts corners and reacts late. The theorem on the page assumes no delay and no steering limit.
- The goal point jumps. When the vehicle is far from the path, the circle of radius may not meet the path ahead, or may meet a later part of a path that loops. Searching only forward from the last closest index, and taking the end of the path as a fallback, are the usual fixes.
- End of the path. Near the end, the goal point is the last point, closer than . Use the actual distance in line L4, not , or the curvature is wrong.
- Wrong reference point. The formula holds for the rear axle. Measuring the pose at the center of mass or the front axle and using the same formula gives a biased steering.
- Sign conventions. Left turns must have positive , positive and positive in the same frame; a sign error makes the vehicle turn away from the path.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/pure-pursuit/. The authors are listed in prov/RC03NN.jsonl.
"""Pure pursuit path tracking (Wallace et al. 1985, Amidi 1990, Coulter 1992).
The vehicle is the kinematic bicycle model with its reference point at the center of the
rear axle: x' = v cos(theta), y' = v sin(theta), theta' = v tan(delta) / L, with the
wheelbase L in meters and the steering angle delta in radians. The path is a polyline.
At each step the controller picks the goal point: the first point of the path, ahead of
the point closest to the rear axle, at distance ld (the lookahead) from the rear axle.
It steers along the circle arc that starts at the rear axle, is tangent to the heading
and passes through the goal point. That arc has curvature kappa = 2 y_g / ld^2, where
y_g is the lateral coordinate of the goal point in the vehicle frame, and the steering
angle is delta = atan(kappa L).
"""
import math
def wrap(a):
return (a + math.pi) % (2.0 * math.pi) - math.pi
def closest_on_path(path, p, start):
"""Index i and parameter u in [0, 1] of the point of segment i closest to p,
searching the segments from index start onward."""
best = (math.inf, start, 0.0)
for i in range(start, len(path) - 1):
ax, ay = path[i]
bx, by = path[i + 1]
dx, dy = bx - ax, by - ay
den = dx * dx + dy * dy
u = 0.0 if den == 0.0 else max(0.0, min(1.0, ((p[0] - ax) * dx + (p[1] - ay) * dy) / den))
qx, qy = ax + u * dx, ay + u * dy
d2 = (qx - p[0]) ** 2 + (qy - p[1]) ** 2
if d2 < best[0]:
best = (d2, i, u)
return best[1], best[2]
def goal_point(path, p, i, u, ld):
"""First point of the path after (i, u) at distance ld from p, or the last point."""
for j in range(i, len(path) - 1):
ax, ay = path[j]
bx, by = path[j + 1]
dx, dy = bx - ax, by - ay
fx, fy = ax - p[0], ay - p[1]
a = dx * dx + dy * dy
if a == 0.0:
continue
b = 2.0 * (fx * dx + fy * dy)
c = fx * fx + fy * fy - ld * ld
disc = b * b - 4.0 * a * c
if disc < 0.0:
continue
s = (-b + math.sqrt(disc)) / (2.0 * a) # the exit point of the circle
lo = u if j == i else 0.0
if lo <= s <= 1.0:
return ax + s * dx, ay + s * dy
return path[-1]
class PurePursuit:
"""Pure pursuit controller for a polyline path."""
def __init__(self, path, lookahead, wheelbase, max_steer=math.pi / 2.0):
self.path = [tuple(p) for p in path]
self.ld = lookahead
self.L = wheelbase
self.max_steer = max_steer
self.index = 0
self.goal = None
self.kappa = 0.0
def steer(self, pose):
"""Steering angle for the rear axle pose (x, y, theta)."""
x, y, th = pose
i, u = closest_on_path(self.path, (x, y), self.index) # @line L1
self.index = i # @line L1
gx, gy = goal_point(self.path, (x, y), i, u, self.ld) # @line L2
self.goal = (gx, gy)
dx, dy = gx - x, gy - y # @line L3
xv = math.cos(th) * dx + math.sin(th) * dy # @line L3
yv = -math.sin(th) * dx + math.cos(th) * dy # @line L3
d2 = xv * xv + yv * yv
self.kappa = 0.0 if d2 == 0.0 else 2.0 * yv / d2 # @line L4
delta = math.atan(self.kappa * self.L) # @line L5
return max(-self.max_steer, min(self.max_steer, delta)) # @line L5
def bicycle_rhs(state, v, delta, wheelbase):
x, y, th = state
return v * math.cos(th), v * math.sin(th), v * math.tan(delta) / wheelbase
def rk4_step(state, v, delta, wheelbase, dt):
"""One RK4 step of the rear-axle kinematic bicycle with v and delta held constant."""
def add(s, k, h):
return s[0] + h * k[0], s[1] + h * k[1], s[2] + h * k[2]
k1 = bicycle_rhs(state, v, delta, wheelbase)
k2 = bicycle_rhs(add(state, k1, dt / 2.0), v, delta, wheelbase)
k3 = bicycle_rhs(add(state, k2, dt / 2.0), v, delta, wheelbase)
k4 = bicycle_rhs(add(state, k3, dt), v, delta, wheelbase)
return tuple(state[j] + dt / 6.0 * (k1[j] + 2.0 * k2[j] + 2.0 * k3[j] + k4[j]) for j in range(3))
def simulate(controller, pose, v, dt, steps):
"""Closed loop: compute the steering, hold it for dt, integrate with RK4."""
poses = [tuple(pose)]
steers = []
for _ in range(steps): # @line L6
delta = controller.steer(pose) # @line L6
pose = rk4_step(pose, v, delta, controller.L, dt) # @line L7
poses.append(pose)
steers.append(delta)
return poses, steers
test_pure_pursuit.py 97 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/pure-pursuit/. The authors are listed in prov/RC03NN.jsonl.
import math
import random
from pure_pursuit import PurePursuit, goal_point, closest_on_path, rk4_step, simulate, wrap
def test_the_arc_passes_through_the_goal_point():
# The arc of curvature kappa, tangent to the heading at the rear axle, has its center at
# distance 1 / kappa to the left of the vehicle. The goal point must lie on that circle.
rng = random.Random(1)
for _ in range(2000):
path = [(rng.uniform(-20, 20), rng.uniform(-20, 20)) for _ in range(rng.randint(2, 6))]
pose = (rng.uniform(-20, 20), rng.uniform(-20, 20), rng.uniform(-math.pi, math.pi))
pp = PurePursuit(path, rng.uniform(0.5, 10.0), 2.5)
pp.steer(pose)
gx, gy = pp.goal
if abs(pp.kappa) < 1e-9:
# A straight line: the goal point is on the heading line.
assert abs(-math.sin(pose[2]) * (gx - pose[0]) + math.cos(pose[2]) * (gy - pose[1])) < 1e-6
continue
r = 1.0 / pp.kappa
cx, cy = pose[0] - r * math.sin(pose[2]), pose[1] + r * math.cos(pose[2])
assert abs(math.hypot(gx - cx, gy - cy) - abs(r)) < 1e-9 * max(1.0, abs(r))
def test_goal_point_is_at_the_lookahead_distance():
rng = random.Random(2)
for _ in range(2000):
path = [(rng.uniform(-20, 20), rng.uniform(-20, 20)) for _ in range(rng.randint(2, 6))]
p = (rng.uniform(-20, 20), rng.uniform(-20, 20))
ld = rng.uniform(0.5, 10.0)
i, u = closest_on_path(path, p, 0)
g = goal_point(path, p, i, u, ld)
if g != path[-1]:
assert abs(math.hypot(g[0] - p[0], g[1] - p[1]) - ld) < 1e-9
def test_straight_line_convergence():
# Start 1 m to the left of the x axis and 0.3 rad off the heading.
path = [(-10.0, 0.0), (500.0, 0.0)]
pp = PurePursuit(path, 5.0, 2.5)
poses, steers = simulate(pp, (0.0, 1.0, 0.3), 5.0, 0.02, 1500)
x, y, th = poses[-1]
assert abs(y) < 1e-6 and abs(wrap(th)) < 1e-6
assert abs(steers[-1]) < 1e-6
def test_small_error_matches_the_linear_closed_form():
# Linearized on a straight line: e'' + (2 v / ld) e' + (2 v^2 / ld^2) e = 0, so with
# a = v / ld and zero heading error at t = 0, e(t) = e0 exp(-a t) (cos a t + sin a t).
v, ld, e0, dt = 5.0, 5.0, 1e-3, 0.001
a = v / ld
pp = PurePursuit([(-10.0, 0.0), (500.0, 0.0)], ld, 2.5)
poses, _ = simulate(pp, (0.0, e0, 0.0), v, dt, 6000)
worst = 0.0
for k in range(0, 6001, 50):
t = k * dt
lin = e0 * math.exp(-a * t) * (math.cos(a * t) + math.sin(a * t))
worst = max(worst, abs(poses[k][1] - lin))
# The steering is held for dt, which acts like a delay of dt / 2.
assert worst < 1e-3 * e0
def test_tracks_a_circle_exactly():
# On a circle of radius R the goal point stays on the circle, the arc through it is the
# circle itself, and the steering is atan(L / R).
R, L, n = 10.0, 2.5, 4000
path = [(R * math.sin(2 * math.pi * k / n), R - R * math.cos(2 * math.pi * k / n)) for k in range(n + 1)]
pp = PurePursuit(path, 4.0, L)
poses, steers = simulate(pp, (0.0, 0.0, 0.0), 2.0, 0.05, 250)
for (x, y, _), d in zip(poses, steers):
# The polyline has 4000 chords, so the circle is exact to about 1e-5 m.
assert abs(math.hypot(x, y - R) - R) < 1e-5
assert abs(d - math.atan(L / R)) < 1e-5
def test_steering_limit_is_respected():
rng = random.Random(3)
for _ in range(500):
path = [(rng.uniform(-5, 5), rng.uniform(-5, 5)) for _ in range(3)]
pp = PurePursuit(path, rng.uniform(0.5, 3.0), 2.5, max_steer=0.5)
pose = (rng.uniform(-5, 5), rng.uniform(-5, 5), rng.uniform(-math.pi, math.pi))
assert -0.5 <= pp.steer(pose) <= 0.5
def test_rk4_follows_the_exact_arc():
# With a constant steering angle the rear axle moves on a circle of radius L / tan(delta).
L, delta, v, dt = 2.5, 0.3, 3.0, 0.01
q = (0.0, 0.0, 0.0)
for _ in range(300):
q = rk4_step(q, v, delta, L, dt)
r = L / math.tan(delta)
th = v * 3.0 / r
assert abs(q[0] - r * math.sin(th)) < 1e-9 and abs(q[1] - r * (1 - math.cos(th))) < 1e-9
History
Pure pursuit came from the road-following work at Carnegie Mellon University in the 1980s. Wallace, Stentz, Thorpe, Moravec, Whittaker and Kanade described an early form in 1985, and Amidi compared it with other path trackers in his report of 1990. Coulter's report of 1992 wrote down the geometry of the arc and the implementation steps, and most later code follows it. Snider's report of 2009 described pure pursuit, the Stanley controller and other steering laws for cars side by side, with their tuning.
References
- Implementation of the Pure Pursuit Path Tracking Algorithm, the whole report (the curvature of the arc through the goal point and the steps of the implementation)
- Automatic Steering Methods for Autonomous Automobile Path Tracking, the section on pure pursuit (the law kappa = 2 sin(alpha) / ld, the steering angle of the bicycle model, and a lookahead proportional to speed with a lower and an upper limit)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag RC03NN Edit this page History Report an error Markdown