Chapter 08 · Map, localize, navigate, and recover with Nav2
Today in the field story
One problem, then the next
Lay transparent policy sheets over the Medicine-Cart Route Trial’s saved map: static structure, live obstacle observations, inflation, unknown-space handling, measured footprint, and staff-only keepout. Test a doorway with body and uncertainty margins rather than shrinking the cart to force a route. Make global and local layers explain every occupied, cleared, inflated, and prohibited cell.
- Why now
A planner cannot propose safe travel until body geometry and operating policy are encoded in its world representation.
- Ignore today
Ignore exhaustive costmap tuning; qualify one measured footprint and small scenario set.
- Unlocks next
A collision-aware graph for the A* preview and Nav2 planner.
Understand
Build the physical picture first
A costmap is transparent safety paper laid over the floor plan: one sheet holds the known building, another adds what sensors see now, and another spreads warning space around danger.
A saved occupancy map mostly represents lasting structure such as walls. A Nav2 costmap is an active decision surface used by planners and controllers. Its cells hold travel cost: free cells are cheap, lethal obstacles are forbidden, and intermediate values discourage travel near danger. The global costmap usually covers the larger planning area in the map frame. The local costmap is commonly a rolling window in odom that moves with the robot and reacts quickly to nearby sensor observations.
Costmaps are layered so each source has a named job. A static layer brings in the saved map. An obstacle layer marks and ray-traces two-dimensional lidar observations; a voxel layer can handle three-dimensional observations before projecting relevant occupancy. An inflation layer raises cost around lethal obstacles. Marking says where a sensor saw an obstacle, while clearing uses observed free rays to remove old marks. Incorrect sensor frames, height limits, ranges, timestamps, or clearing rules can create ghost obstacles or erase real ones.
The robot is not a point. Its footprint is the polygon occupied by the base, and footprint padding adds a small explicit margin. Nav2 can also use a radius for a circular robot, but a measured polygon better represents many rectangular AMRs. Inflation is related but different: it creates a graded cost field around obstacles so paths prefer clearance. Changing the footprint because the robot picked up a pallet changes collision geometry; changing inflation changes route preference. Neither value should be copied from a tutorial without measuring the robot and testing representative gaps.
Keepout zones express a product rule such as “never enter the forklift charging area” even when the floor is physically empty. Nav2 applies them as costmap filters from a mask and filter information, separate from ordinary layers. A speed filter can similarly request lower speed in an area. Use the policy in both the global and local decision surfaces where appropriate; otherwise a global path may avoid a zone while local control still cuts across it, or the local costmap may reject a path the global planner keeps producing.
Costmap tuning is a chain of evidence. Confirm the correct global frame and robot frame, map resolution and origin, footprint dimensions, sensor topics and frames, observation persistence, marking and clearing, update and publish rates, transform tolerance, unknown-space policy, and CPU load. Then test a doorway, a temporary obstacle, a removed obstacle, an unknown boundary, and a keepout area. A colorful RViz display is useful only when each color can be traced to its layer and physical meaning.
Words you need
Name each idea precisely
- Global costmap
The larger travel-cost grid used mainly for route planning, usually referenced to the map frame.
Physical example:It contains the warehouse walls, mapped aisles, and a keepout mask around the forklift zone.
- Local costmap
A smaller, frequently updated grid around the robot used mainly for local control and nearby obstacles.
Physical example:A trolley rolled into the next two metres appears in the robot-centred rolling window.
- Footprint
The polygon or radius that represents the robot's occupied floor area for collision checks.
Physical example:A 0.70 m by 0.50 m rectangular base needs more side clearance than its centre point suggests.
- Inflation
A graded region of higher cost around obstacles that encourages safer clearance.
Physical example:Cells beside a wall become increasingly expensive as the path gets closer to the wall.
- Keepout filter
A spatial policy mask that marks places the navigation system must not use even if sensors report free floor.
Physical example:An AMR may not cross a human-only packing zone painted on the facility plan.
Math, one line at a time
Work through today’s relationship
Prerequisite rescue · optionalOccupancy probability and path cost
Navigation converts uncertain map cells into a collision-aware route.
- p(occupied)
- belief that a map cell contains an obstacleUnit: probability from 0 to 1
- g(n)
- cost already travelled to cell nUnit: cost or metres
- h(n)
- estimated remaining costUnit: same as g
For an A* node, suppose g = 4 m and admissible h = 3 m.
Total priority f = g + h = 7 m.
The planner compares f values, but the final path must also clear the inflated robot footprint.
It resembles shortest-path routing in a network, but each node represents physical space and the robot has width.
What is f when g = 2.5 m and h = 1.5 m?
f = 4.0 m.
Required center clearance is
Passing between two obstacles therefore needs at least
which exceeds the doorway.
Decide whether a doorway has physical clearance
A doorway is 1.00 m wide. The rectangular robot is 0.55 m wide, and engineering requires 0.05 m footprint padding on each side.
Write all widths in metres and distinguish total width from one-sided margin.
Add both padding sides to the robot width: effective width = 0.55 + 2(0.05) = 0.65 m.
Subtract from the doorway width: total remaining gap = 1.00 - 0.65 = 0.35 m.
For a perfectly centred robot, divide that gap between two sides: 0.35 / 2 = 0.175 m per side.
Compare 0.175 m with localization error, map error, door-frame irregularity, and the intended inflation-cost policy; geometric fit alone is not acceptance.
Test the actual footprint polygon in the costmap and inspect the footprint collision result rather than shrinking inflation until a route appears.
The padded body has 0.175 m nominal clearance per side when perfectly centred, but the passage is accepted only if measured uncertainty and control performance fit inside that remaining margin.
Footprint math answers whether the body can fit; inflation and operating rules decide whether the planner should prefer or reject that risk.
Physical examples
Where this appears in real life
Coin robot through a paper doorway
A centre-line drawn through a paper doorway looks clear, but a coin placed on the line overlaps both doorposts.
The footprint converts a point path into an occupied area; padding and localization uncertainty reduce the usable gap further.
Three sheets of tracing paper
One transparent sheet shows walls, one shows a movable chair, and one shades warning bands around every obstacle.
The final cost is a layered combination. Removing the chair should clear only its live observation, not erase the wall sheet.
Hands-on exercise
Make the idea observable
Use the saved Week 8 map, Gazebo robot, lidar, RViz, and one version-controlled Nav2 parameter file. Do not change several parameters at once.
Measure the simulated chassis corners relative to
base_link, declare the footprint polygon in metres, and overlay the published footprint on the rendered robot.Display global and local costmaps separately in RViz, then identify the frame, size, resolution, update rate, and every enabled layer for each.
Place a simulated box in the lidar field and trace the scan point into the obstacle layer; remove the box and verify ray-tracing clears the temporary mark within the declared policy.
Drive toward a measured doorway and compare centre-line planning with full-footprint collision checking; record minimum nominal clearance and any oscillation.
Add a keepout mask over a physically open patch and verify both global route choice and local controller behavior respect it.
Plant one bad configuration—wrong sensor frame, oversized footprint, disabled clearing, or stale observation—and save before/after costmap evidence that explains the symptom.
Every occupied, inflated, unknown, and policy cell should have a traceable source; the costmaps should update fast enough for the controller without ghosting or excessive CPU load.
The robot footprint matches the model, a temporary obstacle marks and clears predictably, the measured doorway decision is explainable, and a keepout zone is enforced by both planning layers.
Build today
Launch one pinned Gazebo, SLAM Toolbox, AMCL, and Nav2 stack; survive cancellation, obstruction, stale localization, and bounded recovery; then freeze the world, seed, bag, map, graph, configuration, transform snapshot, scenarios, and raw results.
Evidence to save
DONE when “Layered costmaps, robot footprint, inflation, and keepout zones” runs from one documented command and the nominal plus boundary outputs are attached.
Common mistakes
Catch the wrong mental model
Reducing the robot footprint until a desired path becomes valid.
Keep the footprint tied to measured occupied geometry; investigate map, localization, controller, and route constraints without lying about body size.
Treating inflation radius as extra physical robot width.
Use footprint and padding for occupied geometry, then use inflation to shape cost and preferred clearance around lethal cells.
Enabling keepout policy only on one costmap and assuming all navigation layers will obey it.
Apply and test policy on the relevant global and local costmaps so planning and immediate control do not disagree.
Calling a cell stale or wrong without identifying which layer produced it.
Inspect layers separately and correlate cell changes with sensor data, transforms, marking, clearing, persistence, and filter masks.
Job connection
How this becomes employable evidence
Commission an AMR in aisles narrower than the lab, measure its real loaded footprint, tune sensor clearing and inflation, and prove that mapped walls, temporary stock, and customer keepout zones behave differently.
Relevant target roles
- Robotics Application / ROS 2 Integration Engineer
- Robotics Software Engineer — ROS 2 / AMR
- Robotics Deployment, Integration & Validation Engineer
Chapter 08 interview drill
Interview questions: Layered costmaps, robot footprint, inflation, and keepout zones
Practise a 60–90 second answer: define the idea, connect it to a physical robot, state assumptions, frames, and units when relevant, then finish with the failure signal or evidence you would inspect.
Primary interview scenario
A Nav2 robot refuses a doorway that appears wide enough, while another configuration clips a corner. Explain how you would separate footprint, padding, inflation, map resolution, localization error, and obstacle-layer evidence.
Answer shape: clarify the situation → trace the physical and software path → test the most likely boundaries → name the evidence that would confirm the result.
Technical follow-up questions
Q1Why are global and local costmaps usually different?
The global map supports longer route planning in a stable frame, while the local rolling map updates nearby obstacles quickly for control.
Q2What is the difference between footprint padding and inflation?
Padding enlarges the geometry used for collision checking; inflation creates graded travel cost around obstacles to influence route clearance.
Q3Why can a keepout zone be necessary on physically empty floor?
Navigation must obey operational rules such as human-only or hazardous areas, not merely avoid objects that sensors can see.