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

Add entity and sdf parameters to Server's AddSystem interface #2324

Conversation

g-arjones
Copy link
Contributor

@g-arjones g-arjones commented Feb 24, 2024

🦟 Bug fix

Fixes #2322

Summary

Entity and XML content information are lost when adding systems through the Server::AddSystem(system) API. To reproduce it:

  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::systems::DummyPlugin", "<test>foo</test>");
  auto mockSystemPlugin = systemLoader.LoadPlugin(sdfPlugin);
  EXPECT_TRUE(*server.AddSystem(mockSystemPlugin.value()));

Without this patch, the code above will output:

<plugin filename='__default__'/>

After the patch, you will be able to use the extended Server::AddSystem(plugin, entity, sdf) API and get:

<plugin filename='dummy_plugin' name='gz::sim::DummyPlugin'>
  <test>foo</test>
</plugin>

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label Feb 24, 2024
@g-arjones g-arjones force-pushed the add_entity_and_sdf_params_to_add_system_interface branch from 6ca5766 to aafaa1e Compare February 24, 2024 18:10
@g-arjones g-arjones force-pushed the add_entity_and_sdf_params_to_add_system_interface branch from aafaa1e to 6d3211d Compare February 26, 2024 15:12
@g-arjones
Copy link
Contributor Author

Amended to fix linting issues

@azeey azeey self-requested a review February 28, 2024 16:24
Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for the contribution!

I have a few minor comments, but otherwise this is good to go!

One thing I noticed is that adding a plugin through Server is still overly complicated. A follow up PR would be to have a new API:

      public: std::optional<bool> AddSystem(
                  const std::Plugin &_plugin,
                  std::optional<Entity> _entity,
                  const unsigned int _worldIndex = 0);

That would encapsulate loading the plugin and extracting the _sdf element from sdf::Plugin. Thoughts?

include/gz/sim/Server.hh Show resolved Hide resolved
include/gz/sim/Server.hh Outdated Show resolved Hide resolved
@azeey azeey self-assigned this Feb 28, 2024
@g-arjones
Copy link
Contributor Author

That would encapsulate loading the plugin and extracting the _sdf element from sdf::Plugin. Thoughts?

Sounds good to me. May I do it in this PR ?

@azeey
Copy link
Contributor

azeey commented Feb 28, 2024

That would encapsulate loading the plugin and extracting the _sdf element from sdf::Plugin. Thoughts?

Sounds good to me. May I do it in this PR ?

Go for it!

@g-arjones g-arjones force-pushed the add_entity_and_sdf_params_to_add_system_interface branch from 6d3211d to 2c6f4bd Compare February 28, 2024 20:46
@g-arjones
Copy link
Contributor Author

@azeey Comments have been addressed.

Thank you for the review!

@g-arjones g-arjones force-pushed the add_entity_and_sdf_params_to_add_system_interface branch 2 times, most recently from 5cd3710 to bf4a8db Compare February 29, 2024 12:58
@g-arjones
Copy link
Contributor Author

@azeey Had to amend again because of another linter issue, sorry about that.

BTW, the contribution guide mentions a codecheck target but the current cmake configuration doesn't seem to be generating that:

$ make codecheck
make: *** No rule to make target 'codecheck'.  Stop.

How should I run cpplint and cppcheck on gz-sim properly?

@g-arjones g-arjones force-pushed the add_entity_and_sdf_params_to_add_system_interface branch from bf4a8db to 8ce19f5 Compare February 29, 2024 17:50
@azeey
Copy link
Contributor

azeey commented Feb 29, 2024

@azeey Had to amend again because of another linter issue, sorry about that.

BTW, the contribution guide mentions a codecheck target but the current cmake configuration doesn't seem to be generating that:

$ make codecheck
make: *** No rule to make target 'codecheck'.  Stop.

How should I run cpplint and cppcheck on gz-sim properly?

You must install cppcheck first for the codecheck target to be available.

@g-arjones
Copy link
Contributor Author

You must install cppcheck first for the codecheck target to be available.

Got it. I think we are good to go now.

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.98%. Comparing base (633ce72) to head (4e739b8).

Additional details and impacted files
@@             Coverage Diff             @@
##           gz-sim8    #2324      +/-   ##
===========================================
+ Coverage    65.97%   65.98%   +0.01%     
===========================================
  Files          327      327              
  Lines        31328    31339      +11     
===========================================
+ Hits         20668    20680      +12     
+ Misses       10660    10659       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small comment. Thanks!

include/gz/sim/Server.hh Show resolved Hide resolved
@g-arjones g-arjones force-pushed the add_entity_and_sdf_params_to_add_system_interface branch from 8ce19f5 to 4e739b8 Compare March 1, 2024 12:46
@g-arjones
Copy link
Contributor Author

No problem. Amended again.

Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. Thanks for the contribution!

@iche033 iche033 merged commit 2ca64d0 into gazebosim:gz-sim8 Mar 5, 2024
10 checks passed
@g-arjones g-arjones deleted the add_entity_and_sdf_params_to_add_system_interface branch March 5, 2024 02:22
@g-arjones
Copy link
Contributor Author

@azeey @iche033 Any idea when this might be released?

GauravKumar9920 pushed a commit to GauravKumar9920/gz-sim that referenced this pull request Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

SystemLoader ignores XML content when loading plugins through LoadPlugin(...)
3 participants