-
Notifications
You must be signed in to change notification settings - Fork 91
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
Support implicit nested canonical links #341
Conversation
Allow models without links if they have nested models instead. When building FrameAttachedToGraph, if model has no links choose first link of the first nested model as canonical link instead. Repeat this logic for the `Model::CanonicalLink` method. Nested links cannot be specified explicitly with :: syntax in `//model/@canonical_link` in SDFormat 1.7. This will be supported in SDFormat 1.8. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
This is a new private function that de-duplicates the code that was in both FrameSemantics.cc and Model::CanonicalLink. It provides a Link* pointer to the canonical link and its nested name relative to the current model, which is needed in the FrameAttachedToGraph. This function is private to hide :: syntax from libsdformat9, at least until there is a compelling reason to make the API public. A helper function is added to FrameSemantics.cc as a friend of Model so that buildFrameAttachedToGraph can call the private API. That function can't be added directly as a friend since it uses a FrameAttachedToGraph& as an argument, which isn't defined in Model.hh. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Codecov Report
@@ Coverage Diff @@
## sdf9 #341 +/- ##
==========================================
+ Coverage 86.22% 86.25% +0.03%
==========================================
Files 59 59
Lines 9148 9170 +22
==========================================
+ Hits 7888 7910 +22
Misses 1260 1260
Continue to review full report at Codecov.
|
Should resolve #342 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 10 of 10 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @azeey and @scpeters)
test/integration/model_dom.cc, line 349 at r1 (raw file):
ASSERT_NE(nullptr, model->CanonicalLink()); // this reports the local name, not the nested name "nested::link2" EXPECT_EQ("link2", model->CanonicalLink()->Name());
Is there a way to assert that this link belongs to "nested"?
test/integration/model_dom.cc, line 364 at r1 (raw file):
EXPECT_EQ(2u, model->ModelCount()); EXPECT_NE(nullptr, model->ModelByIndex(0)); EXPECT_NE(nullptr, model->ModelByIndex(1));
nit Consider making this more explicit, and more explicitly check parity with ModelByName
?
EXPECT_EQ(model->ModelByName("nested"), model->ModelByIndex(0));
EXPECT_EQ(model->ModelByName("shallow"), model->ModelByIndex(1));
EXPECT_EQ(nullptr, model->ModelByIndex(2));
* Expect CanonicalLink() == ModelByName("nested")->LinkByName("link2") * Match up ModelByName and ModelByIndex expectations Signed-off-by: Steve Peters <scpeters@openrobotics.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 9 of 10 files reviewed, 1 unresolved discussion (waiting on @azeey and @EricCousineau-TRI)
test/integration/model_dom.cc, line 349 at r1 (raw file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
Is there a way to assert that this link belongs to "nested"?
added this expectation in 6c7b3eb
test/integration/model_dom.cc, line 364 at r1 (raw file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
nit Consider making this more explicit, and more explicitly check parity with
ModelByName
?EXPECT_EQ(model->ModelByName("nested"), model->ModelByIndex(0)); EXPECT_EQ(model->ModelByName("shallow"), model->ModelByIndex(1)); EXPECT_EQ(nullptr, model->ModelByIndex(2));
ok, I've added this in 6c7b3eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2, 1 of 1 files at r3.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @azeey)
I tested this PR with gazebosim/gz-physics#66 and gazebosim/gz-sim#258. A model with a nested link and no direct child links now successfully loads in ign-gazebo. Changes look good to me. |
Allow models without links if they have nested models instead. When building FrameAttachedToGraph, if model has no links choose the first link of the first nested model as canonical link instead. A new private function `Model::CanonicalLinkAndRelativeName` is added that provides a `Link*` pointer to the canonical link and its nested name relative to the current model, which is needed in the FrameAttachedToGraph. This private prevents duplicate code in `FrameSemantics.cc` and `Model::CanonicalLink`. The method is private to hide :: syntax from libsdformat9, at least until there is a compelling reason to make the API public. A helper function is added to FrameSemantics.cc as a friend of Model so that buildFrameAttachedToGraph can call the private API. That function can't be added directly as a friend since it uses a `FrameAttachedToGraph&` as an argument, which isn't defined in Model.hh. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Allow models without links if they have nested models instead. When building FrameAttachedToGraph, if model has no links choose the first link of the first nested model as canonical link instead. A new private function `Model::CanonicalLinkAndRelativeName` is added that provides a `Link*` pointer to the canonical link and its nested name relative to the current model, which is needed in the FrameAttachedToGraph. This private prevents duplicate code in `FrameSemantics.cc` and `Model::CanonicalLink`. The method is private to hide :: syntax from libsdformat9, at least until there is a compelling reason to make the API public. A helper function is added to FrameSemantics.cc as a friend of Model so that buildFrameAttachedToGraph can call the private API. That function can't be added directly as a friend since it uses a `FrameAttachedToGraph&` as an argument, which isn't defined in Model.hh. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Allow models without links if they have nested models instead. When building FrameAttachedToGraph, if model has no links choose the first link of the first nested model as canonical link instead. A new private function `Model::CanonicalLinkAndRelativeName` is added that provides a `Link*` pointer to the canonical link and its nested name relative to the current model, which is needed in the FrameAttachedToGraph. This private prevents duplicate code in `FrameSemantics.cc` and `Model::CanonicalLink`. The method is private to hide :: syntax from libsdformat9, at least until there is a compelling reason to make the API public. A helper function is added to FrameSemantics.cc as a friend of Model so that buildFrameAttachedToGraph can call the private API. That function can't be added directly as a friend since it uses a `FrameAttachedToGraph&` as an argument, which isn't defined in Model.hh. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Allow models without links if they have nested models instead. When building FrameAttachedToGraph, if model has no links choose the first link of the first nested model as canonical link instead. A new private function `Model::CanonicalLinkAndRelativeName` is added that provides a `Link*` pointer to the canonical link and its nested name relative to the current model, which is needed in the FrameAttachedToGraph. This private prevents duplicate code in `FrameSemantics.cc` and `Model::CanonicalLink`. The method is private to hide :: syntax from libsdformat9, at least until there is a compelling reason to make the API public. A helper function is added to FrameSemantics.cc as a friend of Model so that buildFrameAttachedToGraph can call the private API. That function can't be added directly as a friend since it uses a `FrameAttachedToGraph&` as an argument, which isn't defined in Model.hh. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Allow models without links if they have nested models instead. When building FrameAttachedToGraph, if model has no links choose the first link of the first nested model as canonical link instead. A new private function `Model::CanonicalLinkAndRelativeName` is added that provides a `Link*` pointer to the canonical link and its nested name relative to the current model, which is needed in the FrameAttachedToGraph. This private prevents duplicate code in `FrameSemantics.cc` and `Model::CanonicalLink`. The method is private to hide :: syntax from libsdformat9, at least until there is a compelling reason to make the API public. A helper function is added to FrameSemantics.cc as a friend of Model so that buildFrameAttachedToGraph can call the private API. That function can't be added directly as a friend since it uses a `FrameAttachedToGraph&` as an argument, which isn't defined in Model.hh. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Allow models without links if they have nested models instead. When building FrameAttachedToGraph, if model has no links choose the first link of the first nested model as canonical link instead. A new private function `Model::CanonicalLinkAndRelativeName` is added that provides a `Link*` pointer to the canonical link and its nested name relative to the current model, which is needed in the FrameAttachedToGraph. This private prevents duplicate code in `FrameSemantics.cc` and `Model::CanonicalLink`. The method is private to hide :: syntax from libsdformat9, at least until there is a compelling reason to make the API public. A helper function is added to FrameSemantics.cc as a friend of Model so that buildFrameAttachedToGraph can call the private API. That function can't be added directly as a friend since it uses a `FrameAttachedToGraph&` as an argument, which isn't defined in Model.hh. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
This is a follow-up to #283 to support some models without direct child links if they contain a nested model with nested links like the following:
Nested canonical links can be used implicitly, but not explicitly since the
::
syntax for referencing across model boundaries will not be supported until SDFormat 1.8.The
FrameAttachedToGraph
does need to store the relative name of a nested canonical link using::
syntax, so a private helper functionModel::CanonicalLinkAndRelativeName
is added that computes this relative name. This helper function is called byModel::CanonicalLink
to avoid code duplication.This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)