Skip to the lesson
FixTheRobot Explore Robotics / Localization & SLAM / M4 Graph-Based SLAM / M4-T2

Localization & SLAM · Theory · M4

M4-T2 — Pose Graphs

The robot’s whole history as a graph of poses connected by measured relative motions.

  • Lesson 2 of 8
  • Module 4: Graph-Based SLAM
  • Theory
  • About 8 minutes to read

A pose graph forgets the sensor data and keeps only what they implied: where the robot was at certain moments, and how each place relates to its neighbours in time and space. This lesson defines the graph and the error of an edge, builds one from odometry and a loop closure, and computes the numbers that the optimiser will try to reduce.

Learning objectives

After this lesson, you should be able to:

  • Define the nodes, edges and information matrices of a pose graph.
  • Compute the error eij of an SE(2) edge from the current poses and the measurement.
  • Build a pose graph from odometry and loop-closure measurements and evaluate its total cost.
  • Interpret information matrices: what the numbers say about trust in an edge.

The intuition

Picture a necklace of beads: each bead is a place the robot visited, and each string between neighbours is a measurement that says “from here, the next bead is about this far and in this direction.” Hung from the first bead, the necklace is the dead-reckoned path. Now add one more string between the last bead and the first, because the robot recognised the starting place. The necklace no longer fits: some strings must stretch and others bend. Optimisation is finding the shape of the necklace that strains every string as little as possible, with stiffer strings (more confident measurements) allowed to stretch less.

A pose graph is a network of springs. Each edge is a spring whose rest length is the measurement and whose stiffness is the information matrix.

A pose graph of four posesFour nodes of a square. Grey: the true positions. Orange: positions from integrating odometry with a heading bias, which do not close. Edges link consecutive nodes; a blue loop-closure edge joins the last node to the first, and its error is the gap. x0x1x2x3 Nodes: unknown poses x0 … x3 Orange edges: odometry measurements Blue edge: loop closure (measured: x3 is one stepbefore x0), but the chain puts x3 7 cm away Optimisation moves all four poses so that thetotal weighted error over all four edges is smallest.
Four poses from a square loop. Odometry edges chain them; the closure edge reveals that the chain has drifted.

The mathematics

A pose graph has nodes xi = (x, y, θ), and edges (i, j) each with a measurement zij (the pose of node j as seen from node i) and an information matrix Ωij = Σij⁻¹.

For a candidate set of poses, the predicted relative pose is Xi⁻¹ Xj (the transform from M2-T1). The edge error is the transform that takes the measurement to the prediction, flattened to a 3-vector:

SE(2) edge error
eij=t2v(Zij−1(Xi−1 Xj))e_{ij}=t2v(Z_{ij}^{-1}(X_{i}^{-1}\,X_{j}))
t2v(T)=(Tx, Ty, atan2(T21, T11))t2v(T)=(T_{x},\,T_{y},\,\mathrm{atan}2(T_{21},\,T_{11}))
translation and angle of a 2D transform

In components, with d = tj − ti and R(·) the rotation matrix:

Edge error in components
exy=R(θz)⊤(R(θi)⊤ d−tz)e_{xy}=R(\theta _{z})^{\top}(R(\theta _{i})^{\top}\,d-t_{z})
eθ=wrap⁡(θj−θi−θz)e_{\theta }=\operatorname{wrap}(\theta _{j}-\theta _{i}-\theta _{z})
Xi
the 3×3 matrix of the current pose of node i.
Zij, (tz, θz)
the measured relative pose from i to j.
eij
zero when the poses agree exactly with the measurement. Its units are metres, metres and radians.
Ωij
information matrix (3×3): large entries mean a trusted component. Typical: diag(1/σx², 1/σy², 1/σθ²).

The total cost is

Pose-graph cost
F(x)=∑(i, j) eij⊤ Ωij eijF(x)=\sum _{(i,\,j)}\,e_{ij}^{\top}\,\Omega _{ij}\,e_{ij}

and the maximum-likelihood trajectory minimises it. Each term is a squared Mahalanobis distance: the error measured in units of the measurement’s standard deviation. If the graph is consistent, the minimum F is about the number of constraints minus the number of free variables.

Where edges come from

Kinds of edges in a pose graph
EdgeBetweenMeasurementTypical information
OdometryConsecutive nodesWheel or inertial odometry; or scan-to-scan matchingModerate; grows with distance
Scan-matching constraintConsecutive or nearby nodesRegistration of two scansHigh, if the geometry is good; low in corridors
Loop closureTwo nodes far apart in time, close in spaceRegistration after place recognitionHigh, after verification
Prior (anchor)One node and the worldGPS fix, known start poseSets the gauge; absolute position

Without an anchor, the graph defines poses only up to a rigid motion of the whole thing: every constraint is relative. The optimiser fixes the first node (M4-T4).

A worked example: four poses, a drifting square

The robot drives a 1 m square: four poses, each reached from the previous by “1 m forward, then turn 90°”. The odometry has a heading bias: every step measures a turn of 92° instead of 90°. After the fourth pose it recognises the start and measures its pose relative to the start exactly: the loop-closure edge from x3 to x0, z = (1, 0, 90°).

  1. Initial guess by chaining the odometry. x0 = (0, 0, 0°); x1 = (1, 0, 92°); x2 = (0.965, 0.999, 184°); x3 = (−0.033, 0.930, 276°). The true x3 is (0, 1, 270°): the drift is 7.7 cm and 6°.
  2. Odometry edges are satisfied by construction: their errors are exactly (0, 0, 0), because the chain was built from them.
  3. The loop-closure edge is not. The chain predicts x0 relative to x3 as something that differs from the measured (1, 0, 90°) by e = (−0.065 m, +0.072 m, −0.105 rad): 6° in angle and about 10 cm in position.
  4. Cost. With Ω = diag(100, 100, 400) (σ = 10 cm, σθ = 0.05 rad): F = 100(0.065²) + 100(0.072²) + 400(0.105²) = 0.42 + 0.52 + 4.41 = 5.33. The angle error dominates: 6° is two standard deviations of its edge.
  5. What the optimiser will do. It distributes the 6° of excess turning over all four edges instead of pinning it on the loop-closure edge. After two Gauss-Newton iterations the cost falls to 1.11, and the position error of x3 falls from 7.7 cm to 2.1 cm (M4-T4 shows the iterations).

The remaining cost, 1.11, is not a failure: with four edges (12 constraints) and three free poses (9 unknowns) the expected minimum is about 3; a value near or below that says the odometry’s claimed accuracy was not overconfident.

Engineering implications and limitations

Engineering implications

  • Define the error carefully. The edge error depends on the convention (which frame the measurement is in, which composition order). A wrong convention gives a graph that converges to the wrong shape. Test with a trivial graph whose answer you know, like the square above.
  • Choose nodes sparsely. Between nodes the information of dozens of scans is folded into one edge. Spacing of 0.3–1 m or a few degrees is common in 2D; keyframes for cameras.
  • Set information from evidence. A constant Ω is a crude guess. Scale it by matching quality and by distance; use the Hessian of the matcher when available. Never give a doubtful edge a high information.
  • Keep the graph. Serialise nodes, edges and information (g2o format, TORO, or your own). Datasets such as Intel, MIT Killian Court and Manhattan3500 are standard benchmarks.
  • Mind the angle. The wrapped angle error is non-smooth at ±π; a graph with large angle errors can start in the wrong basin (good initialisation, M4-T4).

Limits

A pose graph throws away the maps: once poses are optimised, the maps (grids, point clouds) must be re-rendered from the stored scans. It treats edges as independent, which is false when two edges come from the same scan, and assumes Gaussian errors, which a bad loop closure violates (M4-T6). It keeps only relative poses; it cannot represent landmarks unless extended into a factor graph (bundle adjustment, M4-T7).

Common misconceptions

“The odometry edges are the ones that are wrong.”

The odometry edges are consistent with the initial guess by construction. The error shows up on the loop-closure edge, and the optimiser distributes it.

“A larger information matrix means a larger error.”

It means the measurement is trusted more. The same error costs more on an edge with higher information.

“The graph has a unique solution.”

Only up to a global rigid transform until an anchor fixes one node.

“A zero cost means a correct map.”

It means the constraints agree with each other. Consistent but wrong constraints (or too few) also give zero.

Engineering takeaways

  1. A pose graph has poses as nodes and measured relative poses with information matrices as edges.
  2. The edge error is t2v(Z⁻¹ Xi⁻¹ Xj): zero when the poses match the measurement.
  3. The cost is the sum of squared Mahalanobis errors; the best trajectory minimises it.
  4. Odometry edges are consistent by construction; loop closures expose the drift.
  5. An anchor is needed because all constraints are relative.

References and further reading

Primary papers and authoritative documentation.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

In the square example the odometry edge errors are exactly zero but the cost is 5.33. Where does the cost come from, and what does that tell you about drift?

Explanation

It comes entirely from the loop-closure edge: the odometry chain was built from the odometry measurements, so it satisfies them by definition, but the chain’s end does not agree with the independent loop-closure measurement. Drift is invisible to odometry edges alone; only an independent constraint exposes it.

Question 2

Two edges have the same error vector (5 cm, 5 cm, 2°). One has information diag(100, 100, 400) and the other diag(400, 400, 1600). Which contributes more to the cost, and what does that mean for the optimised result?

Explanation

The second contributes four times as much. The optimiser will make that edge’s error smaller, at the expense of the other: the trusted measurement is respected more.

Question 3

Why must one node be fixed (or an absolute prior added) before solving?

Explanation

All edges are relative, so moving the entire trajectory rigidly changes no error: the problem has a three-dimensional family of equally good solutions in 2D (a gauge freedom). Fixing a node, or adding an absolute constraint, picks one of them and makes the normal equations non-singular.

What’s next

To minimise the cost we need an optimiser. The next lesson derives it in general: Gauss-Newton and Levenberg-Marquardt for nonlinear least squares.

Practice this lesson

Visualize a Pose Graph

Build a pose graph from odometry and loop-closure measurements and inspect its edges, residuals and information.

Next lesson

M4-T3 — Nonlinear Least Squares

Derive Gauss-Newton and Levenberg-Marquardt for least-squares problems and the role of the Jacobian.

Nothing below is required to finish this lesson. The last 2 entries are lessons of other courses on this site that teach the background or go further.