Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

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

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.