ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Spawn three different custom robots in a launch file

asked 2019-02-07 11:13:14 -0500

the3kr gravatar image

updated 2021-11-14 09:49:04 -0500

lucasw gravatar image

Is it possible to combine three different robot together in a launch file, spawn them together in gazebo and visualize in RVIZ ?

I've created and simulated the three robots but I'll like to combine them in a single simulation.


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2019-02-08 03:53:49 -0500

Delb gravatar image

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 :


    <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">

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 :

    <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)"/>

<!-- Set different initial poses to avoid collision when spawning the model -->
    <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 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 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"/>


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.

edit flag offensive delete link more


Yes you are right. It's three different robots. Thanks.

the3kr gravatar image the3kr  ( 2019-02-09 17:53:27 -0500 )edit

What would i have to change in the code in order to spawn 3 copies of the same robot? Thanks.

Nick_JR gravatar image Nick_JR  ( 2020-07-03 09:53:47 -0500 )edit

hi. thanks for your complete and nice reply. could you please consider replying the case of spawning two same models?

M.IR gravatar image M.IR  ( 2022-08-31 13:16:57 -0500 )edit

answered 2019-02-07 12:02:37 -0500

ct2034 gravatar image

Whenever you call spawn_model, a new robot is added to your simulation. You just have to call it 3 times in your launchfile.

rosrun gazebo_ros spawn_model -file `rospack find baxter_description`/urdf/baxter.urdf -urdf -z 1 -model baxter

This should teach you everything:

edit flag offensive delete link more


It seems promising I'll try it and let you know if it works. But a quick question both nodes have the same name 'spawn_urdf' in the same launch file, isn't that a name clash?

the3kr gravatar image the3kr  ( 2019-02-07 12:19:45 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-02-07 11:13:14 -0500

Seen: 1,560 times

Last updated: Feb 08 '19