In this video, we are going to see how can we launch multiple robots in a single Gazebo simulation.
We will be introduced to the concept of namespace and tf_prefix, which are essential to make sure that the robots will be able to work correctly. We will create a series of launch files that will enable us to easily add robots into our Gazebo simulation.
This is a video based on the following post on ROS Answers: https://answers.ros.org/question/41433/multiple-robots-simulation-and-navigation/
NOTICE: most of the code would be the same in the ROS Answer, however, we’ll make some change to make sure it is compatible with ROS kinetic. Please use the code below.
Step 1. Create a project in ROS Development Studio(ROSDS)
ROSDS helps you follow our tutorial in a fast pace without dealing without setting up an environment locally. If you haven’t had an account yet, you can create a free account here.
Step 2. Create a package
We’ll create a package to put our source code for the project with the following command
cd ~/catkin_ws/src catkin_create_pkg multi_robot rospy gazebo_ros
Then we’ll create a folder called launch under the package directory and create 3 launch files that we need.
<launch> <arg name="robot_name"/> <arg name="init_pose"/> <node name="spawn_minibot_model" pkg="gazebo_ros" type="spawn_model" args="$(arg init_pose) -urdf -param /robot_description -model $(arg robot_name)" respawn="false" output="screen" /> <node pkg="robot_state_publisher" type="state_publisher" name="robot_state_publisher" output="screen"/> <!-- The odometry estimator, throttling, fake laser etc. go here --> <!-- All the stuff as from usual robot launch file --> </launch>
This launch file will launch one robot in the simulation.
<launch> <!-- No namespace here as we will share this description. Access with slash at the beginning --> <param name="robot_description" command="$(find xacro)/xacro.py $(find turtlebot_description)/robots/kobuki_hexagons_asus_xtion_pro.urdf.xacro" /> <!-- BEGIN ROBOT 1--> <group ns="robot1"> <param name="tf_prefix" value="robot1_tf" /> <include file="$(find multi_robot)/launch/one_robot.launch" > <arg name="init_pose" value="-x 1 -y 1 -z 0" /> <arg name="robot_name" value="Robot1" /> </include> </group> <!-- BEGIN ROBOT 2--> <group ns="robot2"> <param name="tf_prefix" value="robot2_tf" /> <include file="$(find multi_robot)/launch/one_robot.launch" > <arg name="init_pose" value="-x -1 -y 1 -z 0" /> <arg name="robot_name" value="Robot2" /> </include> </group> </launch>
Please notice that it should have a different namespace and tf_prefix for each robot.
<launch> <param name="/use_sim_time" value="true" /> <!-- start world --> <node name="gazebo" pkg="gazebo_ros" type="gazebo" args="$(find turtlebot_gazebo)/worlds/empty_wall.world" respawn="false" output="screen" /> <!-- start gui --> <!-- <node name="gazebo_gui" pkg="gazebo" type="gui" respawn="false" output="screen"/> --> <!-- include our robots --> <include file="$(find multi_robot)/launch/robots.launch"/> </launch>
You can launch the simulation with the following command
roslaunch multi_robot main.launch
Then you have to open the gazebo window from Tools->Gazebo
You should see 2 robots are spawned in the simulation. You can spawn more by changing the robots.launch if you want.
Step 3. Move the robot
Open another terminal, if you type rostopic list , you’ll see there are 2 cmd_vel topics for the robots. The simplest way to control them is with the teleop_twist. We can run it and remap the cmd_vel with the robot you want to control. For example
rosrun teleop_twist_keyboard teleop_twist_keyboard.py /cmd_vel:=/robot1/cmd_vel
Now you can control the robot you want.
Edit by: Tony Huang
// RELATED LINKS
Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.