RobotGuide

Tools & simulation · topic G4 · 40 hours

Nav2 & the mobile-robot stack

The standard stack for AGVs, inspection robots, and delivery robots — and the layer with the largest gap between «works in sim, crashes on site». Parameters here are not tuned by feel; they are computed from physical quantities.

Engineering stage · Intermediate
Algorithm · Hands-on System software · Proficient Embedded & controls · Aware

Tools
Tools

What to learn

  • Six core nodes: bt_navigator, planner_server, controller_server, behavior_server, smoother_server, velocity_smoother
  • Layered costmap: static, obstacle, voxel, inflation; the inflation radius and cost decay decide whether the robot dares to hug walls
  • Planners: NavFn (Dijkstra/A*), Smac 2D/Planner (hybrid), Hybrid-A* (car-like, with a minimum turning radius), Theta* (any-angle)
  • Controllers: DWB (default, sampling), TEB (timed elastic band, strong in narrow lanes but parameter-sensitive), MPPI (GPU sampling, good in dynamic environments), RPP (pure pursuit, simple and stable)
  • Behavior tree: the XML structure of NavigateToPose, recovery behaviors (clear costmaps, spin in place, back up), custom BT nodes
  • Localization: AMCL (particle count, update thresholds, initial pose) and slam_toolbox (online mapping); the trade between map resolution and memory
  • Where the field gap comes from: wheel diameter/track calibration error, wheel slip, reflective floors, dynamic pedestrians, and the local planner's acceleration limits

The lesson · plain words

Nav2 is the «full navigation suite» for mobile robots: global planning + local avoidance + recovery behaviors + costmaps. The key to understanding it is one picture: a wavefront spreading over a costmap.

Global planning: finding a path on the costmap

The global costmap = a grid (one cost per cell): obstacle cells infinite, surroundings inflated (safety distance), unknown space penalized. A*/Dijkstra spread backward from the goal over this map — watch the figure: shading is literally «how many steps from the goal», and the robot descends the gradient to reach it.

The inflation radius is not decoration: it quantifies «how close counts as dangerous». Too large and it cannot fit through doors, too small and it clips corners — field tuning is mostly tuning this.

Interactive figure · drag it and see

What this figure shows: a costmap where the wavefront spreads outward from the goal cell — shading encodes steps to the goal — with the cost built from obstacle inflation plus an unknown-space penalty, a local planner dodging in real time, and a re-spread button. Takeaway: the robot descends the gradient to the goal; the inflation radius is your safety policy quantified.

Global vs local: a clear division of labor

Global planning (NavFn/Smac): low rate (1 Hz), whole map, answers «which route». Local planning (DWB/TEB/RPP): high rate (20 Hz), local window, answers «how to steer this second» + real-time avoidance. When the local planner fails, recovery behaviors fire (spin, clear the costmap, back up).

This architecture is exactly isomorphic to B10's layered thinking: a coarse model owns the big picture, fine control owns execution. Learn one, know two.

Localization and map: Nav2's upstream

Nav2 only handles «from A to B on a map». The map (SLAM output, C4) and localization (AMCL/cartographer localization mode) are upstream. Localization jitter makes the costmap «jitter» — when a wall-hugging robot suddenly detours, a localization jump is usually the culprit.

Field debugging order: localization drifted → map stale → inflation radius wrong → local planner parameters. 90% of «navigation acting up» dies in the first two steps.

How deep to go

Configure a complete Nav2 parameter set (global/local planners, costmap layers, recovery behaviors); explain what each costmap layer (static/obstacle/inflation) does; close the navigation loop in Gazebo. With that you can independently deliver indoor mobile-robot navigation.

Three questions — do you really get it?

1. What does the costmap's inflation layer do?

  • AMakes the map look nice
  • BSpreads obstacles into a cost slope by safety distance so planning actively keeps away
  • CCompresses the map
Show answer

B. The inflation slope makes A* naturally avoid obstacles. The radius is your safety policy quantified.

2. What is the local planner's (DWB/TEB) responsibility?

  • AThe globally optimal path
  • BHigh-rate real-time avoidance and execution inside a local window
  • CBuilding the map
Show answer

B. Global owns the route, local owns every second underfoot. Recovery behaviors are the safety net.

3. The robot «suddenly detours while hugging a wall» — what do you check first?

  • AThe local planner
  • BWhether localization is jumping / the map is stale
  • CCPU usage
Show answer

B. Localization jitter → costmap jitter → path jitter. Upstream causes are more common than downstream ones.

Keep going deeper

Links without a marker stay on this site; the rest point to the Chinese edition until its translation batch lands.

How it fails in the field

  • Setting the inflation radius directly to the robot radius: corridor width is exactly half gone and global planning has no solution — you must add margin for tracking error and localization drift
  • Tuning only on an empty map, then hitting the first box on site: the voxel layer is off, obstacles only get marked and never cleared (marking and clearing not configured)
  • A beautiful global path, but the robot swings left and right: the controller's max_vel and acceleration do not match what the base can actually do

You have learned enough when

Run Nav2 point-to-point navigation in Gazebo; drop a box mid-route and it goes around; unplug the lidar and recovery behavior fires instead of freezing in place. You can explain what inflation_radius vs robot_radius each govern and why they differ by a safety margin.

The Chinese edition carries the full topic page for Nav2 & the mobile-robot stack, including the complete outline, depth requirements per career track, and further derivations: robotguide.dev/k/G4/.