Gazebo | Ignition | Community
Ask Your Question
3

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.

EDIT:

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 -->
          <imageTopicName>image_raw</imageTopicName>
          <cameraName>camera</cameraName>
          ...
          <frameName>camera_frame</frameName>
          ...
        </plugin>
      </sensor>
    </link>
  </model>
</sdf>

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

<sdf version="1.3">
  <world name="cameras_world">
    ...
    <include>
      <uri>model://camera</uri>
      <name>camera_1</name>
      <pose>1 0 1 0 0 0</pose>
    </include>

    <include>
      <uri>model://camera</uri>
      <name>camera_2</name>
      <pose>2 0 1 0 0 0</pose>
    </include>

    <include>
      <uri>model://camera</uri>
      <name>camera_3</name>
      <pose>3 0 1 0 0 0</pose>
    </include>
</sdf>

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 :-)

Thanks,

Boris

edit retag flag offensive close merge delete

Comments

@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
1

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

Comments

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

This link is now broken.

ricardo.halfeld gravatar imagericardo.halfeld ( 2020-06-11 15:20:47 -0500 )edit
brawner gravatar imagebrawner ( 2022-09-20 14:31:32 -0500 )edit
2

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

AndreiHaidu gravatar image

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

Hi,

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

<plugin name='plugin_name' filename='libplugin_name.so'>
    <topic>topic_name</topic>
</plugin>

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

UPDATE!!!

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

Comments

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
0

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

iche033 gravatar image

try:

<include>
  <uri>model://my_model</uri>
  <name>my_model_unique_name</name>
</include>

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

edit flag offensive delete link more

Comments

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

Another broken link.

ricardo.halfeld gravatar imagericardo.halfeld ( 2020-06-11 15:21:56 -0500 )edit
jdekarske gravatar imagejdekarske ( 2021-01-19 21:39:23 -0500 )edit

Question Tools

3 followers

Stats

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

Seen: 10,916 times

Last updated: May 11 '13