Let's consider the mobile base we created in Chapter 3, Building an Industrial Mobile Manipulator, for this example. The workspace is available in GitHub at the following link: https://github.com/PacktPublishing/ROS-Robotics-Projects-SecondEdition/tree/master/chapter_3_ws/src/robot_description. Download it in to a new workspace and then compile the workspace. The robot base is launched using the following commands:
$ initros1
$ roslaunch robot_description base_gazebo_control.xacro.launch
You should then see the gazebo model, as shown here:
Now, our intent is to spawn another robot into the gazebo, so let's name the robots robot1 and robot2. To the preceding base_gazebo_control.xacro.launch file, we are launching the empty gazebo world, loaded with our robot and controller configurations, into the ROS server and loading the controller node. We need to do the same, but for more than one robot. For this, we would launch the robot under a namespace group tag. We need to ensure that the robot transforms are differentiated using the tf_prefix parameter and a <robot_name> prefix while loading the robot's URDF.
Finally, we have to differentiate each robot's controllers using the ns argument while loading the controller and the --namespace argument while launching the controller node. These changes can be applied to robot1 like so:
<group ns="/robot1">
<param name="tf_prefix" value="robot1" />
<rosparam file="$(find robot_description)/config/control.yaml" command="load" ns="/robot1" />
<param name="/robot1/robot_description" command="$(find xacro)/xacro --inorder $(find robot_description)/urdf/robot_base.urdf.xacro nsp:=robot1"/>
<node name="urdf_spawner_1" pkg="gazebo_ros" type="spawn_model"
args="-x -1.0 -y 0.0 -z 1.0 -unpause -urdf -model robot1 -param robot_description " respawn="false" output="screen">
</node>
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher_1">
<param name="publish_frequency" type="double" value="30.0" />
</node>
<node name="robot1_controller_spawner" pkg="controller_manager" type="spawner"
args="--namespace=/robot1
robot_base_joint_publisher robot_base_velocity_controller
--shutdown-timeout 3">
</node>
</group>
To launch two robots, simply copy and paste this whole block of code twice and replace robot1 with robot2 in the second copied block. You could go about creating as many blocks as you like. For simplicity, we moved this block of code into another launch file called multiple_robot_base.launch. The full code for launching two such robots is available on GitHub (https://github.com/PacktPublishing/ROS-Robotics-Projects-SecondEdition/blob/master/chapter_6_ws/src/robot_description/launch/multiple_robot_base.launch). The main launch file is available on GitHub under the robotbase_simulation.launch, which starts the gazebo empty world and the multiple_robot_base launch file.
Your gazebo view will look as follows:
The following are the rostopic lists:
Now that we have launched multiple robots using namespaces, let's look at its limitations.