How to spawn multiple objects in gazebo using libgazebo_ros_camera.so

1k Views Asked by At

Using the following in the .sdf file works fine only for spawning one object. If I try to spawn more than one, an error occurs because there are two objects "talking" on the same topics.

How can I write this piece of sdf more general so that spawning more objects is not a problem anymore? For example adding the model name inside the topic name?

<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
    <alwaysOn>true</alwaysOn>
    <updateRate>0.0</updateRate>  
    <cameraName>RCcar/camera1</cameraName>   
    <imageTopicName>image_raw</imageTopicName>    
    <cameraInfoTopicName>camera_info</cameraInfoTopicName>    
    <frameName>link_camera</frameName>    
    <hackBaseline>0.0</hackBaseline>    
    <distortionK1>0.0</distortionK1>    
    <distortionK2>0.0</distortionK2>    
    <distortionK3>0.0</distortionK3>    
    <distortionT1>0.0</distortionT1>    
    <distortionT2>0.0</distortionT2>    
    <robotNamespace>/</robotNamespace>    
</plugin>
1

There are 1 best solutions below

0
On

there is a way that you do not need to modify your model profile.

In the ROS launch file in which you spawn the models, you can add a "group ns" attribute. Here is an example:

<!-- BEGIN ROBOT 1-->
  <group ns="robot1">
    <param name="tf_prefix" value="robot1_tf" />
    <include file="EXAMPLE_PATH/EXAMPLE_LAUNCH_FILE_FOR_ONE_ROBOT.launch" >
      (args ...)
    </include>
  </group>

  <!-- BEGIN ROBOT 2-->
  <group ns="robot2">
    <param name="tf_prefix" value="robot2_tf" />
    <include file="EXAMPLE_PATH/EXAMPLE_LAUNCH_FILE_FOR_ONE_ROBOT.launch" >
      (args ...)
    </include>
  </group>

In the "EXAMPLE_LAUNCH_FILE_FOR_ONE_ROBOT.launch" file, you may launch one robot model.

Then the rostopics will be:

...

/robot1/topicXXX
/robot2/topicXXX

...