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

Allow loading a model SDF file in the Server class #1775

Merged
merged 16 commits into from
Nov 9, 2022

Conversation

JoanAguilar
Copy link
Contributor

🎉 New feature

Closes #1711

Summary

The constructor of the Server class has been updated to handle SDF files that contain a model without a world. The model is loaded into the default world.

Test it

One should be able to create Server instances using model SDF files, for instance: test/worlds/models/sphere/model.sdf.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • 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 🌱 garden Ignition Garden label Nov 1, 2022
@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #1775 (2131fc7) into gz-sim7 (6a8594b) will increase coverage by 0.05%.
The diff coverage is 68.64%.

@@             Coverage Diff             @@
##           gz-sim7    #1775      +/-   ##
===========================================
+ Coverage    64.16%   64.21%   +0.05%     
===========================================
  Files          335      336       +1     
  Lines        26508    26864     +356     
===========================================
+ Hits         17008    17251     +243     
- Misses        9500     9613     +113     
Impacted Files Coverage Δ
include/gz/sim/SystemLoader.hh 100.00% <ø> (ø)
include/gz/sim/detail/EntityComponentManager.hh 93.86% <ø> (ø)
include/gz/sim/rendering/RenderUtil.hh 100.00% <ø> (ø)
.../plugins/component_inspector/ComponentInspector.hh 28.57% <ø> (ø)
src/gui/plugins/scene_manager/GzSceneManager.cc 17.58% <0.00%> (-0.60%) ⬇️
...rc/systems/ackermann_steering/AckermannSteering.hh 100.00% <ø> (ø)
src/systems/track_controller/TrackController.cc 46.80% <ø> (+0.19%) ⬆️
.../systems/triggered_publisher/TriggeredPublisher.hh 100.00% <ø> (ø)
.../plugins/component_inspector/ComponentInspector.cc 5.46% <2.77%> (-0.33%) ⬇️
...s/multicopter_motor_model/MulticopterMotorModel.cc 75.91% <33.33%> (-0.22%) ⬇️
... and 16 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
@mjcarroll
Copy link
Contributor

Since UNIT_Server_TEST is already pretty close to the timeout when run in Github Actions (at least, maybe other places as well), I'm a little concerned about adding tests that also depend on rendering as well.

Do you think that you could break this out into UNIT_Server_Rendering_TEST to make it a separate executable and also contain the rendering dep?

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 and works in debug builds. The only blocking comment is about the use of asserts. I also agree with @mjcarroll that we should put the test in a separate file.

src/Server.cc Outdated Show resolved Hide resolved
src/Server.cc Outdated Show resolved Hide resolved
src/Server.cc Outdated
// world and add the model to it.
const sdf::Model model = *(sdfRoot.Model());
errors = this->dataPtr->sdfRoot.LoadSdfString(DefaultWorld::World());
assert(this->dataPtr->sdfRoot.WorldCount() == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we use assert in our code base very much, so this seems out of place, but I'm not opposed to using it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was worndering about that. The other options that come to mind would be to catch this via if statement, or leave this uncaught. I have no strong preference, I'll go with whatever you-all think is best.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be sufficient to add an if statement and returning early if world is nullptr.

auto loadedEngNames = gz::rendering::loadedEngines();
if (loadedEngNames.empty())
{
gzdbg << "No rendering engine is loaded yet" << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

This works, but I think the recommended way to return a failure with a reason is for the function to return an AssertionResult (http://google.github.io/googletest/advanced.html#using-a-function-that-returns-an-assertionresult)

if (!engine)
{
gzerr << "Internal error: failed to load engine [" << engineName
<< "]. Grid plugin won't work." << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the grid plugin relevant here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. FWIW, I took this from RenderingGuiPlugin::FindScene. I'll update this.

src/Server.cc Outdated Show resolved Hide resolved
@JoanAguilar
Copy link
Contributor Author

Do you think that you could break this out into UNIT_Server_Rendering_TEST to make it a separate executable and also contain the rendering dep?

OK, sure. Note that (for now) there's only going to be one test in the new executable: LoadSdfModelRelativeUri.

@mjcarroll
Copy link
Contributor

Note that (for now) there's only going to be one test in the new executable: LoadSdfModelRelativeUri.

Yes, I think that will be fine.

Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
* Remove unnecessary sdf::Root constructor call.

* Avoid an unnecessary copy of an sdf::Model instance.

* Remove asserts.

Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
@JoanAguilar
Copy link
Contributor Author

Previous comments should be addressed now:

  • LoadSdfModelRelativeUri is now on its own file.

  • I have removed the asserts.

  • I have updated FindScene to use gtest macros to determine success (rather than returning a boolean).

  • Some other minor changes.

@mjcarroll
Copy link
Contributor

Looking better, I think that Windows and macOS are having failures in the test that you added. The Ubuntu failure is known and can be ignored.

@azeey
Copy link
Contributor

azeey commented Nov 3, 2022

Looks like the windows tests are failing on the stable CI as well https://build.osrfoundation.org/job/ign_gazebo-gz-sim7-win/17/

@mjcarroll
Copy link
Contributor

Oops, you are right, I misread that.

Also, I'm interested in why these compiler warnings have all appeared in the Windows build here, I thought that we just addressed that via the #1771

@azeey
Copy link
Contributor

azeey commented Nov 3, 2022

Also, I'm interested in why these compiler warnings have all appeared in the Windows build here, I thought that we just addressed that via the #1771

This branch needs to merge from gz-sim7. Unfortunately, when we enabled the ability to merge a PR without being up-to-date with the target branch, github removed the "Update branch" button.

Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
src/Server_Rendering_TEST.cc Outdated Show resolved Hide resolved
@@ -519,6 +519,18 @@ TEST_P(ServerFixture, SdfStringServerConfig)
EXPECT_EQ(2u, *server.SystemCount());
}

/////////////////////////////////////////////////
TEST_P(ServerFixture, LoadSdfModel)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be removed or be added to the other file? We need to reduce the number of tests in Server_TEST.cc.

Copy link
Contributor Author

@JoanAguilar JoanAguilar Nov 4, 2022

Choose a reason for hiding this comment

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

Fine with me. This test will then be in Server_Rendering_TEST.cc and not require rendering, but I understand we are OK with that. (Or I guess I could just remove it.)

src/Server_Rendering_TEST.cc Outdated Show resolved Hide resolved
src/CMakeLists.txt Show resolved Hide resolved
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
@JoanAguilar
Copy link
Contributor Author

JoanAguilar commented Nov 6, 2022

I pushed another batch of changes:

  • I added Server_Rendering_TEST.cc to the list of tests_needing_display.

  • Per comment, I disabled LoadSdfModelRelativeUri for macOS.

  • I moved LoadSdfModel to Server_Rendering_TEST.cc. I think there is some value in keeping it (for instance, LoadSdfModel will run on macOS, while LoadSdfModelRelativeUri won't); however, it does feel a bit misplaced.

  • I made tests on Server_Rendering_TEST.cc run only once.

CI looks a lot more green now, but that might be in part because LoadSdfModelRelativeUri does not seem to run in some of the builds.

edit: looking at the logs, it seems that LoadSdfModelRelativeUri only runs on the Ubuntu jenkins job, and that LoadSdfModel runs in the Ubuntu and macOS jenkins jobs.


As a side note: after I moved UNIT_Server_Rendering_TEST to the list of tests_needing_display it doesn't run anymore on my local build. I wonder if the fact that I'm using Docker + rocker is interfering with the logic in charge of detecting a valid display (display capabilities seem to work fine, as I'm able to launch a GUI windows). And talking about GUI windows, there also seems to be a set of GUI tests that are not in the tests_needing_display list, that run regardless (and spawn new windows while they run).

Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
@mjcarroll
Copy link
Contributor

As a side note: after I moved UNIT_Server_Rendering_TEST to the list of tests_needing_display it doesn't run anymore on my local build

It's likely that the detection is broken because of missing application. I believe that you need to have env DISPLAY set, and then you need xwininfo from x11-utils and glxinfo from mesa-utils.

Currently, these things will come back as "STATUS" messages, but maybe we can elevate them to warning to make it more obvious.

src/Server.cc Outdated
// world and add the model to it.
const sdf::Model model = *(sdfRoot.Model());
errors = this->dataPtr->sdfRoot.LoadSdfString(DefaultWorld::World());
assert(this->dataPtr->sdfRoot.WorldCount() == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be sufficient to add an if statement and returning early if world is nullptr.

Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
Signed-off-by: Joan Aguilar Mayans <joan@openrobotics.org>
@mjcarroll mjcarroll merged commit 5a15834 into gazebosim:gz-sim7 Nov 9, 2022
@JoanAguilar JoanAguilar deleted the load-model-sdf-3 branch November 10, 2022 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Should support loading model SDFormat files directly without having to put them in a world file
3 participants