Module 4/5 · Weeks 10–12 · 27 h

Path planning and avoidance

UAT 308 Automation and Robotics Technology

About 90 minDraft, awaiting reviewLast updated 24 October 2026

Lesson

By the end of this module you will be able to

  1. Explain sampling-based planning and write RRT on a map with obstacles
  2. Shorten an RRT path by shortcutting
  3. Use pure pursuit to track a path and choose a lookahead distance that suits the delay
  4. Separate the roles of the path planner and the path tracker
  5. Convert speed and turn-rate commands into wheel speeds and control them with a PI loop

Prerequisites: UAT 308 Modules 1–3 · UAT 304 Module 3 (route and waypoint planning)

Why this matters

Grid path finding often uses A*, and reactive obstacle avoidance often uses potential fields or VFH. This module adds two things: RRT, which finds paths in continuous space without dividing it into a grid, and pure pursuit, which turns a path into steering commands. The textbooks by Siegwart et al. and by Lynch and Park separate these two jobs: the planner answers “which way?” and the tracker answers “how much to steer now?”

RRT

RRT (Rapidly-exploring Random Tree, LaValle 1998) grows a tree from the start. Each iteration samples a random point, finds the nearest node in the tree, and extends a branch one step towards it; if the branch hits no obstacle, it is added. Random sampling makes the tree expand quickly into unexplored free space, and some iterations sample the goal directly (goal bias) to pull the tree towards it. The first path is usually winding, so it is commonly shortcut by drawing straight lines between points with nothing in between.

Example 1 Crossing panel rows to the inverter cabinet

A 20 × 20 m area has three panel rows staggered from alternate sides. The UGV starts at (1, 1) and must reach the inverter cabinet at (19, 19). The branch step is 1 m, 10% of samples are the goal, and the random seed is fixed so results repeat (simulated data).

import numpy as np

rng = np.random.default_rng(7)
start, goal = np.array([1.0, 1.0]), np.array([19.0, 19.0])
# solar panel rows (xmin, ymin, xmax, ymax) m
rows = [(0, 5, 15, 6.5), (5, 10, 20, 11.5), (0, 15, 15, 16.5)]

def free(p):
    return all(not (x0 <= p[0] <= x1 and y0 <= p[1] <= y1) for x0, y0, x1, y1 in rows)

def segment_free(a, b, step=0.1):
    n = max(2, int(np.linalg.norm(b - a) / step))
    return all(free(a + (b - a) * s) for s in np.linspace(0, 1, n))

def rrt(max_nodes=3000, step=1.0, goal_bias=0.1):
    nodes, parent = [start], [-1]
    while len(nodes) < max_nodes:
        sample = goal if rng.random() < goal_bias else rng.uniform(0, 20, 2)
        i = int(np.argmin([np.linalg.norm(n - sample) for n in nodes]))
        d = sample - nodes[i]
        new = nodes[i] + d / max(np.linalg.norm(d), 1e-9) * min(step, np.linalg.norm(d))
        if free(new) and segment_free(nodes[i], new):
            nodes.append(new); parent.append(i)
            if np.linalg.norm(new - goal) < step and segment_free(new, goal):
                nodes.append(goal); parent.append(len(nodes) - 2)
                path, k = [], len(nodes) - 1
                while k != -1:
                    path.append(nodes[k]); k = parent[k]
                return path[::-1], len(nodes)
    return None, len(nodes)

def length(path):
    return sum(np.linalg.norm(path[i+1] - path[i]) for i in range(len(path) - 1))

def shortcut(path):
    out, i = [path[0]], 0
    while i < len(path) - 1:
        j = len(path) - 1
        while j > i + 1 and not segment_free(path[i], path[j]):
            j -= 1
        out.append(path[j]); i = j
    return out

path, n = rrt()
short = shortcut(path)
print(f"nodes in tree {n}")
print(f"RRT path {length(path):.1f} m ({len(path)} points)")
print(f"after shortcutting {length(short):.1f} m ({len(short)} points)")
print(f"straight line {np.linalg.norm(goal - start):.1f} m (blocked by panels)")
nodes in tree 389
RRT path 70.7 m (74 points)
after shortcutting 52.6 m (7 points)
straight line 25.5 m (blocked by panels)

RRT finds a feasible path within a few hundred nodes, but it winds for 70.7 m. Shortcutting cuts it to 52.6 m with just 7 waypoints. The path still hugs the panel edges, so real work must inflate obstacles by half the vehicle width plus a margin before planning. RRT results depend on sampling: a different seed gives a different path, so test several times.

A 20 by 20 metre area with three light purple panel rows staggered left and right; thin grey RRT branches spread throughout; a winding pink line runs from the lower left to the upper right around the row ends, and a thick green line is the straighter path after shortcutting
Figure 1 RRT in the solar farm and the shortcut path

Pure pursuit

Coulter (1992) describes pure pursuit as choosing a goal point on the path at a lookahead distance from the vehicle, then computing the curvature of the circle through both vehicle and goal point, , where is the goal point’s lateral offset in the vehicle frame. Equivalently, , where is the angle from the vehicle heading to the goal point. The commanded turn rate is . A short lookahead joins the path quickly but is sensitive to delay and noise; a long one is smooth but cuts corners and joins slowly.

Example 2 Joining a panel row line with a 0.3 s steering delay

The UGV drives at 1 m/s, starting 1.0 m from the row line and parallel to it. Steering commands reach the wheels 0.3 s late because of communication and the motor driver. Compare lookahead distances of 0.5, 1.0, 1.5 and 3.0 m (a kinematic model).

import numpy as np

V, DT, T = 1.0, 0.05, 15.0     # speed m/s, time step s, simulated time s
DELAY = 0.3                    # steering command reaches wheels 0.3 s late

def track(Ld):
    x, y, th = 0.0, 1.0, 0.0            # start 1.0 m from the path y = 0
    buf = [0.0] * int(round(DELAY / DT))
    ys = []
    for _ in range(int(T / DT)):
        dx, dy = Ld, -y                 # goal point on the path, Ld ahead along x
        alpha = np.arctan2(dy, dx) - th
        buf.append(2 * np.sin(alpha) / np.hypot(dx, dy))
        kappa = buf.pop(0)
        th += V * kappa * DT
        x += V * np.cos(th) * DT
        y += V * np.sin(th) * DT
        ys.append(y)
    return np.array(ys)

for Ld in [0.5, 1.0, 1.5, 3.0]:
    ys = track(Ld)
    out = np.where(np.abs(ys) >= 0.05)[0]
    settle = (out[-1] + 1) * DT
    s = f"settles within ±5 cm by {settle:.1f} s" if settle < T else "does not settle in 15 s"
    print(f"Ld={Ld:.1f} m  {s}  max overshoot {max(0, -ys.min())*100:.1f} cm")
Ld=0.5 m  does not settle in 15 s  max overshoot 24.9 cm
Ld=1.0 m  settles within ±5 cm by 2.3 s  max overshoot 1.8 cm
Ld=1.5 m  settles within ±5 cm by 3.2 s  max overshoot 2.7 cm
Ld=3.0 m  settles within ±5 cm by 6.1 s  max overshoot 3.8 cm

Without delay, the shortest lookahead joins the path fastest. With a 0.3 s delay, a 0.5 m lookahead oscillates without settling, 1.0 m reaches the ±5 cm band fastest, and 3.0 m is smooth but slow. Lookahead must therefore be chosen together with the speed and delay of the real system; many systems scale lookahead with speed.

Distance from the path against time from 0 to 15 seconds: the pink 0.5 metre lookahead line keeps oscillating around plus or minus 0.25 metres; the green 1.0 metre line drops to zero within about 2 to 3 seconds; the blue 3.0 metre line falls slowly and reaches zero around 6 seconds
Figure 2 Pure pursuit with different lookahead distances

Low-level control: wheel speed with PI

Pure pursuit only says how fast the vehicle should drive and turn. Someone still has to make each wheel actually turn at the right speed on grass, gravel and slopes. A robot’s control system is therefore a cascade, like the flight controller in UAT 202 module 5: the planner (RRT) gives a new path only occasionally, when the route or obstacles change, the tracker (pure pursuit) turns it into speed and turn rate many times a second, and the fastest inner loop controls each motor.

For a differential-drive UGV, the wheel speeds come from the same geometry as odometry in module 1:

In ROS 2, the diff_drive_controller of ros2_control does exactly this conversion and computes odometry from wheel feedback; the wheel speed control itself happens in the hardware interface or the motor driver. That inner loop is usually a PI or PID controller (Lynch and Park; Åström and Murray). The proportional term reacts to the present error; the integral term accumulates error over time, so a steady load such as a slope cannot leave a permanent speed error. When the motor voltage hits its limit, integration must stop (anti-windup, as in UAT 202 module 4).

Example 3 Wheel speed control on a slope

Pure pursuit commands 1.0 m/s with a 0.4 rad/s turn. The UGV of module 1 has a 0.50 m wheel separation and 0.10 m wheels. The wheel motor is modelled as first order with a 0.2 s time constant and a gain of 1 (rad/s)/V, limited to 24 V; from t = 2 s the vehicle climbs a slope that pulls the wheel speed down (all motor values assumed). Compare P control with PI control on the right wheel.

V, W = 1.0, 0.4                 # pure pursuit command: 1.0 m/s, 0.4 rad/s turn
B, R = 0.50, 0.10               # wheel separation and radius m (as in module 1)
w_right = (V + W * B / 2) / R   # wheel speed targets rad/s
w_left = (V - W * B / 2) / R
print(f"wheel targets: right {w_right:.1f} rad/s, left {w_left:.1f} rad/s")

TAU, K, U_MAX, DT = 0.20, 1.0, 24.0, 0.01   # motor model: time constant s, gain (rad/s)/V, voltage limit (assumed)

def run(kp, ki, target=w_right):
    w, integ, log = 0.0, 0.0, {}
    for k in range(int(4.0 / DT)):
        t = k * DT
        slope = -4.0 if t >= 2.0 else 0.0            # climbing a slope from t = 2 s slows the wheel
        e = target - w
        u = kp * e + ki * integ
        if abs(u) < U_MAX:                          # stop integrating while saturated (anti-windup)
            integ += e * DT
        u = max(-U_MAX, min(U_MAX, u))
        w += DT / TAU * (-w + K * u + slope)
        log[round(t + DT, 2)] = w
    return log

for name, kp, ki in (("P  (kp 2)", 2.0, 0.0), ("PI (kp 2, ki 10)", 2.0, 10.0)):
    log = run(kp, ki)
    dip = min(v for t, v in log.items() if t > 2.0)
    print(f"{name:<17} at 1.9 s {log[1.9]:5.2f}, lowest on slope {dip:5.2f}, at 4.0 s {log[4.0]:5.2f} rad/s")
wheel targets: right 11.0 rad/s, left 9.0 rad/s
P  (kp 2)         at 1.9 s  7.33, lowest on slope  6.00, at 4.0 s  6.00 rad/s
PI (kp 2, ki 10)  at 1.9 s 11.00, lowest on slope  9.96, at 4.0 s 11.00 rad/s

With P control alone the wheel settles at only 7.33 rad/s even on flat ground, and drops to 6.00 rad/s on the slope. If both wheels were P controlled, the left wheel would settle at 6.0 rad/s, so the vehicle would drive at about 0.67 m/s and turn at 0.27 rad/s instead of 0.4, and pure pursuit would keep correcting an error that the inner loop created. The PI controller reaches the target, dips by about 1 rad/s when the slope starts, then recovers fully. Tune the inner loop first and make it much faster than the outer loops; only then tune the lookahead.

Module lab

Lab: planning and tracking in a mock field

Done in the course lab hours as Worksheet 4 (weeks 10 to 12 of the weekly plan); not counted in the module class time.

  1. Build a mock panel-row field with cones or boards, and inflate the obstacles by the vehicle width
  2. Find paths with RRT following Example 1 ten times with different seeds, recording length and node count, and compare with A* on a grid
  3. Measure the real steering delay from sending a command to the wheels starting to turn
  4. Have the UGV track the path with pure pursuit at 3 lookahead values, measuring lateral error with LiDAR or RTK GNSS
  5. Choose the lookahead to use and justify it from the measurements

Common mistakes

Watch out

  • Not inflating obstacles by vehicle size, so paths run too close to edges
  • Trusting a single RRT run when results depend on sampling
  • Setting a short lookahead without considering delay
  • Making the tracker solve the planner’s problems, such as avoiding new obstacles
  • Not limiting speed in tight turns
  • Tuning the lookahead before the wheel speed loop works, or using P control alone so wheels never reach their target

Summary

  • RRT finds paths in continuous space by randomly growing a tree, and should be shortcut afterwards
  • Pure pursuit computes curvature from a goal point one lookahead distance ahead
  • Lookahead must be chosen together with speed and system delay
  • The planner and tracker work at different levels and rates
  • Below the tracker, each wheel’s speed is held by a PI loop; the integral removes steady errors from loads such as slopes, and the inner loop must be tuned first

Check your understanding

  1. How does RRT grow its tree in each iteration?
  2. The UGV (b = 0.5 m, r = 0.1 m) is commanded 1.0 m/s and 0.4 rad/s. What speed must the left wheel turn at?
  3. A goal point is 0.5 m to the side with a 2 m lookahead. What is the curvature?
  4. A curvature of 0.25 1/m at 2 m/s gives what turn rate?
  5. Why does a short lookahead oscillate when there is delay?
Answers
  1. Sample a point, find the nearest node, extend one step towards the point, and add it if collision-free
  2. rad/s
  3. 1/m
  4. rad/s
  5. The vehicle corrects hard and fast but commands reach the wheels late, so it overshoots and corrects back and forth

Key formulas

Pure pursuit curvature
Right wheel speed
Turn rate

Key references

  1. LaValle, S. M. (1998). Rapidly-exploring random trees: A new tool for path planning (TR 98-11). Iowa State University. link
  2. Coulter, R. C. (1992). Implementation of the pure pursuit path tracking algorithm (Tech. Rep. CMU-RI-TR-92-01). Robotics Institute, Carnegie Mellon University. link
  3. Siegwart, R., Nourbakhsh, I. R., & Scaramuzza, D. (2011). Introduction to autonomous mobile robots (2nd ed.). MIT Press. link
  4. Lynch, K. M., & Park, F. C. (2017). Modern robotics: Mechanics, planning, and control. Cambridge University Press. link
  5. Åström, K. J., & Murray, R. M. (2021). Feedback systems: An introduction for scientists and engineers (2nd ed.). Princeton University Press. link
  6. ros2_control Maintainers. Diff drive controller. ros2_controllers documentation (Jazzy). link

Further reading

Study the assigned knowledge units in advance, review media and take the module quiz

In class / field

Lab or field practice from worksheets with a safety checklist

Learning evidence: Checked worksheets and quiz results

Module quiz

This is a formative self-check, not a graded exam

Knowledge domain: Control, autopilot and navigation · Automation, robotics and swarms