ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes it is possible you just need to be careful with the namespaces. You will need two launch files : one to spawn a robot and one for the common configuration and to call the other one. The first one should be something like that :

spawn.launch :

<launch>

    <arg name="initial_pose_x" default="0.0"/>
    <arg name="initial_pose_y" default="0.0"/>
    <arg name="initial_pose_a" default="0"/>
    <arg name="robot_name" default="A_DEFAULT_NAME"/>

    <!--  ******************** Robot Model ********************  -->
    <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find YOUR_PACKAGE_WITH_URDF_FILE)/urdf/$(arg robot_name).urdf'"/>

    <node pkg="gazebo_ros" type="spawn_model" name="spawn_$(arg robot_name)" 
        args="-x $(arg initial_pose_x) -y $(arg initial_pose_y) -Y $(arg initial_pose_a)
        -unpause -urdf -param robot_description -model $(arg robot_name)" respawn="false">
    </node>
</launch>

Then your other launch file will start gazebo (and maybe rviz too if you want) and call your other launch files in different namespaces (to allow make sure you have different cmd_vel topics so that the three robots don't move the same).

gazebo.launch :

<launch>
    <arg name="world_file"     default="YOUR_PATH_TO_A_WORLD_FILE"/>
    <arg name="gui" default="true"/>
    <arg name="initial_pose_x" default="0.0"/>
    <arg name="initial_pose_y" default="0.0"/>
    <arg name="initial_pose_a" default="0"/>
    <arg name="robot_name" default="A_DEFAULT_ROBOT_NAME"/>
    <param name="/use_sim_time" value="true"/>

        <!--  ******************** Gazebo ********************  -->
    <include file="$(find gazebo_ros)/launch/empty_world.launch">
        <arg name="use_sim_time" value="true"/>
        <arg name="debug" value="false"/>
        <arg name="world_name" value="$(arg world_file)"/>
        <arg name="gui" value="$(arg gui)"/>
    </include>


<!-- Set different initial poses to avoid collision when spawning the model -->
<group ns="THE_NAME_OF_FIRST_ROBOT">
    <include file="$(find PACKAGE_WITH_SPAWN.LAUNCH)/launch/spawn.launch">
        <arg name="initial_pose_x" value="0.0"/>
        <arg name="robot_name" value="THE_NAME_OF_FIRST_ROBOT"/>

    </include>  
</group>

<group ns="THE_NAME_OF_SECOND_ROBOT">
    <include file="$(find PACKAGE_WITH_SPAWN.LAUNCH))/launch/spawn.launch">
        <arg name="initial_pose_x" value="1.0"/>
        <arg name="robot_name" value="THE_NAME_OF_SECOND_ROBOT"/>
    </include>
</group>    

<group ns="THE_NAME_OF_THIRD_ROBOT">
    <include file="$(find PACKAGE_WITH_SPAWN.LAUNCH))/launch/spawn.launch">
        <arg name="initial_pose_x" value="-1.0"/>
        <arg name="robot_name" value="THE_NAME_OF_THIRD_ROBOT"/>
    </include>
</group>

</launch>

That worked fine when I tested it.

Note : From your question I assumed you had three different robots (thus three different urdf files) but it is also possible to do the same for three robots with the same urdf file, let me know if it's the case and I will modify the launch files accordingly.