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

SystemLoader ignores XML content when loading plugins through LoadPlugin(...) #2322

Closed
g-arjones opened this issue Feb 23, 2024 · 7 comments · Fixed by #2324
Closed

SystemLoader ignores XML content when loading plugins through LoadPlugin(...) #2322

g-arjones opened this issue Feb 23, 2024 · 7 comments · Fixed by #2324
Labels
bug Something isn't working

Comments

@g-arjones
Copy link
Contributor

Environment

  • OS Version: Ubuntu 22.04
  • Source or binary build? Binary (version 8.1.0)

Description

  • Expected behavior:
  • Actual behavior:

Steps to reproduce

  1. Create a dummy system plugin:
class DummyPlugin : public gz::sim::System,
  public gz::sim::ISystemConfigure,
{
public:
  void Configure(
    const gz::sim::Entity &_entity,
    const std::shared_ptr<const sdf::Element> &_sdf,
    gz::sim::EntityComponentManager &_ecm,
    gz::sim::EventManager &_eventMgr) override
  {
    std::cout << _sdf->ToString("") << std::endl;
  }
};
  1. Load it with the SystemLoader (extracted from here):
  sim::SystemLoader systemLoader;
  sdf::Plugin sdfPlugin("dummy_plugin", "gz::sim::DummyPlugin", "<test>foo</test>");
  auto mockSystemPlugin = systemLoader.LoadPlugin(sdfPlugin);
  EXPECT_TRUE(*server.AddSystem(mockSystemPlugin.value()));

Output

You should get on your console:

<plugin filename='__default__'/>

When you should actually be getting something like:

<plugin filename='dummy_plugin' name='gz::sim::DummyPlugin'>
  <test>foo</test>
</plugin>
@g-arjones g-arjones added the bug Something isn't working label Feb 23, 2024
@azeey
Copy link
Contributor

azeey commented Feb 23, 2024

It looks like we need a new API for adding systems programmatically with XML content. The current System::AddSystem API calls SimulationRunner::AddSystem with the default arguments, which has sdf::ElementPtr set to std::nullopt.

public: void AddSystem(const SystemPluginPtr &_system,
std::optional<Entity> _entity = std::nullopt,
std::optional<std::shared_ptr<const sdf::Element>> _sdf =
std::nullopt);

@g-arjones
Copy link
Contributor Author

Unfortunately, both SystemManager and SimulationRunner are private classes so I don't see any way around this. Is there a reason why this wasn't implemented? Would you guys accept a patch?

@azeey
Copy link
Contributor

azeey commented Feb 23, 2024

Yes, I think it would be great to have a Server::AddSystem that mirrors SimulationRunner::AddSystem but has the additional _worldIndex parameter. A patch for that would be awesome!

Another thought is to extend ServerConfig to allow adding plugins in addition to the ones loaded by default or listed in the SDFormat file. This would be useful for gazebosim/ros_gz#500

@g-arjones
Copy link
Contributor Author

g-arjones commented Feb 23, 2024

Another thought is to extend ServerConfig to allow adding plugins in addition to the ones loaded by default or listed in the SDFormat file. This would be useful for gazebosim/ros_gz#500

Not sure I get this one... Isn't this possible already through these interfaces:

/// \brief Instruct simulation to attach a plugin to a specific
/// entity when simulation starts.
/// \param[in] _info Information about the plugin to load.
public: void AddPlugin(const PluginInfo &_info);
/// \brief Add multiple plugins to the simulation
/// \param[in] _plugins List of Information about the plugin to load.
public: void AddPlugins(const std::list<PluginInfo> &_plugins);

@azeey
Copy link
Contributor

azeey commented Feb 23, 2024

Unfortunately, those APIs don't work if the SDF file doesn't have any plugins and instead wants to just use the default set. When calling ServerConfig::AddPlugin, just the plugins in the ServerConfig get loaded, but the default set of plugins doesn't. I haven't actually what happens if the SDF file actually has plugins listed and we call ServerConfig::AddPlugin.

@g-arjones
Copy link
Contributor Author

I see. OK, I will give it a try.

@g-arjones
Copy link
Contributor Author

@azeey I have submitted a patch to fix the original issue. The feature you proposed seemed a bit more involved and is worth a separate PR IMO. I will work on the other one if we can merge #2324 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants