ROS2 and Gazebo: multiple robots

Compiling and Running

We use different mode values (simple - slam - map) and accordingly, different RViz config files. Alltogether, it creates kind of a mess, but the logic is simple.

                    # Terminal 1
                    # echo $ROS_DISTRO
                    # galactic
                    #
                    # source /opt/ros/galactic/setup.bash
                    #
                    $ cd ~/SnowCron/ros_projects/harsh
                    $ colcon build --packages-select multi_bot_03
                    $ source install/setup.bash
                    
                    # To run a single robot without SLAM or Map (robot name in code is set to ""):
                    $ ros2 launch multi_bot_03 multi_simulation_launch.py world:=src/worlds/maze_with_charger.sdf map:=src/maps/map.yaml keepout_mask:=src/maps/keepout_mask.yaml rviz_config_file:=src/multi_bot_03/rviz/simple_single.rviz mode:=simple

                    # To run a single robot simulation (SLAM) (robot name set to ""):
                    $ ros2 launch multi_bot_03 multi_simulation_launch.py world:=src/worlds/maze_with_charger.sdf map:=src/maps/map.yaml keepout_mask:=src/maps/keepout_mask.yaml rviz_config_file:=src/multi_bot_03/rviz/slam_single.rviz mode:=slam

                    # To run a single robot simulation (Map) (robot name set to ""):
                    $ ros2 launch multi_bot_03 multi_simulation_launch.py world:=src/worlds/maze_with_charger.sdf map:=src/maps/map.yaml keepout_mask:=src/maps/keepout_mask.yaml rviz_config_file:=src/multi_bot_03/rviz/map_single.rviz mode:=map

                    # To run a multi robot without SLAM or Map (robot name set to robot1, robot2):
                    $ ros2 launch multi_bot_03 multi_simulation_launch.py world:=src/worlds/maze_with_charger.sdf map:=src/maps/map.yaml keepout_mask:=src/maps/keepout_mask.yaml rviz_config_file:=src/multi_bot_03/rviz/simple_multi.rviz mode:=simple

                    # !!! Not implemented!!! Will do in future tutorials.
                    # To run a multi robot simulation (SLAM):
                    $ ros2 launch multi_bot_03 multi_simulation_launch.py world:=src/worlds/maze_with_charger.sdf map:='src/maps/map.yaml' keepout_mask:=src/maps/keepout_mask.yaml rviz_config_file:=src/multi_bot_03/rviz/slam_multi.rviz mode:=slam

                    # !!! Not implemented!!! Will do in future tutorials.                    
                    # To run a multi robot simulation (Map):
                    $ ros2 launch multi_bot_03 multi_simulation_launch.py world:=src/worlds/maze_with_charger.sdf map:='src/maps/map.yaml' keepout_mask:=src/maps/keepout_mask.yaml rviz_config_file:=src/multi_bot_03/rviz/map_multi.rviz mode:=map


                    # Terminal 2
                    $ cd ~/SnowCron/ros_projects/harsh
                    $ source install/setup.bash

                    # To move a single robot
                    # Single command:
                    $ ros2 topic pub cmd_vel geometry_msgs/msg/Twist '{linear: {x: 0.5, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}'
                    # Teleop tool:
                    $ ros2 run teleop_twist_keyboard teleop_twist_keyboard
                    
                    # to move the robot in multi-robot launch, use one of the following
                    # (you can use them simultaneously):
                    $ ros2 topic pub /robot1/cmd_vel geometry_msgs/msg/Twist '{linear: {x: 0.5, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}'
                    $ ros2 topic pub /robot2/cmd_vel geometry_msgs/msg/Twist '{linear: {x: 0.5, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}'
                    $ ros2 run teleop_twist_keyboard teleop_twist_keyboard --remap cmd_vel:=/robot1/cmd_vel
                    $ ros2 run teleop_twist_keyboard teleop_twist_keyboard --remap cmd_vel:=/robot2/cmd_vel
                    
                

(C) snowcron.com, all rights reserved

Please read the disclaimer