Module 9/10 · Weeks 13–14 · 14 h

Mapping and path planning

UAT 458 Indoor Autonomous UAS and Navigation Technology

About 90 minDraft, awaiting reviewLast updated 1 October 2026

Lesson

By the end of this module you will be able to

  1. Build an occupancy grid map with log-odds updates and estimate the memory needed for a 3D map
  2. Explain pose-graph SLAM and compute how loop closure distributes error by least squares
  3. Inflate obstacles by the drone size, plan a path with A* and compare it with Dijkstra
  4. Choose between grid-based and sampling-based planning according to the size of the problem

Prerequisites: Module 8 LiDAR and sensor fusion · UAT 308 Automation and Robotics Technology (RRT and path tracking)

Why this matters

Hall 3 changes its layout for every event. Monday night there may be 200 booths; Friday night a concert stage and 12 m lighting towers. The drone needs an up-to-date map for two reasons. First, LiDAR can localize without drift only if it has a map to match against (module 8). Second, planning a route from the dock to an inspection point requires knowing which space is free, which is occupied, and which has never been seen.

This module covers two topics from the course description: mapping with occupancy grids and SLAM, and path planning on that map. Reactive avoidance during flight and its autopilot settings are covered in modules 1–5 of this course.

Occupancy grid maps

An occupancy grid map divides space into equal cells, each holding the probability that it is occupied. The idea comes from Elfes (1989). Its strength is that data from several sensors and many scans merge easily into one map. When a LiDAR beam strikes a point, the cell containing that point gains evidence of a hit; cells the beam passed through before reaching it gain evidence of being free.

Combining evidence directly as probabilities takes several multiplications and divisions, so Thrun and colleagues (2005) store log-odds instead, and each update becomes a simple addition. An unknown cell has (). Every hit adds , every pass-through adds the negative , and the value is usually clamped so that a cell can still change when a booth is removed.

The key point is that a never-observed cell must be “unknown”, not “free”. If the planner treats unknown cells as free, it will route the drone behind a booth the LiDAR has never seen.

Example 1 One cell at a booth edge, and the map size of the whole hall

A cell at the edge of a booth is scanned five times: two hits, then on the third scan the beam passes through because the drone was tilted, then two more hits. The sensor model uses and , clamped at ±3.5 (assumed). Then compute the size of a 3D map of the 120 × 72 × 18 m hall.

import math
# Example 1: log-odds update of one occupancy-grid cell, and map size of the hall
L_OCC, L_FREE = 0.85, -0.40          # log-odds added for a hit and for a pass-through (assumed sensor model)
L_MAX = 3.5                           # clamp so a cell can still change when a booth is removed

def prob(l):
    return 1 - 1 / (1 + math.exp(l))

l = 0.0                               # unknown: p = 0.5
for scan, hit in enumerate(["hit", "hit", "free", "hit", "hit"], start=1):
    l = max(-L_MAX, min(L_MAX, l + (L_OCC if hit == "hit" else L_FREE)))
    print(f"scan {scan}: {hit:4s} -> log-odds {l:+.2f}, p(occupied) {prob(l):.2f}")

W, D, Hh = 120, 72, 18                # hall size (m)
for cell in (0.2, 0.1):
    n = round(W / cell) * round(D / cell) * round(Hh / cell)
    print(f"3D cells of {cell} m: {n / 1e6:.2f} million, {n / 1e6:.1f} MB at 1 byte per cell")
scan 1: hit  -> log-odds +0.85, p(occupied) 0.70
scan 2: hit  -> log-odds +1.70, p(occupied) 0.85
scan 3: free -> log-odds +1.30, p(occupied) 0.79
scan 4: hit  -> log-odds +2.15, p(occupied) 0.90
scan 5: hit  -> log-odds +3.00, p(occupied) 0.95
3D cells of 0.2 m: 19.44 million, 19.4 MB at 1 byte per cell
3D cells of 0.1 m: 155.52 million, 155.5 MB at 1 byte per cell

After five scans the cell has an occupancy probability of 0.95; the one free reading lowers it only slightly because evidence accumulates over many scans. For memory, 0.2 m cells over the whole hall give 19.44 million cells, about 19.4 MB. Halving the cell to 0.1 m multiplies the count by eight to 155.5 MB, too heavy for a small onboard computer. Real systems therefore store only observed cells in a tree structure, or use fine cells only near the trusses where the drone must fly close.

Bar chart of the probability that a cell is occupied. It starts at 0.50 in grey, rises to 0.70 in yellow after hit 1, 0.85 after hit 2, falls to 0.79 after free scan 3, then 0.90 after hit 4 and 0.95 after hit 5 in pink
Figure 1 Occupancy probability of one cell after log-odds updates

SLAM and loop closure

The occupancy grid can only be built if the drone’s position at each scan is known, yet that position comes from matching against the map. This chicken-and-egg problem is solved by SLAM (simultaneous localization and mapping), which estimates position and map together. Cadena and colleagues (2016) describe modern SLAM systems as a front-end, which processes sensor data and finds relationships between poses, and a back-end, which solves an optimisation problem.

Graph-based SLAM stores each drone pose as a node and each measured relationship, such as “moved 60.2 m” from odometry, as an edge with its own uncertainty. The back-end adjusts every node to disagree with the edges as little as possible, in the form (Grisetti and colleagues, 2010). Loop closure happens when the system recognises a place it has visited before and adds an edge stating that two nodes are the same place; the error accumulated around the loop is then spread back over every node. Cartographer performs this loop closure in real time with 2D LiDAR (Hess and colleagues, 2016).

Example 2 Closing the inspection loop with the dock tag

The drone flies a rectangular inspection lap around the hall. Odometry measures four legs of (60.2, 0), (0, 36.3), (−59.6, 0.4) and (−0.3, −35.9) m. Back at the dock the camera sees the AprilTag, so the system knows it has truly returned to the start. The team weights the loop-closure edge ten times more than odometry (assumed; positions only, heading ignored).

# Example 2: closing the loop of an inspection lap with a small pose graph (positions only)
import numpy as np
odo = np.array([[60.2, 0.0], [0.0, 36.3], [-59.6, 0.4], [-0.3, -35.9]])   # measured legs (m)
loop = np.array([0.0, 0.0])            # tag at the dock: last pose is the start pose
poses = np.vstack([[0, 0], np.cumsum(odo, axis=0)])
print("end point from odometry only:", np.round(poses[-1], 2), "m")

# unknowns: poses 1..4 (x, y); pose 0 is fixed at the origin
A = np.zeros((10, 8)); b = np.zeros(10); w = np.ones(10)
for i in range(4):                     # odometry edges p[i+1] - p[i] = odo[i]
    for k in range(2):
        r = 2 * i + k
        if i + 1 <= 4: A[r, 2 * i + k] = 1
        if i >= 1: A[r, 2 * (i - 1) + k] = -1
        b[r] = odo[i, k]
for k in range(2):                     # loop-closure edge p[4] - p[0] = 0, trusted 10 times more
    A[8 + k, 6 + k] = 1; b[8 + k] = loop[k]; w[8 + k] = 10
sol = np.linalg.lstsq(A * w[:, None], b * w, rcond=None)[0].reshape(4, 2)
for i, p in enumerate(sol, start=1):
    print(f"pose {i}: odometry {np.round(poses[i], 2)} -> optimised {np.round(p, 2)}")
end point from odometry only: [0.3 0.8] m
pose 1: odometry [60.2  0. ] -> optimised [60.13 -0.2 ]
pose 2: odometry [60.2 36.3] -> optimised [60.05 35.9 ]
pose 3: odometry [ 0.6 36.7] -> optimised [ 0.38 36.1 ]
pose 4: odometry [0.3 0.8] -> optimised [0. 0.]

Odometry alone puts the final point at (0.3, 0.8) m instead of the start, 0.85 m off. After the least-squares solution, node 4 returns to (0, 0) and the error is spread to the other nodes; for example node 3 moves from (0.6, 36.7) to (0.38, 36.1) m. Real systems use each edge’s uncertainty and include heading, but the principle is the same. One caution: a false loop closure is worse than none. If the system believes it sees the dock tag but it is actually a duplicate tag with the same ID elsewhere, the whole map is warped. Every tag ID in the hall must therefore be unique.

Two rectangles. The dashed pink odometry-only path ends short of the dock at the lower left; the solid green path after loop closure returns exactly to the dock. Points p1, p2 and p3 mark the other three corners
Figure 2 Pose graph of one inspection lap before and after loop closure

Planners usually treat the drone as a point, so before searching, obstacles must be inflated by the drone’s radius including propellers plus a safety margin. If the drone’s centre stays outside the inflated region, its propellers stay clear of the real obstacle. When converting to a number of cells, always round up; rounding down leaves less margin than required.

Each free cell then becomes a graph node, joined to its neighbours by edges costing the distance between them. Dijkstra’s algorithm expands nodes in order of the accumulated cost from the start, ; it always finds the shortest path but searches in every direction. A*, by Hart and colleagues (1968), expands the node with the lowest , where estimates the remaining cost to the goal. If never overestimates (it is admissible), as with straight-line distance to the goal, A* still returns the shortest path while searching less.

Example 3 A path between booths on the night before opening

The planning layer uses 1 m cells over a 60 × 36 m area containing four booths and stages. The drone’s radius including propellers is 0.45 m and the margin 0.5 m. It flies from the dock at cell (2, 18) to a sprinkler-pipe inspection point at cell (57, 24), moving in eight directions without cutting obstacle corners (assumed).

# Example 3: A* on an occupancy grid of the hall with inflated booths
import heapq
cell = 1.0                                     # 1 m cells for the planning layer
grid = np.zeros((36, 60), dtype=bool)          # rows = y, cols = x; a 60 x 36 m part of the hall
for x0, y0, w_, h_ in [(10, 5, 8, 20), (25, 10, 10, 26), (42, 0, 6, 22), (42, 26, 6, 10)]:
    grid[y0:y0 + h_, x0:x0 + w_] = True       # booths and stages (m)
r_infl = math.ceil((0.45 + 0.5) / cell)       # drone radius 0.45 m + margin 0.5 m -> whole cells
inflated = grid.copy()
for y, x in zip(*np.nonzero(grid)):
    inflated[max(0, y - r_infl):y + r_infl + 1, max(0, x - r_infl):x + r_infl + 1] = True

def astar(occ, start, goal, use_h=True):
    moves = [(1, 0, 1), (-1, 0, 1), (0, 1, 1), (0, -1, 1), (1, 1, 1.414), (1, -1, 1.414), (-1, 1, 1.414), (-1, -1, 1.414)]
    h = (lambda p: math.dist(p, goal)) if use_h else (lambda p: 0.0)
    g = {start: 0.0}; came = {}; openq = [(h(start), start)]; done = set()
    while openq:
        _, cur = heapq.heappop(openq)
        if cur == goal:
            path = [cur]
            while cur in came: cur = came[cur]; path.append(cur)
            return path[::-1], g[goal], len(done)
        if cur in done: continue
        done.add(cur)
        for dx, dy, c in moves:
            nx, ny = cur[0] + dx, cur[1] + dy
            if 0 <= nx < occ.shape[1] and 0 <= ny < occ.shape[0] and not occ[ny, nx]:
                if dx and dy and (occ[cur[1], nx] or occ[ny, cur[0]]): continue   # no corner cutting
                ng = g[cur] + c
                if ng < g.get((nx, ny), math.inf):
                    g[(nx, ny)] = ng; came[(nx, ny)] = cur
                    heapq.heappush(openq, (ng + h((nx, ny)), (nx, ny)))
    return None, math.inf, len(done)

start, goal = (2, 18), (57, 24)
print(f"inflation {r_infl} cells; free cells {np.sum(~inflated)} of {inflated.size}")
for name, flag in (("A*", True), ("Dijkstra", False)):
    path, cost, n_exp = astar(inflated, start, goal, flag)
    print(f"{name:8s}: path {cost:.1f} m, {len(path)} cells, expanded {n_exp} nodes")
inflation 1 cells; free cells 1344 of 2160
A*      : path 81.6 m, 76 cells, expanded 896 nodes
Dijkstra: path 81.6 m, 76 cells, expanded 1061 nodes

Radius plus margin is 0.95 m, rounded up to 1 cell, leaving 1344 of 2160 cells free. A* and Dijkstra both find the same 81.6 m path because both find the shortest path, but A* expands 896 nodes against Dijkstra’s 1061. The difference is modest here because long booths block the straight line to the goal, limiting what the heuristic can do; in a more open hall or a large 3D map the difference becomes much larger. The resulting path turns at cell corners, so real systems smooth it before handing it to the path follower.

A 60 by 36 cell grid map. Four dark orange booths are surrounded by pale yellow inflated bands. Pale blue cells are those A* expanded. A pink path runs from the start on the left, below the first booth, below the second, then up through the gap between the two right-hand booths to the goal
Figure 3 A* path between booths on a 1 m grid map

Sampling-based planning

When planning in 3D across the whole hall with fine cells, the tens of millions of cells from Example 1 make A* too slow. Sampling-based planning avoids building the whole graph. The RRT (rapidly-exploring random tree) of LaValle (1998) samples a random point, finds the nearest node in the tree, and extends one step towards the sample; if that step is collision-free it joins the tree, and a fraction of samples are the goal itself to pull the tree towards it. RRT finds a flyable path quickly, but the first path is usually winding and changes with the random seed. Implementing RRT and tracking the path with pure pursuit were covered in UAT 308.

The rule of thumb for Hall 3 is to use A* on a 2D map at a fixed flight height for transits between inspection points, which gives a guaranteed shortest path and the same result every time, and to use sampling-based planning in 3D only where the drone must thread through trusses or complex lighting rigs, testing with several random seeds.

Module lab

Lab: build an occupancy grid and plan paths in the lab room

  1. Scan the lab room with a 2D LiDAR from 5 known positions and build a 0.1 m occupancy grid with log-odds updates as in Example 1, showing unknown cells in a different colour from free cells
  2. Carry the sensor once around the room with an AprilTag at the start point, log odometry, and close the loop with the code in Example 2; report the error before and after closure
  3. Inflate obstacles by your group’s drone radius plus margin, then plan with A* and Dijkstra between three pairs of points; compare path lengths and nodes expanded
  4. Move one table, scan again, and check how many scans the map needs to adapt and whether the path changes

Common mistakes

Watch out

  • Treating never-observed cells as free and routing behind booths that have not been seen
  • Not clamping log-odds, so a cell that once held a booth never becomes free after the booth is removed
  • Choosing cells finer than needed across a whole 3D map, running out of memory and time
  • Accepting a loop closure matched to the wrong place, or using duplicate tag IDs in one building
  • Rounding the inflation cell count down, leaving less margin than required
  • Trusting a single RRT run when the path changes with the random seed

Summary

  • An occupancy grid stores occupancy probability, updated by adding log-odds, and must keep unknown cells separate from free ones
  • 3D map size grows with the cube of resolution; halving the cell size takes eight times the memory
  • Graph SLAM adjusts every pose to agree with the edges; loop closure spreads accumulated error back around the loop, but a false closure warps the map
  • Inflate obstacles by radius plus margin and round up. A* uses with a non-overestimating and finds the shortest path with less search than Dijkstra
  • Sampling-based planning suits large 3D spaces, but paths must be shortened and tested with several seeds

Check your understanding

  1. A cell at = 0.5 receives one hit with = 0.85. What is the new probability?
  2. How many cells does a 40 × 30 × 10 m 3D map with 0.25 m cells have?
  3. A 200 m inspection lap returns to the start 1.0 m off. What percentage of distance is that?
  4. A drone radius of 0.35 m, a 0.3 m margin and 0.2 m cells: how many cells of inflation?
  5. Why does A* with straight-line distance as still find the shortest path?
Answers
  1. cells
  2. , rounded up to 4 cells
  3. Straight-line distance is never longer than the true remaining path, so the heuristic never overestimates and A* never skips a better path

Key formulas

Log-odds of a grid cell
Back to probability
Least-squares pose graph
A* evaluation function

Key references

  1. Elfes, A. (1989). Using occupancy grids for mobile robot perception and navigation. Computer, 22(6), 46–57. link
  2. Thrun, S., Burgard, W., & Fox, D. (2005). Probabilistic robotics. MIT Press. link
  3. Cadena, C., Carlone, L., Carrillo, H., Latif, Y., Scaramuzza, D., Neira, J., Reid, I., & Leonard, J. J. (2016). Past, present, and future of simultaneous localization and mapping: Toward the robust-perception age. IEEE Transactions on Robotics, 32(6), 1309–1332. link
  4. Grisetti, G., Kümmerle, R., Stachniss, C., & Burgard, W. (2010). A tutorial on graph-based SLAM. IEEE Intelligent Transportation Systems Magazine, 2(4), 31–43. link
  5. Hess, W., Kohler, D., Rapp, H., & Andor, D. (2016). Real-time loop closure in 2D LIDAR SLAM. In 2016 IEEE International Conference on Robotics and Automation (ICRA) (pp. 1271–1278). IEEE. https://doi.org/10.1109/ICRA.2016.7487258 link
  6. Hart, P. E., Nilsson, N. J., & Raphael, B. (1968). A formal basis for the heuristic determination of minimum cost paths. IEEE Transactions on Systems Science and Cybernetics, 4(2), 100–107. link
  7. LaValle, S. M. (1998). Rapidly-exploring random trees: A new tool for path planning (TR 98-11). Iowa State University. 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 · Delivery, indoor operations and warehousing · Automation, robotics and swarms