Mobile Robot Full-stack Development In Practice Ⅵ: How Does a Robot Find Its Way? ROS 2 Nav2 Localization and Path Planning

Imagine sending a mobile robot through an office doorway. This time, a traffic cone stands where its saved map shows open floor. How does the robot determine its position, plan a route, and navigate around the unexpected obstacle? In Module 05, we explored how robots build, correct, and reload maps. Now let’s put those maps to work.

In Module 06 of Seeed Studio’s Mobile Robot Full-Stack Development course, you’ll build a 2D occupancy map, relocalize against the saved map with adaptive Monte Carlo localization (AMCL), and see how ROS 2 Nav2 navigation combines global planning with local obstacle avoidance.

You’ll learn how to verify localization, understand why a robot takes a detour, evaluate goal arrival and obstacle clearance, and use rosbag to review your experiments. Follow the linked hands-on guides for installation, launch commands, and experiments you can reproduce.

Mobile robot development roadmap from platform setup and perception through SLAM, navigation and deployment
From mapping and localization to autonomous navigation. Course roadmap

From Simulation to Onboard Robotics with NVIDIA Jetson

The navigation exercises run on a development PC with ROS 2 Humble and Gazebo Fortress. When moving toward physical deployment, the reComputer Robotics J501 family brings NVIDIA Jetson AGX Orin compute together with camera, USB, Ethernet, and CAN interfaces. For example, this combination gives you a starting point for integrating an Ethernet LiDAR, a compatible CAN-connected chassis, and cameras, subject to sensor and driver compatibility.

Seeed Studio reComputer Robotics J5012 edge AI computer with GMSL expansion
reComputer Robotics J5012 with NVIDIA Jetson AGX Orin 64GB and GMSL expansion. Photo: Seeed Studio. Seeed Studio product page

Explore reComputer Robotics J5012 with GMSL for hardware specifications and configuration options.

Open the J501 Robotics Wiki for interfaces, JetPack flashing, and setup.

1. Build a Map, Restart, and Find the Robot Again

Gazebo view of a differential-drive chassis in a multi-room office with walls, shelving and doorways
The simulated office provides doorways, shelves, and corridors for testing a differential-drive robot. Simulation scene

The mapping experiment uses a differential-drive chassis in Ubuntu 22.04, ROS 2 Humble and Gazebo Fortress. A height slice of the simulated 3D LiDAR cloud is projected into a 2D LaserScan. Next, SLAM Toolbox uses those scans and odometry during a survey of the office, building an occupancy grid the robot can later reload. The robot follows predefined survey waypoints. However, walls behind shelves can remain unknown even after a successful run.

The transform chain explains how the robot can move smoothly while correcting a drifting position. The extended Kalman filter (EKF) combines wheel-derived forward velocity, a zero lateral velocity measurement constraint and IMU yaw rate to provide continuous local motion in odom → base_footprint. During mapping, SLAM supplies map → odom. In contrast, after a restart in navigation mode, AMCL supplies that correction against the saved map. For this reason, checking who publishes each transform and whether timestamps agree can explain a bent wall or a jumping pose before you touch any planner settings.

Side-by-side occupancy maps from separate wheel-only and wheel/IMU EKF simulation runs
Wall alignment in separate wheel-only and wheel/IMU EKF simulation runs. Mapping comparison

Separate wheel-only and wheel/IMU EKF simulations illustrate the effect of heading drift. Specifically, in these runs, the 95th-percentile distance from occupied map cells to the known scene surfaces fell from about 0.400 m to 0.075 m. That metric describes how closely the observed occupied cells align with the simulated surfaces. However, to assess map coverage, also inspect which passages and walls the survey actually observed. Mapping evaluation records

Save the Map and Relocalize with AMCL

ROS 2 workflow from mapping and saving to AMCL relocalization and Nav2 activation
Mapping, map saving, relocalization, and navigation are distinct stages, with separate recordings for mapping and navigation. Mapping and relocalization workflow

Save the occupancy image and YAML metadata for Map Server and AMCL, as well as the serialized SLAM pose graph. Then, restart explicitly in navigation mode to test map reuse. Make sure you save the map while SLAM is still running. Give AMCL an approximate starting pose, then let it update against the scans. In this implementation, navigation activates only after fresh observations, bounded position and yaw uncertainty, sufficient scan-to-map agreement, and five consecutive passing AMCL updates. However, in a symmetric corridor, two poses may still look similar to the scanner. For example, use a distinctive doorway or corner in RViz to cross-check the estimate. Map reuse and relocalization guide

2. Global Path Planning and Local Motion Control in Nav2

The global planner determines a route through the office, while the local controller determines how the chassis should move along it. The footprint and inflation layer influence both decisions. For example, a path that looks clear for a point robot may leave too little room for a differential-drive base to turn through a doorway.

ComponentAlgorithms and configurationWhat to inspect
Global plannerA* and Dijkstra in NavFn, plus the native Theta* pluginRoute shape, length and clearance with a fixed map, start and goal
Local controllerDWB samples and scores candidate motions. MPPI evaluates sampled control sequences. RPP tracks a path while regulating speed and checking collisions.Progress at corners, changes in speed, recoveries and final pose
CostmapsA static-map global costmap and a local costmap updated by live LiDARWhether a new obstacle appears where and when you expect it to

Planner and controller exercise

Native Nav2 global routes on a fixed office map beside a separate MPPI box-avoidance trajectory
Left: three global planners tested with the same map, start, and goal. Right: a separate MPPI test using a fixed reference path around an unmapped box. Planning results

To isolate the planner, request a path with ComputePathToPose, and inspect it without moving the robot. For a separate controller test, save a reference route, insert an unmapped box, and invoke FollowPath without global replanning. Instead, use NavigateToPose when you want to observe the complete behavior tree, including replanning and recovery. In one recorded DWB corner-stagnation case, the robot stopped making progress before the cone. Therefore, checking where a run fails tells you whether to inspect path tracking, goal tolerances or the obstacle observations first. Recorded failure cases

3. LiDAR-Based Obstacle Avoidance: Navigating Around an Unmapped Cone

To test obstacle avoidance, we add a cone to the navigation scene after mapping. In the 3D pipeline, the detector transforms and crops the point cloud, downsamples it, removes a fitted ground plane and clusters the remaining points. Next, non-ground points mark occupied space in the local costmap. Meanwhile, the projected scan clears space along observed rays, and inflation adds a clearance cost around obstacles. Finally, the controller receives the costmap, while RViz displays boxes so you can inspect the geometry that produced it. LiDAR and local costmap setup

Initial global route, localization trace near a cone, and one LiDAR detection frame with a 3D cluster box
Estimated robot trajectory, local detour, and a timestamped LiDAR detection frame. Obstacle avoidance results

The green line shows the initial global route, and the blue line shows the estimated trajectory. Meanwhile, the point cloud and bounding boxes capture a detection frame near the detour. Together, these views connect the change in motion with the sensor observations available at that moment. For quantitative clearance or error estimates, use the evaluation record and its frame definitions. In one documented Gazebo navigation run using a measured map, the robot traveled about 13.08 m and finished about 0.17 m from the goal, with a minimum sampled footprint clearance of 0.27 m. However, these results apply only to that simulation, map, and configuration. Clearance between samples and performance on physical hardware require their own checks. Measured-map navigation record

From Static Obstacles to Moving Objects

Importantly, the cone is stationary. For a changing scene, try the optional crossing-box exercise that lets you look for costmap marks lingering after the object has moved. By contrast, predicting a pedestrian’s motion adds another problem: associating detections over time, accounting for the robot’s own motion and projecting where a track might go. Multi-frame tracking, two-second prediction and predictive control are follow-on work. Moving-object exercise and prediction extensions

4. From Single-Robot Navigation to Multi-Robot Coordination

A follower that should stay one meter behind a leader must rotate that offset with the leader’s heading. For example, if the leader is at (2, 3) and faces along the map’s positive Y axis, the follower target is (2, 2). Run the offline exercise with several headings and see how the target moves. Then consider what information you would need to send each robot: a common map reference, separately identifiable TF frames, timestamped poses and a way to handle stale updates. In addition, each robot still needs its own localization and local obstacle handling.

To verify communication between machines, record /robot1/status. First, start the recorder on the same DDS domain and RMW setup before the talker publishes. Next, check that the listener receives a stream, then inspect the bag’s message counts. However, a future formation trial will need namespaced sensor and TF streams, synchronized time and both robots’ trajectories. Online dual-robot formation remains a follow-on lab. Multi-robot communication and formation exercise

Leader and follower target illustrating how a formation offset rotates with leader heading
The follower target is calculated by rotating its relative offset with the leader’s heading. Formation geometry

5. Debug and Reproduce Navigation Experiments with rosbag

Whether you are testing localization or obstacle detection, rosbag helps you inspect what happened and isolate the effect of a processing change. In particular, reusing the same recorded sensor inputs makes offline comparisons more meaningful.

ROS 2 rosbag workflow for recording sensor data, inspecting original outputs and recomputing results from raw inputs
Record before motion, inspect the bag, then replay original outputs or recompute results from recorded raw inputs. Recording and replay workflow

First, start the Gazebo source and check that it publishes simulation time, wheel odometry, IMU, LiDAR and static transforms. Next, start the recorder before the survey or relocalization, and confirm it is receiving the required topics before the robot moves. For a mapping run, save the map while SLAM is still running, then stop the recorder cleanly. Then, after the navigation restart, make a new bag. As a result, this keeps the clock reset and the change in transform publishers out of the mapping recording. For physical hardware, the recording guide also describes a mode using a validated driver stack and system time. ROS 2 rosbag recording and replay guide

Use ros2 bag info on the directory that contains metadata.yaml. In particular, check the duration, counts on the required topics and the presence of static sensor transforms. Keep every data segment together. Also, archive the Git revision, map and parameter files separately, and note the goal and outcome for a navigation run. A screenshot or trajectory JSON can illustrate what happened in a documented run. However, replaying sensor messages requires an actual bag, and historical sensor bags for these figures are not included in the repository.

Use the Playback Mode That Answers Your Question

QuestionMethodEvidence to compare
Why did the robot turn here?Play the original recorded outputs in RViz2, including the map, transforms, trajectory, detections and costmaps.Compare the recorded route and local obstacle observations at the point where the trace diverged.
Would a different detector setting or EKF configuration change the result?Launch offline processing and feed it the original sensor input topics. For mapping from the 3D LiDAR inputs, these are wheel odometry, IMU, the LiDAR cloud and static TF.Check the detections or map recomputed from the same observations. Reset processing state and keep sample counts comparable between runs.
Would a different controller get through the doorway?Run a new closed-loop trial in live Gazebo and start a fresh recording before movement.Compare route completion, recovery behavior, goal error and sampled clearance.

Offline replay runs separately from live drivers. In this setup, the player supplies a single clock for the replay nodes, and the playback lists exclude recorded velocity commands. When recomputing the map from recorded sensor inputs, the new processing nodes own the dynamic TF and map. Therefore, feed them recorded raw inputs and static transforms so the original computed outputs cannot compete with the new publishers. The replay launch starts the processing nodes. Then, pass the bag directory to the ros2 bag play command. Playback modes and topic lists

Build Your Own Navigation Experiment

On a physical robot, verify sensor message formats, frame IDs, mounting calibration, time synchronization, footprint and stopping distances before reusing navigation settings. The simulated LiDAR approximates the MID-360 field of view with regular rays. However, a real Livox stream has different sampling and timing, so check the driver and scan projection before applying the lab’s clearing settings. Start with the J501 hardware and JetPack guide and the simulator-to-hardware notes.

First challenge: build and save a map, relocalize, and send a goal through a doorway. Next, export the reference path and estimated trajectory, then compare them in RViz2. For example, pick a moment near the doorway and describe which observation changed before the robot’s motion did. Finally, share a plot, bag-info summary, map and settings in a GitHub issue so another developer can understand your result. Start the Module 06 navigation lab · Share a result on GitHub

To reproduce the documented experiments, use the scripts under docs/M06-Localization-Navigation-and-Path-Planning/modules/ at the linked Git revision. f476fbf course update

Building your own mobile robot? Star the GitHub repository to follow the project, or fork it to document and share your experiments with the community. Open the course repository on GitHub

Join the Seeed Studio Robotics Community

Working on a mobile robot with ROS 2, Nav2 or Jetson? Come share your navigation demos, discuss mapping and localization challenges, and exchange ideas with fellow developers and makers. Whether you are just getting started or building your own robotics platform, we would love to see what you are working on.

Join us on Discord, Facebook or WhatsApp. Let’s learn, build and share together!

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *

Calendar

December 2026
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031