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

Refactor FrameSemantics.cc #764

Merged
merged 14 commits into from
Dec 20, 2021
Merged

Conversation

azeey
Copy link
Collaborator

@azeey azeey commented Nov 30, 2021

🎉 New feature

Summary

The buildFrameAttachedToGraph and buildPoseRelativeToGraph have overloads for the type of parent element, but the code in each overload is very similar to each other. This PR refactors these functions so there's less code duplication.

Note: There is one small change in behavior due to the order in which default edges are added. Before this PR, the default edges were added while adding vertices while in this PR all vertices are added first and then all edges are added. The resulting change is only manifested in the graph output (ign sdf -g) which is only there for development/debugging purposes.

Toward #658

Test it

Checklist

  • Signed all commits for DCO
  • Added tests
  • [ ] Added example and/or tutorial
  • Updated documentation (as needed)
  • [ ] Updated migration guide (as needed)
  • 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

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@azeey azeey requested a review from jennuine November 30, 2021 23:18
@azeey azeey requested a review from scpeters as a code owner November 30, 2021 23:18
@azeey azeey self-assigned this Nov 30, 2021
@github-actions github-actions bot added 🌱 garden Ignition Garden 🏯 fortress Ignition Fortress labels Nov 30, 2021
@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2021

Codecov Report

Merging #764 (1c1b4c4) into sdf12 (ef48530) will increase coverage by 0.96%.
The diff coverage is 93.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##            sdf12     #764      +/-   ##
==========================================
+ Coverage   89.60%   90.57%   +0.96%     
==========================================
  Files          78       78              
  Lines       12691    12336     -355     
==========================================
- Hits        11372    11173     -199     
+ Misses       1319     1163     -156     
Impacted Files Coverage Δ
src/FrameSemantics.cc 83.06% <93.48%> (+9.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef48530...1c1b4c4. Read the comment docs.

Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

just started looking at this; here's what I've noticed so far

src/FrameSemantics.hh Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
azeey and others added 4 commits December 1, 2021 15:17
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

ok, I think I've reviewed all except addIncludedInterfaceModelEdgesToPoseRelativeToGraph

I'll resume later

src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
@EricCousineau-TRI
Copy link
Collaborator

EricCousineau-TRI commented Dec 2, 2021

Per VC, consider having an (internal / private) base class. e.g. FrameBase -> {Frame, InterfaceFrame} (is-a); however, may break ABI.
Alternative, use has-a, some facade class.

Perhaps better is to produce InterfaceModel (possibly InterfaceWorld too) as the facade.

@azeey azeey marked this pull request as draft December 2, 2021 19:51
@azeey
Copy link
Collaborator Author

azeey commented Dec 2, 2021

Converted to a draft to explore use of Interface elements for all frame building logic. @scpeters , @jennuine please hold off on reviewing until I put this back as ready for review.

@azeey
Copy link
Collaborator Author

azeey commented Dec 6, 2021

The issue with trying to use only Interface elements for building frame graphs is they only provide a subset of functions needed for building the graph. For example, sdf::InterfaceLink currently has sdf::InterfaceLink::PoseInModelFrame which limits the possibility of using other frames as @relative_to for the pose of the link. However, sdf::Link has sdf::Link::RawPose and sdf::Link::PoseRelativeTo. Creating an sdf::InterfaceLink from the information contained in an sdf::Link, in the current state of sdf::InterfaceLink, is impossible because we have to provide sdf::InterfaceLink with its pose relative to its model frame, but if the sdf::Link's pose is relative to another frame, we'd have to resolve the pose, which we can't do until the pose graph is built. We can add sdf::InterfaceLink::RawPose andsdf::InterfaceLink::PoseRelativeTo, and change the constructor to take a relativeTo argument, but that would make sdf::InterfaceLink::PoseInModelFrame invalid as it cannot return the pose relative to the model frame.

So the approach I'm thinking of is to create wrapper structs for all elements and use those wrappers in the build* functions.
For example, a wrapper for sdf::Link and sdf::InterfaceLink would be the following:

struct LinkWrapper
{
  explicit LinkWrapper(const sdf::Link &_link)
      : name(_link.Name()),
        rawPose(_link.RawPose()),
        poseRelativeTo(_link.PoseRelativeTo()),
        elementType("Link"),
        frameType(FrameType::LINK)

  {
  }

  explicit LinkWrapper(const sdf::InterfaceLink &_ifaceLink)
      : name(_ifaceLink.Name()),
        rawPose(_ifaceLink.PoseInModelFrame()),
        poseRelativeTo("__model__"),
        elementType("Interface Link"),
        frameType(FrameType::LINK)
  {
  }

  std::string name;
  ignition::math::Pose3d rawPose;
  std::string poseRelativeTo;
  std::string elementType;
  FrameType frameType;
};

The build* functions can then use the members name, rawPose, etc. I'm opting for using a member variables directly instead of getters to limit verbosity. These wrappers would all be in FrameSemantics.cc so we won't have any issue of API/ABI stability.

…ace elements

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
…eToGraph

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@azeey azeey marked this pull request as ready for review December 15, 2021 05:19
@azeey
Copy link
Collaborator Author

azeey commented Dec 15, 2021

This is now ready for review.

src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
src/FrameSemantics.cc Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Copy link
Collaborator

@jennuine jennuine left a comment

Choose a reason for hiding this comment

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

LGTM, maybe @scpeters can take a second look?

@scpeters
Copy link
Member

LGTM, maybe @scpeters can take a second look?

I'm looking right now

Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

just a few minor comments. It looks great, nice work removing all this duplicate code!

src/FrameSemantics.cc Show resolved Hide resolved
if (!_model)
{
errors.push_back({ErrorCode::ELEMENT_INVALID,
"Invalid sdf::Model pointer."});
return errors;
Copy link
Member

Choose a reason for hiding this comment

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

I think this error block has been dropped during this refactor

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added it back in 8572ccb, but I'm not sure if we need it anymore, especially now that we are adding more APIs to programmatically create DOM objects. The Element() member function of those objects will always return a nullptr, but I think we should still be able to build frame graphs for them. Perhaps we can address that in a follow up PR.

src/FrameSemantics.cc Show resolved Hide resolved
src/FrameSemantics.cc Outdated Show resolved Hide resolved
azeey and others added 2 commits December 18, 2021 09:25
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/new-ignition-releases-2022-04-13-fortress-edifice/1367/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏯 fortress Ignition Fortress 🌱 garden Ignition Garden
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants