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

Spawning multiples robots with 1 URDF/XACRO file

asked 2015-03-05 10:46:05 -0500

End-Effector gravatar image

Hello,

I'm spawning 2 pioneer robots but I have some plug-ins for the sensors, odom and cmd/vel that are publishing for the same topics.

Is there any simple/and efficient way to change the topics where they are publishing this messages? The robots have different names already. Anyone knows how to do this?

I don't want just to copy paste all the xacro code and change the topics by hand, I think its not a good solution.

Anyone knows how to do this? So far I created 2 launch files to try to do this:

 <launch>
    <param name="/use_sim_time" value="true"/>

    <include file="$(find gazebo_ros)/launch/empty_world.launch"/>

  <group ns="p3dx_1">
    <include file="$(find p3dx_gazebo)/launch/pioneer.launch">
      <arg name="name" value="p3dx_1"/>
      <arg name="pos_x" value="-4.0"/>
      <arg name="namespace_arg" value="p3dx_1"/>
    </include>
  </group>

  <group ns="p3dx_2">
    <include file="$(find p3dx_gazebo)/launch/pioneer.launch">
      <arg name="name" value="p3dx_2"/>
      <arg name="pos_x" value="4.0"/>
      <arg name="namespace_arg" value="p3dx_2"/>
    </include>
  </group>
</launch>

and this one:

<launch>
  <!-- push robot_description to factory and spawn robot in gazebo -->
  <arg name="name" default="pioneer"/>
  <arg name="pos_x" default="0.0"/>
  <arg name="pos_y" default="0.0"/>
  <arg name="pos_z" default="0.0"/>
  <arg name="namespace_arg" default=""/>

  <arg name="model" default="$(find p3dx_description)/urdf/$(arg namespace_arg).xacro"/>
  <!-- send the robot XML to param server -->
  <param name="robot_description" command="$(find xacro)/xacro.py '$(arg model)'" />
  <param name="tf_prefix" value="$(arg namespace_arg)" />
  <node name="spawn_robot" pkg="gazebo_ros" type="spawn_model"
        args="-param robot_description
              -urdf
              -x $(arg pos_x)
              -y $(arg pos_y)
              -z $(arg pos_z)
              -model $(arg name)"
        respawn="false" output="screen">
  </node>
</launch>

But I think this way I will have to copy the .xacro files. Anyone has a better idea?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-03-06 09:09:03 -0500

LucianTM gravatar image

I just tried it myself with my robot. One thing you need are groups in launchfiles.

http://wiki.ros.org/roslaunch/XML/group

BTW. If you use robot namespace tags in your model plugins, remove them!

Otherwise your topics like for example cmd_vel will overlap.

You also need another parameter with a different name for the other robot because I found out they are named like the param in gazebo.

Put the same launch tags (except the parameter for the spawn and spawn position) for your robots in two tags,

For example:

<node name="spawn_test_bot" pkg="gazebo_ros" type="spawn_model" args="-z 0.1 -urdf -param robot_description -model robot_description" respawn="false" />

 <node name="spawn_test_bot" pkg="gazebo_ros" type="spawn_model" args="-z 0.1 -x 1 -urdf -param robot_description2 -model robot_description2" respawn="false" />

That seems to work for me, but currently I just need one robot.

edit flag offensive delete link more

Comments

how did you make it work? node nam must be unique!

cybodroid gravatar image cybodroid  ( 2015-12-13 21:09:15 -0500 )edit
0

answered 2020-04-13 07:36:51 -0500

Luczia gravatar image

Hi,

the topic is old, but since I struggled with the same issue, I figured to give my input here:

@End-Effector: your approach seems good and as desribed in the different tutorials. Using group and namespace as you did will automatically add a :[namespace_name]/ at the beginning of the broadcasted topics.

Nevertheless, if your urdf description xacro file is including gazebo plugins which publish topics (/laser/scan or /imu for example); then you should not use

<robotNamespace></robotNamespace>

Indeed, it might be counter-intutive but adding those tags (and a value in-between) there seems to override the namespace from the launchfile.

For my part, removing those namespace soved the issue.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-03-05 10:46:05 -0500

Seen: 3,000 times

Last updated: Apr 13 '20