Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sdf plugin #1352

Merged
merged 42 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0896ac1
Added more tests
Feb 11, 2022
60be532
merged with ign-gazebo6
Feb 11, 2022
2770692
Change clone
Feb 16, 2022
4a9822b
Use sdf::Plugin instead of sdf::ElementPtr
Feb 16, 2022
f32555b
Address review comments
Feb 16, 2022
171d745
Merge branch 'ign-gazebo6' into server-config-root-dom
mjcarroll Feb 16, 2022
7d33cf0
Fix linter, and added tests
Feb 16, 2022
7fedd8d
Merge branch 'server-config-root-dom' of github.com:ignitionrobotics/…
Feb 16, 2022
756e818
Merge branch 'ign-gazebo6' into use_sdf_plugin
Feb 28, 2022
087225e
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Feb 28, 2022
f2ad40b
Merge branch 'ign-gazebo6' into use_sdf_plugin
Mar 8, 2022
f27ec9c
Merge branch 'use_sdf_plugin' of github.com:ignitionrobotics/ign-gaze…
Mar 8, 2022
713f3ba
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 8, 2022
711761d
Update branch
Mar 9, 2022
1b48c9d
Merge branch 'use_sdf_plugin' of github.com:ignitionrobotics/ign-gaze…
Mar 9, 2022
7ac1b4e
Merged with server-config-root-dom
Mar 9, 2022
d60d34a
Tweaks
Mar 9, 2022
bb3d2a6
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 14, 2022
1469cd3
Merge branch 'server-config-root-dom' into use_sdf_plugin
Mar 14, 2022
ae00505
Updates to match garden forward port
Mar 14, 2022
f23935c
Updated documentation and minor cleanup
Mar 14, 2022
0402553
Merge branch 'ign-gazebo6' into server-config-root-dom
ahcorde Mar 15, 2022
146ecf9
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 15, 2022
71ee327
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 15, 2022
d0695a4
use sdf 12.4
Mar 16, 2022
977847e
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 18, 2022
3af47f1
Merge branch 'ign-gazebo6' into server-config-root-dom
Mar 24, 2022
c6cd141
Merge branch 'server-config-root-dom' into use_sdf_plugin
Mar 24, 2022
e0d90ce
Merged from ign-gazebo6
Apr 4, 2022
aa28fec
Merge branch 'ign-gazebo6' into use_sdf_plugin
nkoenig Apr 7, 2022
3ae56ea
merged with ign-gazebo6
Apr 21, 2022
611e9aa
Merge branch 'use_sdf_plugin' of github.com:ignitionrobotics/ign-gaze…
Apr 21, 2022
a1b5953
Merge branch 'ign-gazebo6' into use_sdf_plugin
May 13, 2022
fd2b9b1
resolve some comments
May 13, 2022
61fcf05
Resolve issue #1363
May 13, 2022
15d31a9
Merge branch 'ign-gazebo6' into use_sdf_plugin
Jun 8, 2022
c3dbeb7
Remove components::VisualPlugins
Jun 8, 2022
cd39a3d
Merge branch 'ign-gazebo6' into use_sdf_plugin
nkoenig Jun 15, 2022
cacc351
Merge branch 'ign-gazebo6' into use_sdf_plugin
iche033 Jun 17, 2022
afd30fb
Address comments
Jun 23, 2022
ea9b8e7
Merge branch 'use_sdf_plugin' of github.com:ignitionrobotics/ign-gaze…
Jun 23, 2022
6ebc574
Merge branch 'ign-gazebo6' into use_sdf_plugin
Jun 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions include/ignition/gazebo/Conversions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <ignition/msgs/light.pb.h>
#include <ignition/msgs/material.pb.h>
#include <ignition/msgs/particle_emitter.pb.h>
#include <ignition/msgs/plugin.pb.h>
#include <ignition/msgs/plugin_v.pb.h>
#include <ignition/msgs/physics.pb.h>
#include <ignition/msgs/scene.pb.h>
#include <ignition/msgs/sensor.pb.h>
Expand Down Expand Up @@ -742,6 +744,54 @@ namespace ignition
/// \return Plugin message.
template<>
msgs::Plugin convert(const sdf::Plugin &_in);

/// \brief Generic conversion from an SDF plugins to another type.
/// \param[in] _in SDF plugins.
/// \return Conversion result.
/// \tparam Out Output type.
template<class Out>
Out convert(const sdf::Plugins &/*_in*/)
{
Out::ConversionNotImplemented;
}

/// \brief Specialized conversion from an SDF plugins to a plugin_v message.
/// \param[in] _in SDF plugins.
/// \return Plugin_V message.
template<>
msgs::Plugin_V convert(const sdf::Plugins &_in);

/// \brief Generic conversion from a msgs::Plugin to another type.
/// \param[in] _in msgs::Plugin.
/// \return Conversion result.
/// \tparam Out Output type.
template<class Out>
Out convert(const msgs::Plugin &/*_in*/)
{
Out::ConversionNotImplemented;
}

/// \brief Specialized conversion from a msgs::Plugin to an sdf::Plugin.
/// \param[in] _in msgs::Plugin.
/// \return sdf::Plugin.
template<>
sdf::Plugin convert(const msgs::Plugin &_in);

/// \brief Generic conversion from a msgs::Plugin_V to another type.
/// \param[in] _in msgs::Plugin_V.
/// \return Conversion result.
/// \tparam Out Output type.
template<class Out>
Out convert(const msgs::Plugin_V &/*_in*/)
{
Out::ConversionNotImplemented;
}

/// \brief Specialized conversion from a msgs::Plugin_V to an sdf::Plugins.
/// \param[in] _in msgs::Plugin_V.
/// \return sdf::Plugins.
template<>
sdf::Plugins convert(const msgs::Plugin_V &_in);
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion include/ignition/gazebo/Events.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define IGNITION_GAZEBO_EVENTS_HH_

#include <sdf/Element.hh>
#include <sdf/Plugin.hh>

#include <ignition/common/Event.hh>

Expand Down Expand Up @@ -53,11 +54,24 @@ namespace ignition
/// \endcode
using Stop = ignition::common::EventT<void(void), struct StopTag>;

/// \brief Event used to load plugins for an entity into simulation.
/// \brief Please use the LoadSdfPlugins event. The LoadPlugins event
/// will be deprecrated in Gazebo 7 (Garden). Also make sure to
/// connect to only LoadSdfPlugins or LoadPlugins, and not both events.
///
/// Event used to load plugins for an entity into simulation.
/// Pass in the entity which will own the plugins, and an SDF element for
/// the entity, which may contain multiple `<plugin>` tags.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
using LoadPlugins = common::EventT<void(Entity, sdf::ElementPtr),
struct LoadPluginsTag>;

/// \brief Event used to load plugins for an entity into simulation.
/// Pass in the entity which will own the plugins, and an SDF element for
/// the entity, which may contain multiple `<plugin>` tags.
/// Makre sure that you don't also connect to the LoadPlugins event.
using LoadSdfPlugins = common::EventT<void(Entity, sdf::Plugins),
struct LoadPluginsTag>;
}
} // namespace events
} // namespace gazebo
Expand Down
39 changes: 39 additions & 0 deletions include/ignition/gazebo/ServerConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include <vector>
#include <sdf/Element.hh>
#include <sdf/Plugin.hh>
#include <sdf/Root.hh>
#include <ignition/gazebo/config.hh>
#include <ignition/gazebo/Export.hh>
Expand Down Expand Up @@ -86,12 +87,26 @@ namespace ignition
/// \param[in] _name Name of the interface within the plugin library
/// to load.
/// \param[in] _sdf Plugin XML elements associated with this plugin.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: PluginInfo(const std::string &_entityName,
const std::string &_entityType,
const std::string &_filename,
const std::string &_name,
const sdf::ElementPtr &_sdf);

/// \brief Constructor with plugin information specified.
/// \param[in] _entityName Name of the entity which should receive
/// this plugin. The name is used in conjuction with _entityType to
/// uniquely identify an entity.
/// \param[in] _entityType Entity type which should receive this
/// plugin. The type is used in conjuction with _entityName to
/// uniquely identify an entity.
/// \param[in] _plugin SDF Plugin library information.
public: PluginInfo(const std::string &_entityName,
const std::string &_entityType,
const sdf::Plugin &_plugin);

/// \brief Copy constructor.
/// \param[in] _info Plugin to copy.
public: PluginInfo(const PluginInfo &_info);
Expand Down Expand Up @@ -127,32 +142,56 @@ namespace ignition

/// \brief Get the plugin library filename.
/// \return Plugin library filename.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: const std::string &Filename() const;

/// \brief Set the type of the entity which should receive this
/// plugin. The type is used in conjuction with EntityName to
/// uniquely identify an entity.
/// \param[in] _filename Entity type string.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: void SetFilename(const std::string &_filename);

/// \brief Name of the interface within the plugin library
/// to load.
/// \return Interface name.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: const std::string &Name() const;

/// \brief Set the name of the interface within the plugin library
/// to load.
/// \param[in] _name Interface name.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: void SetName(const std::string &_name);

/// \brief Plugin XML elements associated with this plugin.
/// \return SDF pointer.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: const sdf::ElementPtr &Sdf() const;

/// \brief Set the plugin XML elements associated with this plugin.
/// \param[in] _sdf SDF pointer, it will be cloned.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: void SetSdf(const sdf::ElementPtr &_sdf);

/// \brief Get the SDF plugin information.
/// \return The SDF Plugin object.
public: const sdf::Plugin &Plugin() const;

/// \brief Get a mutable version of the SDF plugin information.
/// \return The SDF Plugin object.
public: sdf::Plugin &Plugin();

/// \brief Set the SDF plugin information.
/// \param[in] _plugin The SDF Plugin object to use.
public: void SetPlugin(const sdf::Plugin &_plugin) const;

/// \brief Private data pointer
private: std::unique_ptr<ServerConfig::PluginInfoPrivate> dataPtr;
};
Expand Down
11 changes: 11 additions & 0 deletions include/ignition/gazebo/SystemLoader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string>

#include <sdf/Element.hh>
#include <sdf/Plugin.hh>

#include <ignition/gazebo/Export.hh>
#include <ignition/gazebo/System.hh>
Expand Down Expand Up @@ -53,6 +54,8 @@ namespace ignition
/// \brief Load and instantiate system plugin from an SDF element.
/// \param[in] _sdf SDF Element describing plugin instance to be loaded.
/// \returns Shared pointer to system instance or nullptr.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: std::optional<SystemPluginPtr> LoadPlugin(
const sdf::ElementPtr &_sdf);

Expand All @@ -61,11 +64,19 @@ namespace ignition
/// \param[in] _name Class name to be instantiated.
/// \param[in] _sdf SDF Element describing plugin instance to be loaded.
/// \returns Shared pointer to system instance or nullptr.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// sdf::Plugin interface.
public: std::optional<SystemPluginPtr> LoadPlugin(
const std::string &_filename,
const std::string &_name,
const sdf::ElementPtr &_sdf);

/// \brief Load and instantiate system plugin from name/filename.
/// \param[in] _plugin SDF Plugin to be loaded.
/// \returns Shared pointer to system instance or nullptr.
public: std::optional<SystemPluginPtr> LoadPlugin(
const sdf::Plugin &_plugin);

/// \brief Makes a printable string with info about systems
/// \returns A pretty string
public: std::string PrettyStr() const;
Expand Down
25 changes: 25 additions & 0 deletions include/ignition/gazebo/gui/GuiEvents.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ignition/math/Vector3.hh>
#include <ignition/utils/ImplPtr.hh>
#include <sdf/Element.hh>
#include <sdf/Plugin.hh>

#include "ignition/gazebo/gui/Export.hh"
#include "ignition/gazebo/Entity.hh"
Expand Down Expand Up @@ -215,6 +216,8 @@ namespace events
};

/// \brief Event that notifies a visual plugin is to be loaded
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
/// VisualPlugins class.
class IGNITION_GAZEBO_GUI_VISIBLE VisualPlugin: public QEvent
{
/// \brief Constructor
Expand All @@ -235,6 +238,28 @@ namespace events
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event that notifies a visual plugin is to be loaded
class IGNITION_GAZEBO_GUI_VISIBLE VisualPlugins: public QEvent
{
/// \brief Constructor
/// \param[in] _entity Visual entity id
/// \param[in] _plugins SDF plugin object
public: explicit VisualPlugins(ignition::gazebo::Entity _entity,
const sdf::Plugins &_plugins);

/// \brief Get the entity to load the visual plugin for
public: ignition::gazebo::Entity Entity() const;

/// \brief Get the SDF Plugin of the visual plugin
public: const sdf::Plugins &Plugins() const;

static const QEvent::Type kType = QEvent::Type(QEvent::User + 9);

/// \internal
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};
} // namespace events
}
} // namespace gui
Expand Down
32 changes: 32 additions & 0 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1792,3 +1792,35 @@ msgs::Plugin ignition::gazebo::convert(const sdf::Plugin &_in)

return result;
}

//////////////////////////////////////////////////
template<>
IGNITION_GAZEBO_VISIBLE
msgs::Plugin_V ignition::gazebo::convert(const sdf::Plugins &_in)
{
msgs::Plugin_V result;
for (const sdf::Plugin &plugin : _in)
{
result.add_plugins()->CopyFrom(convert<msgs::Plugin>(plugin));
}
return result;
}

//////////////////////////////////////////////////
template<>
IGNITION_GAZEBO_VISIBLE
sdf::Plugin ignition::gazebo::convert(const msgs::Plugin &_in)
chapulina marked this conversation as resolved.
Show resolved Hide resolved
{
return sdf::Plugin(_in.filename(), _in.name(), _in.innerxml());
}

//////////////////////////////////////////////////
template<>
IGNITION_GAZEBO_VISIBLE
sdf::Plugins ignition::gazebo::convert(const msgs::Plugin_V &_in)
{
sdf::Plugins result;
for (int i = 0; i < _in.plugins_size(); ++i)
result.push_back(convert<sdf::Plugin>(_in.plugins(i)));
return result;
}
47 changes: 47 additions & 0 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1109,3 +1109,50 @@ TEST(Conversions, Plugin)
EXPECT_NE(pluginMsg.innerxml().find("<avocado>0.5</avocado>"),
std::string::npos) << pluginMsg.innerxml();
}

/////////////////////////////////////////////////
TEST(Conversions, MsgsPluginToSdf)
{
std::string innerXml ="<test>another_test</test>\n";
std::string innerXml2 ="<peanut>butter</peanut>\n";

msgs::Plugin msgPlugin;
msgPlugin.set_name("foo");
msgPlugin.set_filename("bar");
msgPlugin.set_innerxml(innerXml);

// Test conversion of a single msgs::Plugin to sdf::Plugin
sdf::Plugin sdfPlugin = convert<sdf::Plugin>(msgPlugin);
EXPECT_EQ("foo", sdfPlugin.Name());
EXPECT_EQ("bar", sdfPlugin.Filename());
ASSERT_EQ(1u, sdfPlugin.Contents().size());
EXPECT_EQ(innerXml, sdfPlugin.Contents()[0]->ToString(""));

// Test conversion of a msgs::Plugin_V with 1 plugin to sdf::Plugins
msgs::Plugin_V msgsPlugin;
msgsPlugin.add_plugins()->CopyFrom(msgPlugin);
sdf::Plugins sdfPlugins = convert<sdf::Plugins>(msgsPlugin);
ASSERT_EQ(1u, sdfPlugins.size());
EXPECT_EQ("foo", sdfPlugins[0].Name());
EXPECT_EQ("bar", sdfPlugins[0].Filename());
ASSERT_EQ(1u, sdfPlugins[0].Contents().size());
EXPECT_EQ(innerXml, sdfPlugins[0].Contents()[0]->ToString(""));

// Add another plugin the msgs::Plugin_V
msgs::Plugin anotherPlugin;
anotherPlugin.set_name("sandwich");
anotherPlugin.set_filename("time");
anotherPlugin.set_innerxml(innerXml + innerXml2);
msgsPlugin.add_plugins()->CopyFrom(anotherPlugin);
sdfPlugins = convert<sdf::Plugins>(msgsPlugin);
ASSERT_EQ(2u, sdfPlugins.size());
EXPECT_EQ("foo", sdfPlugins[0].Name());
EXPECT_EQ("bar", sdfPlugins[0].Filename());
ASSERT_EQ(1u, sdfPlugins[0].Contents().size());
EXPECT_EQ(innerXml, sdfPlugins[0].Contents()[0]->ToString(""));
EXPECT_EQ("sandwich", sdfPlugins[1].Name());
EXPECT_EQ("time", sdfPlugins[1].Filename());
ASSERT_EQ(2u, sdfPlugins[1].Contents().size());
EXPECT_EQ(innerXml, sdfPlugins[1].Contents()[0]->ToString(""));
EXPECT_EQ(innerXml2, sdfPlugins[1].Contents()[1]->ToString(""));
}
3 changes: 3 additions & 0 deletions src/LevelManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ void LevelManager::ReadLevelPerformerInfo()
this->ConfigureDefaultLevel();

// Load world plugins.
this->runner->EventMgr().Emit<events::LoadSdfPlugins>(this->worldEntity,
this->runner->sdfWorld->Plugins());
// Deprecate this in Garden
this->runner->EventMgr().Emit<events::LoadPlugins>(this->worldEntity,
this->runner->sdfWorld->Element());

Expand Down
Loading