ROS2 and Gazebo: multiple robots

Script for multi robot navigation

For a single robot, we have three scripts in multi_bot_04/multi_bot_04 folder:,,

Additionally, I am going to create a script that runs "patrolling" of the area by two robots; here "patrolling" means robots move between waypoints. Also, as robots run out of charge, they should go to charger.

There are some additional problems our robots will face. First, I am going to place an obstacle (a cube) on their way, so navigation algorithm will have to plot the route around it. Surprisingly, it mostly fails.

Second, robots should not bump into each other. This task, if done properly, is much more advanced then just "take right". No. First of all, what if there is no drivable area on the right? What if robots meet on a narrow bridge? What if they move in the same direction, but one is faster? There are many more "what ifs".

So it either takes a planner server, that makes sure robots NEVER bump into each other by keeping them away from each other, or we need to make robots more intelligent - and I am not going to do it, not in this tutorial.

Instead, I am going to implement the most primitive coordinator code that does the followint:
1. We have two robots.
2. Wait for them to load.
3. We have 4 waypoints.
4. Move robot 1 to waypoint 1 and robot2 to waypoint 3. Robots will move counterclockwise, and never be close to each other.
5. Pass next (2 and 4) waypoint to robots. They will start moving.
6. Wait for both robots to arrive.
Send next waypoints (0 and 3). And so on.
When one of the robots needs to recharge, wait for it to do so.

As you can see, it is rather primitive. I will address a proper robotic flocks in later tutorials, right now the purpose is to show multiple robots navigating, that's all.


In previous scripts, ones for a single robot, this code was part of the main script. However, as we now have two robots, I have to call this code twice, so it was moved to a separate file. By comparing with previous scripts, you can see that most of the work was to a. move code to another file and b. use namespaces.

This file has all navigation logic: calling Nav2 functions, docking to a charger...


This file is almost identical to what we had in earlier tutorials. It uses namespaces thought.


(C), all rights reserved

Please read the disclaimer