SLAM mapping
UAT 458 Indoor Autonomous UAS and Navigation Technology
Lesson
By the end of this module you will be able to
- Explain the front-end, back-end and loop closure of SLAM at the level an operator needs, and distinguish mapping mode from localization mode
- Plan a mapping flight so that drift before loop closure stays within tolerance and the flight fits the battery
- Estimate the size of 2D and 3D maps by resolution
- Tie a SLAM map to the building plan with control points and judge quality from the remaining residuals
Why this matters
Module 2 made LiDAR SLAM the main indoor position source, but a SLAM position is only as good as the map it uses. A map that is warped, stretched or not tied to the building plan puts the inspection points that engineers marked on the drawings in the wrong place: the drone photographs a beam 1 m away from the one wanted, or a virtual fence believed to be 2 m from a wall is really half a metre away.
This module treats mapping as an operations task: planning the mapping flight, checking quality, tying the map to the building plan and keeping it up to date as the building changes. SLAM algorithms in depth and methods for evaluating trajectory accuracy are in modules 6–10 of this course; the basics of VIO and visual SLAM are in UAT 307.
SLAM from the operator’s side
SLAM (simultaneous localization and mapping) builds a map and locates the vehicle in it at the same time, like a person entering an unfamiliar building who notes every turn and every pillar on the way, then uses those notes to say where they are. The survey by Cadena et al. (2016) divides modern SLAM systems into two parts.
- The front-end processes sensor data, matches images or scan points over time, and detects whether a place has been seen before.
- The back-end solves an optimisation that adjusts every pose along the path to agree with the data as well as possible. Grisetti et al. (2010) describe the graph form, which stores each pose of the vehicle as a node and each measured relationship as an edge.
Along the way, small errors at every step accumulate into drift until the system recognises that it is back somewhere it has been, called loop closure. It adds an edge saying the two nodes are the same place and spreads the error accumulated around the loop back over all the nodes. Hess et al. (2016) describe the real-time loop closure for 2D LiDAR behind Cartographer, the system the ArduPilot documentation uses as its example of sending a SLAM position to the autopilot through ROS (ArduPilot Dev Team, n.d.). ORB-SLAM3 is an open library for visual SLAM with monocular, stereo and visual-inertial set-ups (Campos et al., 2021).
The operator must remember that a false loop closure is worse than none. If the system mistakes two similar-looking places for the same one, such as the walkway beside filter bed 2 and beside filter bed 6, the whole map is pulled out of shape. Buildings with many repeated sections, like the filter hall, must therefore always be checked visually and against control points.
Map once, localize on every flight
Most SLAM systems run in two modes.
- Mapping mode builds a new map, the first time and whenever the building changes significantly.
- Localization-only mode loads a checked map and no longer changes it; it is used on mission flights.
Separating the modes means every flight uses the same checked map, so inspection points and virtual fences defined on it stay in the same place on every flight. The first mapping run should not be an autonomous flight, because there is no map to trust yet. The safe choices are to carry the sensors, or the drone with propellers removed, along the walkways, or to have the pilot fly slowly in a mode that does not need position, such as AltHold, for areas that cannot be walked, such as over the filter beds.
General rules for mapping runs: move slowly and steadily, turn slowly so the LiDAR and cameras see every wall and pillar, close the area to people and vehicles because anything moving gets baked into the map as a ghost, and return often to places already passed so the system can close loops.
Planning the mapping flight
If drift is a fraction of distance travelled and the tolerance before loop closure is , the distance between revisits must not exceed . In a long building the simplest approach is to split it into sections and close a loop in each. For a building of length and width split into sections, one loop is long.
Example 1 How many mapping loops for the filter hall?
This system’s LiDAR odometry drifts by about 0.5% of distance, drift before loop closure may not exceed 0.5 m, the mapping speed is 1.0 m/s, and one battery gives 12 minutes after the reserve (all assumed).
import math
import numpy as np
# mapping flight plan: how big may each loop be so drift stays inside tolerance before the loop closes?
r, TOL, V, BUDGET = 0.005, 0.5, 1.0, 12.0 # drift 0.5% of distance, tolerance (m), speed (m/s), usable minutes (assumed)
W, L = 30.0, 96.0 # filter hall width and length (m)
print(f"longest distance between revisits: {TOL / r:.0f} m")
for k in (1, 2, 4, 8): # split the hall into k sections, one closed loop each
loop = 2 * (L / k + W)
total = k * loop
print(f"{k} loop(s) of {loop:5.1f} m: drift before closure {r * loop:.2f} m "
f"{'ok' if r * loop <= TOL else 'too much'}, total {total:.0f} m, {total / V / 60:.1f} min "
f"{'fits' if total / V / 60 <= BUDGET else 'exceeds'} {BUDGET:.0f} min")
longest distance between revisits: 100 m
1 loop(s) of 252.0 m: drift before closure 1.26 m too much, total 252 m, 4.2 min fits 12 min
2 loop(s) of 156.0 m: drift before closure 0.78 m too much, total 312 m, 5.2 min fits 12 min
4 loop(s) of 108.0 m: drift before closure 0.54 m too much, total 432 m, 7.2 min fits 12 min
8 loop(s) of 84.0 m: drift before closure 0.42 m ok, total 672 m, 11.2 min fits 12 min
A single loop around the hall is quickest but drifts 1.26 m before closing. Only eight loops of 84 m stay within the tolerance (0.42 m), at the cost of 672 m in total and 11.2 minutes, almost a whole battery. The team therefore decides to map the walkways on foot and fly only over the filter beds, which cuts the actual flight time a great deal. Note that the 30 m width means no loop can be shorter than 60 m however many sections are used, so further improvement must come from lowering the rate , for example by moving more slowly or turning less, not just from more sections.
Map size and resolution
Navigation maps are often an occupancy grid, which divides space into equal cells each holding the probability that the cell is occupied (Elfes, 1989). Resolution is the cell size: small cells reveal narrow gaps but cost memory and computation, and in 3D halving the cell size multiplies the cell count by eight.
Example 2 How many cells does the filter hall map have?
# map size: 2D occupancy grid and 3D voxel map of the filter hall
H = 12.0
for res in (0.10, 0.05):
cells2d = round(L / res) * round(W / res)
vox = cells2d * round(H / res)
print(f"resolution {res:.2f} m: 2D {cells2d:,} cells, 3D {vox:,} voxels")
resolution 0.10 m: 2D 288,000 cells, 3D 34,560,000 voxels
resolution 0.05 m: 2D 1,152,000 cells, 3D 276,480,000 voxels
A 2D map at 5 cm has just over a million cells, easy for the companion computer. A 3D map at 5 cm has nearly 280 million cells; stored as a full array it is too heavy for the computer on the drone. Real systems therefore store 3D maps economically, for example only the cells actually observed, or use 10 cm for navigation and keep the fine data for analysis on the ground.
Tying the map to the building plan
A SLAM map has its origin where mapping started and its axes along the direction the drone faced at the start. Engineers, however, define inspection points on the building drawings, such as “the beam on grid line C between columns 4 and 5”. We therefore need a rigid transformation, a rotation and translation that carry map points onto the plan, , using control points whose plan coordinates are known and which can be found in the map, such as column corners. Umeyama’s (1991) least-squares method uses the singular value decomposition (SVD) and can estimate rotation, translation and scale. For LiDAR, which measures true distances, scale should not be adjusted; a fitted scale far from 1 signals a problem with the map.
Example 3 Tying the map with five column corners
The team picks the four corner columns of the hall and one central column, reads their coordinates from the drawings, and reads the same points from the SLAM map. Its criterion is that every remaining residual be at most 10 cm (assumed values).
# tie the SLAM map to the building plan with surveyed column corners (2D, rigid, Umeyama 1991)
plan = np.array([[0.0, 0.0], [96.0, 0.0], [96.0, 30.0], [0.0, 30.0], [48.0, 15.0]]) # plan coordinates (m)
slam = np.array([[-5.23, -2.27], [90.63, -5.23], [91.65, 24.78], [-4.35, 27.71], [43.17, 11.27]]) # same points in the SLAM map (assumed)
def fit_rigid(src, dst):
ms, md = src.mean(0), dst.mean(0)
U, S, Vt = np.linalg.svd((dst - md).T @ (src - ms))
D = np.diag([1, np.sign(np.linalg.det(U @ Vt))])
R = U @ D @ Vt
return R, md - R @ ms
R, t = fit_rigid(slam, plan)
res = np.linalg.norm((slam @ R.T + t) - plan, axis=1)
print(f"rotation {math.degrees(math.atan2(R[1, 0], R[0, 0])):.2f} deg, translation ({t[0]:.2f}, {t[1]:.2f}) m")
print("residuals (cm):", " ".join(f"{100 * x:.1f}" for x in res))
print(f"RMS {100 * np.sqrt((res ** 2).mean()):.1f} cm, max {100 * res.max():.1f} cm")
rotation 1.76 deg, translation (5.19, 2.42) m
residuals (cm): 3.5 6.1 3.9 1.5 1.8
RMS 3.8 cm, max 6.1 cm
The map is rotated 1.76° from the plan and shifted by about 5.2 m and 2.4 m, which simply reflects where mapping started and is not an error. Quality is shown by the residuals: all are below 10 cm (the largest, 6.1 cm, at corner P2), so the tie passes. If one point were far off, first check whether the wrong column was read before concluding the map is warped.
Control points should be spread over the whole area, not on one straight line, because rotation about that line cannot then be found accurately. There should also be more than the minimum number (two in 2D) so that residuals remain to check: with only two points the fit is always perfect and nothing warns you that a point was misread.
Looking after the map
Buildings change all the time: scaffolding goes up, pallets of spares move, the crane parks somewhere else, a usually open door is shut. A map that no longer matches the building degrades localization gradually without a clear warning. The team should define:
- A map version number, recorded in the flight log of every flight
- Remapping triggers, such as structural changes, walk-test or control-point residuals beyond tolerance, or frequent low match-quality reports from the system
- A pre-mission check: place the drone on a reference mark on the floor and confirm the reported position matches that mark’s coordinates within tolerance
Module lab
Lab: build a map, tie it to the plan and check its quality
- Using recorded 2D LiDAR data (or a Gazebo scene), build a map of the building surveyed in module 1 with the SLAM software chosen by the group, such as Cartographer.
- Plan the mapping loops with the code in Example 1 from the real building size, and decide which parts to walk and which must be flown.
- Carry the sensors along the plan with the area closed to passers-by, noting the times and places where you return to known points.
- Choose at least five control points spread over the building, measure their coordinates from the drawings or with a laser distance meter, tie the map with the code in Example 3 and report the residuals.
- Deliberately misidentify one control point and see how the residuals change.
- Write a map maintenance procedure for the building: version numbers, remapping triggers and the pre-mission check.
Common mistakes
Watch out
- Mapping with an autonomous flight the first time, with no map to trust yet.
- Flying one big loop, so drift before closure exceeds the tolerance.
- Letting people and vehicles pass during mapping, baking moving objects into the map.
- Not checking loop closures in buildings with repeated sections; a false closure warps the whole map.
- Using too few control points, or points in a line, leaving no residuals to check.
- Not recording the map version, so nobody knows which map a problem flight used.
Summary
- SLAM has a front-end that matches data and detects revisits, and a back-end that adjusts the whole graph. Loop closure reduces drift; a false closure warps the map.
- Build the map once in mapping mode and check it, then fly missions in localization-only mode on that map.
- The distance between revisits must not exceed ; keep mapping loops short enough and within the battery.
- 3D maps grow with the cube of resolution; choose the resolution the task needs.
- Tie the map to the plan with from well-spread control points and judge it by the residuals.
Check your understanding
- Drift is 0.5% of distance and the tolerance before loop closure is 0.3 m. How often must you return to a known place?
- Splitting the filter hall into loops of m with 0.5% drift, what is the drift before closure, and does it pass a 0.5 m tolerance?
- How many cells does a 3D map of the 48 × 20 m, 10 m high pump hall have at 0.10 m resolution?
- Why should control points not lie on one straight line, and why should there be more than two?
- Why is a false loop closure worse than none?
Answers
- m
- The loop is 92 m, so drift is m, which passes the 0.5 m tolerance
- cells
- Points in a line leave the rotation poorly determined, and with only two points the transformation always fits exactly, leaving no residuals to reveal a misread point
- Without closure the error stays confined to the drift of one stretch, but a false closure forces two different places to be the same, and the back-end warps the whole map to comply, spreading the error everywhere
Key formulas
| Longest distance between revisits | |
| Mapping loop length with the hall split into k sections | |
| Rigid transformation from map to building plan |
Key references
- 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
- 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
- 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
- Campos, C., Elvira, R., Gómez Rodríguez, J. J., Montiel, J. M. M., & Tardós, J. D. (2021). ORB-SLAM3: An accurate open-source library for visual, visual–inertial, and multimap SLAM. IEEE Transactions on Robotics, 37(6), 1874–1890. link
- ArduPilot Dev Team. Cartographer SLAM for non-GPS navigation. ArduPilot developer documentation. link
- Umeyama, S. (1991). Least-squares estimation of transformation parameters between two point patterns. IEEE Transactions on Pattern Analysis and Machine Intelligence, 13(4), 376–380. link
- Elfes, A. (1989). Using occupancy grids for mobile robot perception and navigation. Computer, 22(6), 46–57. link
Further reading
Study the assigned knowledge units in advance, review media and take the module quiz
SLAM และการนำทางในพื้นที่ไม่มี GNSS
How to know an estimated position is reliable
In class / field
Lab or field practice from worksheets with a safety checklist
Learning evidence: Checked worksheets and quiz results