Algorithm Search⌘K

Algorithmadvanced

State lattice planning

Also called state lattice.

Searches a regular lattice of states joined by precomputed feasible motion primitives, so every path respects the vehicle model.

Time
O(N (log N + b c)) worst
Space
O(N) extra
Where
N = the number of lattice states in the map; b = the number of primitives per state; c = the number of cells in the swath of a primitive
Properties
deterministicnot exactofflinenot randomized
Origin
Mihail Pivtoraiko, Alonzo Kelly, 2005

State lattice planning finds paths for a vehicle with motion constraints, such as a car that cannot turn on the spot. It chooses a regular grid of states, for example positions on a square lattice and 8 or 16 headings. It then builds, once and offline, a small set of motion primitives: short paths that the vehicle can drive and that start and end exactly at lattice states. These primitives, repeated at every state, turn the lattice into a graph, and a graph search such as A* finds a path in it. Because each edge is a feasible motion and joins states exactly, every path in the graph can be driven, and the search is complete and optimal with respect to the lattice and the set of primitives. The method plans for planetary rovers, field robots and autonomous cars.

In plain words

Think of a city of square blocks where a car may only stop at street corners, and only facing one of eight directions. Someone has worked out, once, a short list of moves: go one block straight, or make a gentle curve that ends exactly at another corner, facing another of the eight directions. The car never needs to know more than these moves.

To plan a trip, you search over corners and directions, using only the moves on the list, like a route planner on a map. Every route found is one the car can drive. The catch: a route that needs a stop between corners, or a curve that is not on the list, is never found.

The problem

The model. The vehicle is a forward-driving car with a minimum turning radius, as in the kinematic bicycle model or the Dubins car. The map is an occupancy grid. The lattice has spacing rr and 8 headings kπ/4k\pi/4; the implementation uses arcs of radius R=(1+2) rR = (1 + \sqrt2)\,r, which is the radius the 45 degree turns below need, so the car's own minimum radius must be at most RR. The model is the word RAM with states as integer triples at this resolution.

Input. The grid, a start state and a goal state on the lattice.

Output. A list of lattice states joined by primitives, of least total length among the paths of the lattice graph, or failure.

How it differs from close pages. Hybrid A* also searches with arcs of the car, but from the exact poses where the arcs end, which are off the grid; it keeps one pose per cell and loses completeness and optimality even with respect to its own primitives. A state lattice keeps the states on the grid, so the graph is fixed and the guarantees of graph search hold for it. Grid A* on cells ignores the heading and the turning radius. Kinodynamic planning is the general problem; sampling planners solve it without a fixed lattice.

The algorithm

The control set for heading 0 is three primitives: straight to (1,0,0)(1, 0, 0), length 1; a left turn to (2,1,1)(2, 1, 1), an arc of radius 1+21 + \sqrt2 through π/4\pi/4 and then a straight piece of 2−1\sqrt2 - 1, length 2.31032.3103; and the mirror right turn to (2,−1,7)(2, -1, 7). For heading 1 (π/4\pi/4): straight to (1,1,1)(1, 1, 1), length 2\sqrt2; a right turn to (2,1,0)(2, 1, 0), the straight piece first and then the arc; and the mirror left turn to (1,2,2)(1, 2, 2). Rotations by π/2\pi/2 give the other six headings. Lengths are in units of rr.

  1. LATTICE-PLAN(map, start, goal)
  2. 1g(start) ← 0; push start with f = h(start)
  3. 2h(s) = r |(i, j) - (i_goal, j_goal)|
  4. 3while the open list is not empty: pop the state s with the least f; skip it if closed; close it
  5. 4if s = goal then return the path of parents to s
  6. 5for each primitive p of the control set for the heading of s do
  7. 6if the swath of p, shifted to s, is inside the map and free then
  8. 7t ← the end state of p from s; if g(s) + r length(p) < g(t) then set g(t), parent(t) ← s, push t
  9. 8return failure

The swath of a primitive is the set of cells it touches when driven from (0,0,k)(0, 0, k). It is computed once for each primitive and shifted by (i,j)(i, j) at search time, so the collision check of line L6 is a few set lookups. This is the main practical gain of the lattice: all the geometry is done offline.

Example

Lattice spacing r=1r = 1 m, so R=2.4142R = 2.4142 m. On an empty map, from (5,5,0)(5, 5, 0) to (11,8,2)(11, 8, 2), that is, 6 m ahead and 3 m to the left, now facing north. A* expands 24 states and returns three straight primitives, a left turn to (10,6,1)(10, 6, 1) and a left turn to (11,8,2)(11, 8, 2), length 7.6207 m. Dijkstra on the same graph expands 71 states and finds the same length. The Dubins path with the same radius, which is the continuous optimum, has length 7.4256 m, so the lattice path is 2.6% longer.

The gap can be large. For a U-turn from (5,5,0)(5, 5, 0) to (10,5,4)(10, 5, 4), the lattice path has 9 primitives and length 19.4827 m, against 15.1990 m for the Dubins path: 28% longer, because the lattice offers only 45 degree turns of one radius. Measured: 376 expansions for A* and 1548 for Dijkstra.

Obstacles show the other limit. Add a wall of cells at x∈[9,10)x \in [9, 10), 6≤y<156 \le y < 15 on a 20 m by 20 m map, and plan from (5,10,0)(5, 10, 0) to (14,10,0)(14, 10, 0), just behind the wall, facing east. A* finds a path of 16 primitives and 34.76 m that passes under the wall and loops back, in about 30 ms in CPython. For the goal (13,10,0)(13, 10, 0) it returns failure: no sequence of primitives ends there, because the turns need more room than the lattice gives next to the wall. A continuous car with the same radius can reach it: driving south at x=10.1x = 10.1 and turning left through a quarter circle ends facing east at x=12.5x = 12.5, y=10y = 10, and a short straight piece reaches x=13x = 13. This is what completeness with respect to the lattice means.

Correctness

The proof has three lemmas and a theorem. Lemma 1: each primitive ends exactly at a lattice state; for the 45 degree turn this is the identity R/2+1−1/2=2R/\sqrt2 + 1 - 1/\sqrt2 = 2 with R=1+2R = 1 + \sqrt2. Lemma 2: each primitive and each sequence of primitives is a C1C^1 forward path with curvature at most 1/R1/R, so it can be driven. Lemma 3: the shifted swath is the set of cells the primitive's samples touch. Theorem: the heuristic is consistent, the lattice graph is finite, and A* returns a least-length path in the graph or reports that none exists. The guarantees hold with respect to the lattice and the control set, not for the continuous problem.

Proof: State lattice search is feasible, complete and optimal with respect to its lattice and control setfull

Line numbers refer to the pseudocode on the state lattice planning page. Lengths are in lattice units (r=1r = 1); the costs in meters are rr times these. The lattice states are (i,j,k)(i, j, k) with integers i,ji, j and a heading kπ/4k\pi/4, k∈{0,…,7}k \in \{0, \dots, 7\}. The radius of every arc is R=1+2R = 1 + \sqrt 2.

Lemma 1 (primitives join lattice states). Each primitive of the control set, driven from (0,0,k)(0, 0, k), ends exactly at the lattice state given in the table of the page.

Proof. Start with the left turn from heading 0. An arc of radius RR through the angle π/4\pi/4 from (0,0,0)(0, 0, 0) ends at (Rsin⁡π4, R(1−cos⁡π4))=(R/2, R(1−1/2))(R\sin\frac\pi4,\ R(1 - \cos\frac\pi4)) = (R/\sqrt2,\ R(1 - 1/\sqrt2)) with heading π/4\pi/4. The straight part of length 2−1\sqrt2 - 1 along π/4\pi/4 adds (1−1/2, 1−1/2)(1 - 1/\sqrt2,\ 1 - 1/\sqrt2). With R=1+2R = 1 + \sqrt2, R/2=1+1/2R/\sqrt2 = 1 + 1/\sqrt2 and R(1−1/2)=1−1/2+2−1=1/2R(1 - 1/\sqrt2) = 1 - 1/\sqrt2 + \sqrt2 - 1 = 1/\sqrt2. So the end point is (2,1)(2, 1), with heading π/4\pi/4, the state (2,1,1)(2, 1, 1). The right turn is its mirror image in the xx axis and ends at (2,−1,7)(2, -1, 7). The straight primitives end at (1,0,0)(1, 0, 0) and (1,1,1)(1, 1, 1) by inspection. The turn from (0,0,1)(0, 0, 1) to (2,1,0)(2, 1, 0) is the left turn above driven backward in time and rotated by π\pi: reversing it gives a path from (2,1)(2, 1) with heading 5π/45\pi/4 to (0,0)(0, 0) with heading π\pi, and the rotation by π\pi about the origin after the shift by (−2,−1)(-2, -1) maps it to a path from (0,0,π/4)(0, 0, \pi/4) to (2,1,0)(2, 1, 0), made of a straight part of length 2−1\sqrt2 - 1 and then a right arc through π/4\pi/4. The turn to (1,2,2)(1, 2, 2) is its mirror image in the line y=xy = x. A rotation by π/2\pi/2 maps lattice points to lattice points and adds 2 to kk, so the primitives of the other six headings also join lattice states. □\square

The test test_primitives_end_on_lattice_states drives all 24 primitives in floating point and finds every end within 10−1210^{-12} of its lattice state.

Lemma 2 (primitives are paths of the car). Each primitive is a C1C^1 curve with curvature 00 or ±1/R\pm 1/R, driven forward. So it is a path of the forward car with minimum turning radius RrR r meters, and a sequence of primitives that joins states is again such a path.

Proof. Each piece is an arc of radius RR or a line, both driven forward. Inside a primitive, the arc and the line meet with the same heading, because the line starts in the direction where the arc ends. Two consecutive primitives meet at a lattice state whose heading both of them use, the end heading of the first and the start heading of the second, so the heading is continuous there too. □\square

Lemma 3 (the collision test). Line L6 accepts a primitive from (i,j,k)(i, j, k) only if every sample of the primitive, at spacing at most 1/81/8, lies in a free cell inside the map, where a sample on a cell border counts for the cells on both sides.

Proof. The swath of a primitive is the set of cells hit by its samples from (0,0,k)(0, 0, k), computed once. A shift by the integer vector (i,j)(i, j) moves each sample and its cell by the same vector, so the cells hit from (i,j,k)(i, j, k) are the swath shifted by (i,j)(i, j), and line L6 checks exactly those. □\square

As for every sampled check, an arc can clip the corner of a blocked cell between two samples. The test test_path_is_continuous_and_collision_free samples every returned path four times more densely than the swath and finds no sample in a blocked cell.

Theorem (optimal and complete with respect to the lattice). Let G\mathcal G be the directed graph whose vertices are the lattice states in the map and whose edges are the primitives that pass the test of line L6, weighted by their lengths. The search of lines L1 to L8 returns a path of least weight in G\mathcal G from the start to the goal if one exists, and failure otherwise.

Proof. G\mathcal G is finite: it has 8(nx+1)(ny+1)8(n_x + 1)(n_y + 1) vertices and at most three edges per vertex, all with positive weight. The heuristic of line L2 is h(s)=∣(i,j)−(ig,jg)∣h(s) = |(i, j) - (i_g, j_g)|. A primitive from ss to tt has length at least the distance between its end points, so h(s)≤∣(is,js)−(it,jt)∣+h(t)≤w(s,t)+h(t)h(s) \le |(i_s, j_s) - (i_t, j_t)| + h(t) \le w(s, t) + h(t), and h=0h = 0 at the goal: hh is consistent. A* with a consistent heuristic on a finite graph with positive weights expands each vertex at most once, with its least distance from the start, and stops at the goal with a shortest path, or empties the open list exactly when the goal cannot be reached; see A* search and consistent heuristic. □\square

The test test_a_star_matches_dijkstra compares the cost with Dijkstra's algorithm on the same graph on random maps and finds them equal to 10−910^{-9}, with A* expanding no more states.

What the theorem does not say. The optimality and the completeness are relative to the lattice and to the control set. A path of the continuous car can exist where G\mathcal G has none, and the continuous optimum can be shorter than the best lattice path; the page gives examples of both. Pivtoraiko, Knepper and Kelly call this resolution completeness and optimality with respect to the lattice.

Complexity

  • Time. With NN lattice states, bb primitives per state and swaths of cc cells, A* does at most NN expansions, each with bb swath checks of cc lookups and heap operations of O(log⁡N)O(\log N): O(N(log⁡N+bc))O(N(\log N + bc)). Here N=8(nx+1)(ny+1)N = 8(n_x + 1)(n_y + 1), b=3b = 3, and cc is 6 to 8.
  • Space. O(N)O(N) for the costs and the parents, plus the control set and the swaths, which do not depend on the map.
  • Offline work. Building the control set is a boundary value problem for each primitive. For this lattice it has a closed form; for richer vehicle models, Pivtoraiko et al. compute the primitives with a trajectory generator offline.

Properties

  • Feasible by construction. Every path respects the curvature bound and has a continuous heading, with no smoothing step.
  • Complete and optimal with respect to the lattice. If the lattice graph has a path, the search finds the shortest one; this is a theorem, relative to the lattice and the control set.
  • Not complete for the continuous problem. The example above has a reachable goal that the lattice cannot reach.
  • Regular. The graph is the same at every lattice point up to a shift, so primitives, swaths and heuristic tables are computed once.
  • Choice of control set. More primitives give shorter paths and fewer failures, at a higher branching factor. Pivtoraiko and Kelly choose a near minimal control set: one that reaches the same states with as few primitives as possible.

Variants and improvements

  • More headings and curvatures. 16 headings, and states that also store the curvature, so that the path has continuous curvature.
  • Reverse primitives. Add primitives driven backward, with a higher cost, for parking.
  • Time and velocity. Add time and speed to the state for dynamic obstacles; the lattice becomes a spatio-temporal lattice.
  • Road-aligned lattices. For driving on roads, the lattice follows the lane, with stations along the road and lateral offsets.
  • Heuristic look-up tables. Precompute the exact lattice cost without obstacles for nearby goals and use it as the heuristic; it dominates the Euclidean distance.
  • Incremental search. Replan with D* Lite or anytime search when the map changes.

When to use it

Use it when the vehicle has motion constraints, the environment is known as a grid, and you want guarantees that a graph search gives: an answer whenever the lattice has one, and the best one. It fits rovers, field robots and cars on structured roads or in parking lots. It fits less when the goal pose is not on the lattice (connect to it with a final local path), or when the robot needs paths that the lattice cannot express. Hybrid A* is a common alternative with fewer guarantees but no need for a carefully designed control set.

Pitfalls

  • Primitives that do not land on the lattice. Rounding the end of a primitive to the nearest state breaks feasibility. Solve for primitives that end exactly, as Lemma 1 does.
  • Heading set and lattice spacing. On a square lattice, only some headings, such as multiples of π/4\pi/4 or the directions of (2,1)(2, 1), have short straight primitives. 16 headings with non-uniform angles are common for this reason.
  • Turning radius. The control set fixes the radius. A lattice built for one radius cannot be used for a car that turns less sharply.
  • Swath sampling. A sampled swath can miss a corner. Dilate the obstacles or compute the swath with the vehicle footprint.
  • The goal must be a state. If the goal pose is between states, the search can only reach a nearby state.
  • Branching. Large control sets slow the search more than they improve the paths. Use a small, spanning set.

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.

state_lattice_planning.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/state-lattice-planning/. The authors are listed in prov/C6YCHP.jsonl.

"""State lattice planning for a forward-driving car on a lattice of 8 headings.

States are (i, j, k): the position (i r, j r) on a square lattice of spacing r and the
heading k pi / 4. A motion primitive is a short path of the car, made of arcs of radius
R = (1 + sqrt(2)) r and straight segments, that starts at a lattice state and ends exactly
at another one (Pivtoraiko and Kelly 2005, Pivtoraiko, Knepper and Kelly 2009). The
control set here, for heading 0, is:

    straight  (0, 0, 0) -> (1, 0, 0), length r
    left 45   (0, 0, 0) -> (2, 1, 1): arc of R through pi / 4, then straight (sqrt(2) - 1) r
    right 45  (0, 0, 0) -> (2, -1, 7): the mirror image

and for heading 1 (pi / 4):

    straight  (0, 0, 1) -> (1, 1, 1), length sqrt(2) r
    right 45  (0, 0, 1) -> (2, 1, 0): straight (sqrt(2) - 1) r, then arc of R through -pi / 4
    left 45   (0, 0, 1) -> (1, 2, 2): the mirror image across the line y = x

Rotations by multiples of pi / 2 give the primitives of the other six headings. Each
primitive's swept cells are computed once (the precomputed swath of the paper), so a
collision check is a set lookup. The search is A* with the Euclidean heuristic.
"""

import heapq
import math

SQRT2 = math.sqrt(2.0)
R_UNIT = 1.0 + SQRT2  # the turning radius in lattice units
STUB = SQRT2 - 1.0  # the straight part of a 45 degree turn
QUARTER = math.pi / 4.0


def wrap(a):
    return (a + math.pi) % (2.0 * math.pi) - math.pi


def drive(q, segments):
    """Exact pose after segments of (curvature, length) from q, in lattice units."""
    x, y, th = q
    for kappa, s in segments:
        if kappa == 0.0:
            x, y = x + s * math.cos(th), y + s * math.sin(th)
        else:
            nth = th + kappa * s
            x += (math.sin(nth) - math.sin(th)) / kappa
            y -= (math.cos(nth) - math.cos(th)) / kappa
            th = nth
    return x, y, th


def _base_primitives():
    """Primitives for headings 0 and 1 as (di, dj, k_end, segments), in lattice units."""
    left, right = 1.0 / R_UNIT, -1.0 / R_UNIT
    arc = R_UNIT * QUARTER
    return {
        0: [
            (1, 0, 0, [(0.0, 1.0)]),
            (2, 1, 1, [(left, arc), (0.0, STUB)]),
            (2, -1, 7, [(right, arc), (0.0, STUB)]),
        ],
        1: [
            (1, 1, 1, [(0.0, SQRT2)]),
            (2, 1, 0, [(0.0, STUB), (right, arc)]),
            (1, 2, 2, [(0.0, STUB), (left, arc)]),
        ],
    }


def _rotate(di, dj, quarter_turns):
    for _ in range(quarter_turns):
        di, dj = -dj, di
    return di, dj


def build_control_set():
    """Primitives for all 8 headings: k -> list of (di, dj, k_end, length, segments)."""
    base = _base_primitives()
    out = {}
    for k in range(8):
        b, turns = k % 2, k // 2
        prims = []
        for di, dj, ke, segs in base[b]:
            ri, rj = _rotate(di, dj, turns)
            prims.append((ri, rj, (ke + 2 * turns) % 8, sum(s for _, s in segs), segs))
        out[k] = prims
    return out


def swath(k, segments, samples_per_unit=8):
    """Cells (a, b) of unit size touched by the samples of a primitive from (0, 0, k),
    relative to the start lattice point. Cell (a, b) is the square [a, a + 1) x [b, b + 1)."""
    total = sum(s for _, s in segments)
    n = max(2, int(math.ceil(total * samples_per_unit)))
    cells = set()
    for m in range(n + 1):
        target = total * m / n
        part, acc = [], 0.0
        for kappa, s in segments:
            if acc + s >= target:
                part.append((kappa, target - acc))
                break
            part.append((kappa, s))
            acc += s
        x, y, _ = drive((0.0, 0.0, k * QUARTER), part)
        # Nudge points on cell borders to both sides, so a border counts for both cells.
        for ex in (-1e-9, 1e-9):
            for ey in (-1e-9, 1e-9):
                cells.add((int(math.floor(x + ex)), int(math.floor(y + ey))))
    return frozenset(cells)


class Lattice:
    def __init__(self, width, height, blocked=(), resolution=1.0):
        self.nx, self.ny, self.r = width, height, resolution
        self.blocked = set(blocked)
        self.control = build_control_set()
        self.swaths = {k: [swath(k, p[4]) for p in self.control[k]] for k in range(8)}

    def inside(self, i, j):
        return 0 <= i <= self.nx and 0 <= j <= self.ny

    def free_cells(self, i, j, cells):
        for a, b in cells:
            c = (i + a, j + b)
            if not (0 <= c[0] < self.nx and 0 <= c[1] < self.ny) or c in self.blocked:
                return False
        return True

    def successors(self, state):
        i, j, k = state
        for (di, dj, ke, length, segs), cells in zip(self.control[k], self.swaths[k]):  # @line L5
            if self.inside(i + di, j + dj) and self.free_cells(i, j, cells):  # @line L6
                yield (i + di, j + dj, ke), length * self.r, segs


def lattice_search(lattice, start, goal, use_heuristic=True):
    """A* (or Dijkstra with use_heuristic=False) from lattice state start to goal.
    Returns (cost in meters, list of states, expansions) or None."""
    r = lattice.r

    def h(s):  # @line L2
        return r * math.hypot(s[0] - goal[0], s[1] - goal[1]) if use_heuristic else 0.0

    g = {start: 0.0}  # @line L1
    parent = {start: None}
    heap = [(h(start), 0, start)]  # @line L1
    closed = set()
    counter = 1
    while heap:  # @line L3
        f, _, s = heapq.heappop(heap)  # @line L3
        if s in closed:
            continue
        closed.add(s)
        if s == goal:  # @line L4
            path = []
            while s is not None:
                path.append(s)
                s = parent[s]
            return g[goal], path[::-1], len(closed)
        for t, cost, _ in lattice.successors(s):  # @line L5
            if t in closed:
                continue
            nd = g[s] + cost  # @line L7
            if nd < g.get(t, math.inf):  # @line L7
                g[t] = nd  # @line L7
                parent[t] = s
                heapq.heappush(heap, (nd + h(t), counter, t))  # @line L7
                counter += 1
    return None  # @line L8


def primitive_between(lattice, a, b):
    """The primitive that joins lattice state a to lattice state b."""
    for di, dj, ke, length, segs in lattice.control[a[2]]:
        if (a[0] + di, a[1] + dj, ke) == b:
            return segs
    raise ValueError("no primitive joins these states")
test_state_lattice_planning.py 128 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/state-lattice-planning/. The authors are listed in prov/C6YCHP.jsonl.

import math
import random

from state_lattice_planning import (
    QUARTER,
    R_UNIT,
    Lattice,
    build_control_set,
    drive,
    lattice_search,
    primitive_between,
    wrap,
)


def random_lattice(rng, n=24, density=0.04):
    # A lattice point touches four cells and the turning radius is 2.4 cells, so even a
    # low density of blocked cells removes many states.
    blocked = {(a, b) for a in range(n) for b in range(n) if rng.random() < density}
    return Lattice(n, n, blocked)


def random_state(rng, lat):
    return rng.randint(3, lat.nx - 3), rng.randint(3, lat.ny - 3), rng.randrange(8)


def test_primitives_end_on_lattice_states():
    control = build_control_set()
    for k in range(8):
        assert len(control[k]) == 3
        for di, dj, ke, length, segs in control[k]:
            x, y, th = drive((0.0, 0.0, k * QUARTER), segs)
            assert abs(x - di) < 1e-12 and abs(y - dj) < 1e-12
            assert abs(wrap(th - ke * QUARTER)) < 1e-12
            assert abs(length - sum(s for _, s in segs)) < 1e-15
            assert all(abs(kappa) <= 1.0 / R_UNIT + 1e-15 and s > 0 for kappa, s in segs)


def test_heading_is_continuous_inside_a_primitive():
    # Each primitive is a C1 curve: an arc and a line that meet with the same heading.
    control = build_control_set()
    for k in range(8):
        for _, _, _, _, segs in control[k]:
            q = (0.0, 0.0, k * QUARTER)
            for kappa, s in segs:
                a = drive(q, [(kappa, s - 1e-7)])
                b = drive(q, [(kappa, s)])
                assert math.hypot(b[0] - a[0], b[1] - a[1]) < 1.01e-7
                q = b


def test_a_star_matches_dijkstra():
    rng = random.Random(1)
    solved = 0
    for _ in range(40):
        lat = random_lattice(rng)
        s, t = random_state(rng, lat), random_state(rng, lat)
        a = lattice_search(lat, s, t)
        d = lattice_search(lat, s, t, use_heuristic=False)
        assert (a is None) == (d is None)
        if a is None:
            continue
        solved += 1
        assert abs(a[0] - d[0]) < 1e-9
        assert a[2] <= d[2]
        assert a[0] >= math.hypot(t[0] - s[0], t[1] - s[1]) - 1e-12
    assert solved >= 15


def test_path_is_continuous_and_collision_free():
    rng = random.Random(2)
    for _ in range(30):
        lat = random_lattice(rng)
        s, t = random_state(rng, lat), random_state(rng, lat)
        res = lattice_search(lat, s, t)
        if res is None:
            continue
        cost, states, _ = res
        q = (float(s[0]), float(s[1]), s[2] * QUARTER)
        total = 0.0
        for a, b in zip(states, states[1:]):
            segs = primitive_between(lat, a, b)
            # Dense samples, four times denser than the swath, lie in free cells.
            length = sum(x for _, x in segs)
            n = int(math.ceil(length * 32))
            for m in range(1, n):
                part, acc, target = [], 0.0, length * m / n
                for kappa, x in segs:
                    if acc + x >= target:
                        part.append((kappa, target - acc))
                        break
                    part.append((kappa, x))
                    acc += x
                px, py, _ = drive(q, part)
                cell = (int(math.floor(px)), int(math.floor(py)))
                assert cell not in lat.blocked and 0 <= cell[0] < lat.nx and 0 <= cell[1] < lat.ny
            q = drive(q, segs)
            total += length
            assert abs(q[0] - b[0]) < 1e-9 and abs(q[1] - b[1]) < 1e-9
            assert abs(wrap(q[2] - b[2] * QUARTER)) < 1e-9
        assert abs(total - cost) < 1e-9


def test_rotation_invariance():
    # On an empty lattice, rotating the problem by pi / 2 does not change the cost.
    rng = random.Random(3)
    lat = Lattice(30, 30)
    for _ in range(25):
        di, dj, k1 = rng.randint(-6, 6), rng.randint(-6, 6), rng.randrange(8)
        k0 = rng.randrange(8)
        costs = []
        for turns in range(4):
            a, b = di, dj
            for _ in range(turns):
                a, b = -b, a
            s = (15, 15, (k0 + 2 * turns) % 8)
            t = (15 + a, 15 + b, (k1 + 2 * turns) % 8)
            costs.append(lattice_search(lat, s, t)[0])
        assert max(costs) - min(costs) < 1e-9


def test_unreachable_goal():
    blocked = {(5, b) for b in range(10)}
    lat = Lattice(10, 10, blocked)
    assert lattice_search(lat, (1, 5, 0), (9, 5, 0)) is None

History

Pivtoraiko and Kelly introduced the state lattice and control sets in 2005, for the mobile robots of the Robotics Institute at Carnegie Mellon. Pivtoraiko, Knepper and Kelly gave the full method in 2009, with swaths, heuristics and tests on field robots. Likhachev and Ferguson used lattices with anytime search for Boss, the Carnegie Mellon car that won the DARPA Urban Challenge of 2007, in parking lots. Lattices aligned with the road became a common planner for autonomous cars on highways.

References

  1. Mihail Pivtoraiko, Ross A. Knepper and Alonzo Kelly, Differentially constrained mobile robot motion planning in state lattices, Journal of Field Robotics 26(3), 2009, pages 308 to 333 (the state lattice, control sets of primitives that join lattice states, precomputed swaths for collision checks, and completeness and optimality with respect to the lattice)
  2. Generating near minimal spanning control sets for constrained motion planning in discrete state spaces, the whole paper (the first description of state lattices and of control sets that are small but reach the same states)
  3. Steven M. LaValle, Planning Algorithms, Cambridge University Press, 2006, Section 14.2 (reachability graphs, motion primitives and resolution completeness under differential constraints)

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example