ROS 2 Lyrical Luth · Lesson 68 of 86
Multi-robot navigation
Namespaces, per-robot Nav2 instances, shared maps and avoiding conflicts.
Estimated time · 60–90 min
Learning goals
What you will understand
- Explain multi-robot navigation in your own words
- Use it in a small robotics example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
To run several robots, give each one a namespace (/robot1, /robot2) so topics, nodes and TF do not clash, and start a full Nav2 instance per robot with its own parameters. All can share one map. TF frames need a prefix or per-namespace tf topics (remapped /tf to tf) so each robot has its own tree.
Nav2 itself does not coordinate robots: two robots may plan through each other. Add a traffic layer on top (reservation, priority or a fleet manager, see Phase 7) and keep the robots on different DDS domains or with unique namespaces so discovery stays manageable.
Guided lesson
Work through these steps
- 1.
Source the ROS 2 Lyrical environment in a fresh terminal.
- 2.
Read the multi-robot navigation example and identify what each line does.
- 3.
Build only the affected package, source the workspace overlay, and run the example.
- 4.
Inspect the result from a second terminal with the ros2 CLI or RViz2 and compare it with the expected result.
Worked example
Read it before you run it
from launch.actions import GroupAction, IncludeLaunchDescription
# Actions for grouping and including launch files.
from launch_ros.actions import PushRosNamespace
# Puts everything in a group under a namespace.
def robot(ns):
# A helper that builds the launch actions for one robot.
return GroupAction([PushRosNamespace(ns), IncludeLaunchDescription(nav2_launch)])
# Start Nav2 inside the namespace.
ld = LaunchDescription([robot('robot1'), robot('robot2')])
# Two robots in one launch.What the example is doing
- 1.The ros2 commands query the running graph; they do not prove that a node's internal behavior is correct.
- 2.Build from the workspace root, then source install/setup.bash so the shell can discover the new package.
- 3.Use a second sourced terminal to inspect nodes and interfaces while the example runs.
Watch it run · Mobile robot
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Multi-robot navigation. Expected result: ros2 node list shows /robot1/... and /robot2/... nodes
Practice code
Now type it yourself
Copy the starter into your ROS 2 package, replace every TODO, then build with colcon build and run it from a sourced terminal.
# launch/two_robots.launch.py (fragment)
from launch.actions import GroupAction
from launch_ros.actions import PushRosNamespace
def robot(ns, nav2_launch):
# TODO: group a PushRosNamespace(ns) with the included Nav2 launch descriptionExpected output
ros2 node list shows /robot1/... and /robot2/... nodesStuck? Show the full solution (try it yourself first)
# launch/two_robots.launch.py (fragment)
from launch.actions import GroupAction
from launch_ros.actions import PushRosNamespace
def robot(ns, nav2_launch):
return GroupAction([PushRosNamespace(ns), nav2_launch])Expected result
How you know it worked
- ROS_DISTRO is lyrical in every terminal used for the exercise.
- The complete package from the exercise builds and the expected graph entity appears in a second terminal.
Practical exercise
Apply the lesson
Launch two simulated robots with their own namespaces and Nav2 instances, send each to a goal, and note what happens when their paths cross in a corridor.
Before you continue
- ROS_DISTRO reports lyrical in every terminal you used
- The example builds and runs without errors
- You checked the result with a ros2 command, RViz2 or a test, not just by reading the code
If something goes wrong
Source /opt/ros/lyrical/setup.bash, build from the workspace root, then source install/setup.bash in that terminal.
Confirm both terminals use Lyrical, the same ROS_DOMAIN_ID, and compatible network/discovery settings.