Home | Tutorials | Wiki | Issues
Ask Your Question

Passing parameters to included SDF

asked 2013-05-10 05:44:13 -0500

Boris gravatar image

updated 2013-05-11 12:57:40 -0500

For example I have a bunch of identical cameras in a world. The model of a camera includes the gazebo_ros_camera plugin with parameters such as topic name etc. Obviously every camera should publish to the topic with unique name. So, is it possible to pass such parameters from within <include> tag? If not, are there any workarounds? Duplicating the camera model with modified parameters is not a nice option.

Something similar to <arg> tag in ROS' launch files would suffice, but I was unable to find anything like this in SDF specification.


Let's say I have a Gazebo model of camera:

<sdf version="1.3">
  <model name="camera">
    <link name="link">
      <sensor name="camera" type="camera">
        <plugin name="camera_plugin" filename="libgazebo_ros_camera.so">
          <!-- PROBLEMS ARE HERE -->

Now, if I include several of these to a world:

<sdf version="1.3">
  <world name="cameras_world">
      <pose>1 0 1 0 0 0</pose>

      <pose>2 0 1 0 0 0</pose>

      <pose>3 0 1 0 0 0</pose>

All three cameras will publish to exactly same ROS topic: /camera/image_raw as well as with exactly same frame ID: camera_frame. Because there is no way on SDF level to pass down custom parameters to included models.

So I need a workaround for this and looking for your kind suggestions.

I hope now my question is clear :-)



edit retag flag offensive close merge delete


@Boris did you find a solution after all these years? I face this problem now.

Vangelis gravatar imageVangelis ( 2017-10-25 13:45:50 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2013-05-11 23:08:34 -0500

scpeters gravatar image

See the drc_vehicle model as an example for how to use included models with plugins.

edit flag offensive delete link more


I have multiple instances of model-with-sensor-plugin.sdf included into a world.sdf. If I understand correctly you refer to MudPlugin, which instead of being put inside the Polaris Ranger EV model is on higher level of hierarchy. However in this case plugin should be aware on how to subscribe to particular Gazebo sensor, e.g. using tag <contactsensorname>. I am using standard ROS plugins that do not have such interface, so I need a more generic approach.

Boris gravatar imageBoris ( 2013-05-12 01:20:57 -0500 )edit

answered 2013-05-11 09:48:00 -0500

AndreiHaidu gravatar image

updated 2013-05-11 14:02:48 -0500


you could add the <topic> as a parameter to the plugin (similarly to this answer):

<plugin name='plugin_name' filename='libplugin_name.so'>

in the plugin:

void PluginName::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
string topic;

if (!_sdf->HasElement("topic"))
    // if parameter tag does NOT exist
    std::cout << "Missing parameter <topic> in PluginName, default to standard" << std::endl;
    topic = "standard";
    // if parameter tag exists, get its value
else topic = _sdf->GetElement("topic")->GetValueString();

Cheers, Andrei


You could use the GetName() function to get the names of each camera from the <name> tag, and use that as a unique key for the topics name.

edit flag offensive delete link more


I can't use this method unless I rewrite every single third-party plugin. Obviously I don't want to spend time on this.

Boris gravatar imageBoris ( 2013-05-11 15:17:14 -0500 )edit

Can the same be done with urdf? If so, how would the c++ code change?

reubenjohn gravatar imagereubenjohn ( 2016-09-27 10:19:26 -0500 )edit

answered 2013-05-11 00:49:58 -0500

iche033 gravatar image



you should also be able to override other parameters such as <pose> and <static>

edit flag offensive delete link more


Thanks for your reply, but it is not what I am looking for. As I can see from [latest SDF specification](http://gazebosim.org/sdf/dev.html) <include> allows only 3 tags <uri>, <name> and <pose>... However it is not enough for my case as I need to substitute *custom user tags* inside <plugin></plugin>. Probably I have to look into `xacro`...

Boris gravatar imageBoris ( 2013-05-11 04:05:03 -0500 )edit

That documentation of the include tag at that page is incomplete. I will update it. The include tag currently parses name, pose, static, and plugin (see gazebo/sdf/interface/parser.cc:634-691.

scpeters gravatar imagescpeters ( 2013-05-11 23:07:16 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2013-05-10 05:44:13 -0500

Seen: 5,020 times

Last updated: May 11 '13