Skip to the content
FixTheRobot Explore Robotics / UAV / Module 4 / M4-T1

UAV Systems Engineering · Module 4

M4-T1: SLAM fundamentals

To map you need to know where you are, and to know where you are you need a map: SLAM solves both together, and the correlations are the whole story.

  • Lesson 1 of 15
  • SLAM and Autonomous Localization
  • Research-level
  • About 5 minutes to read

Simultaneous localisation and mapping is the framework behind ORB-SLAM3, VINS-Fusion, LIO-SAM and FAST-LIVO2. Its essential insight is statistical: the robot’s error and the map’s errors are correlated, and revisiting a place propagates information through those correlations to the whole trajectory.

Learning objectives

After this lesson, you should be able to:

  • State the SLAM problem and the roles of front-end and back-end.
  • Explain why the robot and landmark errors are correlated and what a loop closure does.
  • Run a one-dimensional EKF-SLAM example and observe the correlations.
  • Distinguish filtering and smoothing formulations, and odometry from SLAM.

Conceptual explanation

SLAM estimates the vehicle trajectory x0:Tx_{0\text{:}T} and a map mm from controls uu and observations zz. The front-end turns raw sensor data into constraints: feature tracks, scan matches, data associations and loop-closure candidates. The back-end estimates the trajectory and map from those constraints, by filtering (EKF, particle) or by smoothing (pose graph, bundle adjustment, factor graph). Odometry is SLAM without loop closure: it accumulates drift; loop closure recognises a revisited place and removes it.

A SLAM systemSensor data enter a front-end that produces tracked features, scan matches and loop candidates as constraints. The back-end optimises trajectory and map. Loop closure feeds back corrections; the output is a trajectory and a map.Sensorscamera, LiDAR, IMUFront-endtracking, associationConstraintsodometry, loopsBack-endfilter / smootherMap + trajectoryoutputa good front-end is half the system; a wrong association is worse than none
Front-end and back-end.
Animation of a vehicle driving around a square. The path estimated from odometry alone slowly drifts, so after one lap it ends well away from where it started. When the vehicle recognises the starting place, a loop-closure constraint is added to the pose graph, and the optimisation pulls the whole trajectory, not only the last pose, back towards the truth, spreading the correction along the loop. The end error before and after is printed.
SLAM in one picture: the front end gives relative motions (odometry) and recognises revisited places; the back end finds the trajectory that best satisfies all constraints. One loop closure corrects the accumulated drift of the entire lap. Positions-only linear pose graph with an illustrative odometry bias (0.054 m per step). (Looping, about 6 seconds; drawn and computed for this course with illustrative values.)

Engineering intuition

Every landmark position is measured relative to where the robot was, so an error in the robot’s pose becomes the same error in the landmarks seen from it: they are correlated. When the robot later sees an old landmark again, the measurement tightens that landmark and, through the correlation, also tightens the robot’s own position and every landmark seen alongside it. That is why one loop closure can correct a long trajectory: information flows along the correlations. It is also why a false loop closure is so destructive: it injects confident wrong information into all those links.

Mathematical formulation

Full SLAM posterior and its factorisation (Markov assumptions):

Full SLAM posterior
p(x0:T,m∣z1:T,u1:T)∝p(x0)∏tp(xt∣xt−1,ut)∏tp(zt∣xt,m)p(\mathbf x_{0:T}, m \mid \mathbf z_{1:T}, \mathbf u_{1:T}) \propto p(\mathbf x_0)\prod_t p(\mathbf x_t \mid \mathbf x_{t-1}, \mathbf u_t)\prod_t p(\mathbf z_t \mid \mathbf x_t, m)

Taking the negative log with Gaussian noise gives the nonlinear least-squares problem solved by the back-end (pose graphs: lesson M4-T12; bundle adjustment: lesson M4-T2):

Least-squares form (smoothing)
x∗,m∗=arg⁡min⁡ ∑t∥xt−f(xt−1,ut)∥Q−12+∑t∥zt−h(xt,m)∥R−12\mathbf x^{*}, m^{*} = \arg\min\ \sum_t\left\lVert\mathbf x_t - f(\mathbf x_{t-1}, \mathbf u_t)\right\rVert^{2}_{\mathbf Q^{-1}} + \sum_t\left\lVert\mathbf z_t - h(\mathbf x_t, m)\right\rVert^{2}_{\mathbf R^{-1}}

EKF-SLAM keeps the joint Gaussian over the current pose and all landmarks, with a covariance that has off-diagonal robot–landmark and landmark–landmark blocks; its cost grows quadratically with the number of landmarks, which is why modern systems use sparse smoothing instead. Marginalising old states creates dense blocks (fill-in), the reason for keyframes and sliding windows.

xtx_{t}
robot pose at time tt.
mm
map (landmarks, voxels or point cloud).
ff, hh
motion and observation models.
QQ, RR
motion and measurement noise covariances.

Architecture and data flow

On a UAV: VIO or LIO gives smooth, high-rate local odometry; a SLAM layer adds loop closure and maintains a globally consistent map, publishing a correction as the transform between the map frame and the odom frame (as in the ROS convention). The controller consumes the odom-frame estimate (smooth, no jumps); the planner and mission layer use the map-frame estimate. Never feed a jumping map-frame pose directly to the controller.

Real-world UAV applications

  • Building maps of unknown environments for later localisation (lesson M4-T13).
  • Drift correction on long GNSS-denied flights.
  • Multi-session mapping and map merging.
  • Obstacle maps for planning.

Implementation example

This runs as shown: a one-dimensional EKF-SLAM with a robot and two landmarks. The robot drives away and back; re-observing the first landmark shrinks the robot’s variance and the correlation between robot and landmark is non-zero throughout.

import numpy as np
rng = np.random.default_rng(0)
true_L = np.array([5.0, 12.0]); q, r = 0.2, 0.15                    # motion noise per step, measurement noise
x = np.array([0.0, 4.0, 11.0]); P = np.diag([0.0, 4.0, 4.0])       # state: robot, landmark 1, landmark 2 (landmarks start badly known)
truth = 0.0; trace = []

def update(x, P, j, z):                                           # measurement z = L_j - robot
    H = np.zeros((1, 3)); H[0, 1 + j] = 1; H[0, 0] = -1
    S = H @ P @ H.T + r ** 2; K = P @ H.T / S
    x = x + (K * (z - (x[1 + j] - x[0]))).ravel(); P = (np.eye(3) - K @ H) @ P @ (np.eye(3) - K @ H).T + K @ np.array([[r ** 2]]) @ K.T
    return x, P

for k in range(120):
    u = 0.15 if k < 60 else -0.15                                   # drive out for 60 steps, then back for 60
    truth += u + q * rng.standard_normal()
    x[0] += u; P[0, 0] += q ** 2                                   # prediction: only the robot moves, landmarks are static
    for j in (0, 1):
        if abs(true_L[j] - truth) < 6.0: x, P = update(x, P, j, true_L[j] - truth + r * rng.standard_normal())
    trace.append((P[0, 0], P[0, 1], P[1, 1]))
rho = P[0, 1] / np.sqrt(P[0, 0] * P[1, 1])
print(f"final robot std {np.sqrt(P[0, 0]):.3f} m, landmark-1 std {np.sqrt(P[1, 1]):.3f} m, robot-landmark correlation {rho:.2f}")
print(f"robot position error {abs(x[0] - truth):.3f} m, landmark errors {np.round(np.abs(x[1:] - true_L), 3)}")
assert abs(rho) > 0.3                                               # robot and landmark errors are correlated
assert np.sqrt(P[1, 1]) < 0.5 * 2.0 and abs(x[0] - truth) < 0.5     # the map and robot both became well known (landmarks started with std 2 m)
assert np.sqrt(trace[-1][0]) < np.sqrt(max(t[0] for t in trace))   # robot uncertainty shrank after revisiting landmark 1
One-dimensional EKF-SLAM: correlations and the effect of revisiting a landmark.

Common engineering mistakes

Treating SLAM as odometry with a map attached

The loop-closure and consistency machinery is what distinguishes it.

Accepting any loop closure

A false positive can ruin the map: verify geometrically.

Feeding map-frame jumps to the controller

Use the continuous odom-frame estimate for control.

Unbounded map growth

Keyframes, culling and voxel filtering are required for a bounded compute budget.

Ignoring dynamics

Moving objects corrupt the map; filter or model them.

Failure modes

Failure modes, symptoms and causes
Failure modeHow it shows upLikely cause
Map distortion after a false loopFolded or doubled structuresPerceptual aliasing, weak verification
Tracking lossSystem reinitialises or runs on IMU aloneFast motion, low texture, dynamic scene
Inconsistent mapDoubled wallsNo loop closure or timing errors
Compute explosionLatency grows over a long flightMap not bounded

Debugging approach

  1. Plot the trajectory before and after loop closure and the covariance trend.
  2. Review every accepted loop with geometric verification statistics.
  3. Check the map for double surfaces.
  4. Log tracking state and compute time.

Practical exercises

  1. Show analytically why re-observing landmark 1 reduces the robot variance in the 1-D example.
  2. Add a false loop (a wrong association) to the example and observe the damage.
  3. Estimate the EKF-SLAM cost for 1000 landmarks and compare with a sparse smoother.
  4. Describe the map-to-odom transform and who publishes it.

Interview questions

Write an answer in your own words, then reveal the model answer. Nothing is sent anywhere.

Question 1

What are the front-end and back-end of a SLAM system?

Model answer

The front-end extracts constraints from sensor data (tracking, matching, loop candidates); the back-end estimates the trajectory and map from those constraints by filtering or optimisation.

Question 2

Why are robot and landmark errors correlated?

Model answer

Landmarks are measured relative to the robot pose, so any error in the pose appears in all landmarks seen from it; revisiting a landmark therefore corrects the pose and the other landmarks through the correlations.

Question 3

What is the difference between VO/VIO and SLAM?

Model answer

Odometry accumulates drift; SLAM adds recognition of revisited places and global optimisation to remove it.

References and further reading

Primary papers, official documentation and standards. Each claim above that is specific to a tool or version points here.

What’s next

Mark this lesson

Saved in this browser and synced to your account when you are signed in.

Next lesson

M4-T2: Visual SLAM

Describe keyframes, map points and bundle adjustment in a visual SLAM system and their cost.