Localization & SLAM · Theory · M7
M7-T5 — Mapping vs Localization Mode
Mapping asks “what is the world?”; localization asks only “where am I in it?”. Using the wrong one, or the right one with the wrong start pose, looks like a broken SLAM.
Most robots map once and then work for months in the same building. After the map exists the question changes from building the map to finding the robot in it. ROS 2 offers several ways to answer that: SLAM Toolbox in localization mode on a serialised pose graph, AMCL on a saved occupancy grid, or continued mapping that keeps updating. This lesson compares them and covers the step that most often fails: telling the localiser where to start.
Learning objectives
After this lesson, you should be able to:
- Distinguish mapping, localization and lifelong operation and what each assumes about the map.
- Describe SLAM Toolbox localization mode and AMCL with a saved map, and what each needs as input.
- Explain why the initial pose matters and how to provide it, including global localization.
- Recognise failures: wrong start pose, kidnapped robot, changed environment and mode confusion.
The problem and the intuition
Imagine arriving in a city with a street map. First you have to find where you are on it: look for a street sign and say “I am here”. After that you only need to update the position as you walk. If you point at the wrong place on the map, every later estimate is consistent with that wrong place; you will confidently walk through buildings. A localiser behaves the same way: given a map and a rough start it tracks well; given a start in the wrong room it either converges to a wrong one or never converges.
Mapping mode has the opposite risk. It trusts the data so much that it will happily add a moved chair or a person to the map and warp the graph. Localization mode freezes the map and therefore resists such changes, at the price of failing when the environment is truly different.
Fixed map: stable, cheap, needs a correct start pose. Growing map: adaptive, costlier, can be corrupted by changes. Choose by how much the world changes.
The options and what they need
Problem. Operate a robot in a previously mapped environment, estimating its pose in the map frame continuously, recovering from a wrong start or from being moved, and optionally adapting to slow change.
Assumptions. The saved map matches the environment well enough; the lidar sees enough fixed structure; odometry is available for prediction; the operator or a global search can provide an approximate start.
| Option | Map it needs | How it localises | Strengths | Limits |
|---|---|---|---|---|
SLAM Toolbox, mode: localization | Serialised pose graph (.posegraph + .data) | Scan matching against stored scans; adds temporary nodes without changing the saved map | Same code and frames as mapping; accurate in structured maps | Needs the graph, not only the image; initial pose required; heavier than AMCL on large maps |
| AMCL (Nav2) | Occupancy grid from map_server (.yaml + image) | Particle filter (M3-T3, Monte Carlo localisation) with a likelihood-field laser model | Light, standard in Nav2, has a global-localization service | Needs a good occupancy map; poor in long symmetric corridors; particle count sets cost |
| Continued / lifelong mapping | Serialised pose graph loaded in mapping mode | Adds new scans, loop closes, may remove old ones | Adapts to change | Can accumulate errors or corrupt the map; needs monitoring |
Initial pose
A localiser needs a prior belief about where the robot is. Ways to give it:
- RViz “2D Pose Estimate” publishes a
geometry_msgs/PoseWithCovarianceStampedon/initialpose. Click on the map where the robot is and drag to give the heading. AMCL (and SLAM Toolbox in localization mode) use it. - Parameters. AMCL’s
set_initial_posewithinitial_pose.x/y/yaw; SLAM Toolbox’smap_start_poseormap_start_at_dockwhen loading a serialised graph. - Global localization. AMCL provides a service
/reinitialize_global_localizationthat spreads particles over the whole free space; the robot must then move so that observations disambiguate the hypotheses. It works in asymmetric maps and can fail in symmetric ones.
How the particle filter uses the start
AMCL keeps N particles (hypotheses of the pose); the number adapts between min_particles (500 by default) and max_particles (2000) using KLD sampling (Fox, 2001). Given an initial pose with covariance, particles are drawn from that Gaussian. If the true pose is outside the cloud, none of the particles matches the scan well and the filter either converges to a lookalike or spreads out. Motion updates are applied only after the robot has moved update_min_d (0.25 m) or rotated update_min_a (0.2 rad), so a stationary robot does not correct itself.
- /initialpose
- topic on which a start pose with covariance is given to the localiser.
- global localization
- initialising the particle cloud over the entire free space.
- kidnapped robot
- the robot is moved without the localiser being told.
- KLD sampling
- adapting the number of particles to the spread of the posterior.
Failure modes
| Failure | Symptom | Cause / remedy |
|---|---|---|
| Wrong or missing initial pose | Scan does not overlap the walls in RViz; particles in two clouds | Set the pose properly; use global localization and move |
| Kidnapped robot | Confident but wrong pose after carrying the robot | Detect with low scan match scores; trigger global localization; add recovery behaviour |
| Map changed (moved furniture) | Slow degradation, drifting pose near the changed area | Update the map, or use a long-term mapping mode with care |
| Wrong mode | Map grows over the saved one; or nothing updates | Check mode and which node is running |
| Map–odom frame offset | Pose correct only near the origin | Check map_frame, odom_frame and the saved map’s origin |
| Symmetric environment | Pose flips between two hypotheses | Add asymmetric landmarks, other sensors or a better prior |
A worked example: a start pose that is too far off
- The setup. A warehouse map has two identical aisles 6 m apart. The robot is in aisle A at (12.0, 2.0). The operator clicks on the map at aisle B, (12.0, 8.0) with a covariance of 0.25 m² (σ = 0.5 m) on x and y.
- Why it fails. AMCL draws particles from N((12, 8), 0.25). The nearest to the true pose is six standard deviations away: the probability of any particle within 1 m of the truth is about 10−9. The scan taken in aisle A fits aisle B’s walls just as well (the aisles are identical), so the particles converge on aisle B with a high score. The pose is wrong and confident.
- How it would be detected. The robot drives out of the aisle and sees the end wall at a distance that does not match the map: scan match scores drop and the particle cloud spreads. In the meantime Nav2 plans from the wrong position.
- The remedies. (1) Put the initial pose in the right aisle. (2) If unknown, call
/reinitialize_global_localizationand drive; the end of the aisle breaks the symmetry. (3) Give each aisle a distinctive feature (a pillar, a sign) so that the map is not self-similar. - Cost of the particle filter. With 2 000 particles and a scan of 360 beams, each update evaluates 2 000 × 360 = 720 000 likelihood lookups; at a 10 Hz scan rate and an update every 0.25 m of travel (0.5 m/s gives 2 updates per second) that is 1.44 million lookups per second, trivial for a CPU. Reducing the beam count with
max_beams: 60cuts it by six.
Engineering implications and limitations
Engineering implications
- Make the start pose explicit in the workflow. A docking station as the known start, or a launch parameter for the usual pose, removes the most common failure.
- Monitor localisation health. Watch the AMCL covariance and the scan match score; trigger recovery when they degrade.
- Decide how you handle change. A fixed map plus periodic re-mapping is simpler and safer than lifelong mapping for most deployments.
- Keep the map and the robot’s frames consistent. The map origin and the
mapframe must be the same in the saved file and the running system (M7-T6). - Test the kidnapped case. Lift and move the robot in a test and confirm that your system notices and recovers.
- Version your maps. Store them with the date, the parameter file used and a screenshot.
Limits
A fixed-map localiser has no good answer for an environment that has changed a lot; it gives either a poor pose or none. Particle filters need enough particles to cover the uncertainty, and in large symmetric buildings global localization is slow or ambiguous. Both systems are 2D and assume the lidar sees the same structure that was mapped, which fails if the lidar is mounted at a different height or the room is rearranged.
Common misconceptions
“Localization mode builds a bit of the map as it goes.”
In localization mode the saved map is fixed; the localiser adds temporary data only for tracking.
“The localiser will find the robot from anywhere.”
Only global localization attempts that, and it can fail in symmetric maps. A normal start needs an approximately correct prior.
“A high confidence means a correct pose.”
A wrong start in a self-similar map gives a confident wrong pose.
“AMCL and SLAM Toolbox localization use the same map file.”
AMCL uses the occupancy grid; SLAM Toolbox localization uses the serialised pose graph.
Engineering takeaways
- Mapping estimates pose and map together; localization estimates pose in a fixed map.
- SLAM Toolbox localization needs the serialised graph; AMCL needs the occupancy grid and a yaml file.
- The initial pose must be within the localiser’s capture range, or global localization must be used.
- The kidnapped robot, a changed map and symmetric environments are the standard failure cases.
- Monitor localisation health and plan the recovery path in advance.
References and further reading
Primary papers and authoritative documentation.
- Thrun, S., Burgard, W. and Fox, D. (2005). Probabilistic Robotics. MIT Press (Monte Carlo localisation, Chapter 8).
- Fox, D. (2001). KLD-sampling: Adaptive particle filters. Advances in Neural Information Processing Systems 14.
- Macenski, S. and Jambrecic, I. (2021). SLAM Toolbox: SLAM for the dynamic world. Journal of Open Source Software 6(61), 2783.
- Open Navigation. Nav2 documentation: AMCL configuration and Setting the initial pose. docs.nav2.org.
- Dellaert, F., Fox, D., Burgard, W. and Thrun, S. (1999). Monte Carlo localization for mobile robots. IEEE ICRA.
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
You click the initial pose in the wrong aisle of a symmetric warehouse. Why might AMCL show high confidence?
Explanation
The scan fits the identical wrong aisle as well as the right one, so the particles near the clicked pose score high and the filter converges there. High confidence measures agreement with the map at that place, not correctness; the symmetry hides the error until the robot sees something unique.
Question 2
What do you need to save from a mapping session if you want to use both Nav2 AMCL and SLAM Toolbox localization later?
Explanation
Both the occupancy grid (image plus yaml, for AMCL and map_server) and the serialised pose graph (.posegraph and .data, for SLAM Toolbox localization).
Question 3
Why does AMCL not correct a stationary robot’s pose even if the scan disagrees with the map?
Explanation
It performs a filter update only after the robot has moved by update_min_d or rotated by update_min_a; a stationary robot never triggers one, so the particles are unchanged until it moves.
What’s next
Both the picture of a map and the graph behind it can be saved. The next lesson explains what each file contains, how to save and reload them, and the mistakes that make a saved map unusable.
Related content
Nothing below is required to finish this lesson. The last entry is a lesson of other courses on this site that teach the background or go further.
- BeforeM7-T4: SLAM Toolbox and Mapping Workflows
Configure SLAM Toolbox for online and offline mapping and read its key parameters.
- LabM7-L4: Configure Mapping and Localization
Build a map, save it and serialised graph, then relaunch in localization mode with a correct initial pose.
- ProbabilityMonte Carlo Localization in Practice
What AMCL does and what its parameters mean.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.