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

Unflatten flattened models #504

Merged
merged 14 commits into from
Mar 18, 2021
Merged

Unflatten flattened models #504

merged 14 commits into from
Mar 18, 2021

Conversation

jennuine
Copy link
Collaborator

@jennuine jennuine commented Mar 3, 2021

Closes #411

Summary

Implemented conversion from SDFormat 1.7 to 1.8 which takes the flattened XML and infers when a new model should be created/unflattened.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Code check passed (In source directory, run sh tools/code_check.sh)
  • 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: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
@jennuine jennuine requested a review from azeey March 3, 2021 22:18
@github-actions github-actions bot added the 🏢 edifice Ignition Edifice label Mar 3, 2021
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
@jennuine jennuine marked this pull request as ready for review March 5, 2021 01:32
Copy link
Collaborator

@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.

Did a first pass. Looks pretty good! I left some comments related to performance and handling more SDFormat tags in //model.

sdf/1.8/1_7.convert Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
Copy link
Collaborator

@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.

There are some test failures in INTEGRATION_nested_model. Could you update the todos and test expectations in NestedModel.PartiallyFlattened can be to account for the changes in this PR?

src/Converter.cc Show resolved Hide resolved
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
@jennuine
Copy link
Collaborator Author

jennuine commented Mar 9, 2021

There are some test failures in INTEGRATION_nested_model. Could you update the todos and test expectations in NestedModel.PartiallyFlattened can be to account for the changes in this PR?

Done a1006ad

Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
@codecov-io
Copy link

codecov-io commented Mar 10, 2021

Codecov Report

Merging #504 (33dda02) into master (3fb5312) will increase coverage by 0.09%.
The diff coverage is 94.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #504      +/-   ##
==========================================
+ Coverage   87.81%   87.90%   +0.09%     
==========================================
  Files          66       66              
  Lines        9321     9458     +137     
==========================================
+ Hits         8185     8314     +129     
- Misses       1136     1144       +8     
Impacted Files Coverage Δ
src/Converter.cc 92.27% <94.16%> (+0.70%) ⬆️

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 3fb5312...33dda02. Read the comment docs.

test/integration/nested_model.cc Show resolved Hide resolved
test/integration/nested_model.cc Show resolved Hide resolved
test/integration/nested_model.cc Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Show resolved Hide resolved
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
(elemName != "frame" && elemName != "joint" &&
elemName != "link" && elemName != "model"))
{
if (elemName != "gripper")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Can this if condition go into the parent if statement? If not, can you add a comment why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I left a comment for why: dce6828

Did some testing and //gripper/@name doesn't get flattened but //gripper/gripper_link and //griper/palm_link do. The parent if statement returns true because //gripper/@name doesn't contain newModelName

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm surprised that //gripper/@name is not flattened. I'm guessing it's a bug. I like your approach of checking if //gripper/gripper_link has the model name prefix. To future proof this a little bit, when we determine the gripper needs to be moved to a child model, we can check if //gripper/@name has the model prefix and strip it. This would ensure that this would continue to work if someone fixes the flattening at some point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How's this? 3e0cd5d

src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Show resolved Hide resolved
Copy link
Collaborator

@EricCousineau-TRI EricCousineau-TRI 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 thus far! Added some nits and some minor blockers in addition to Addisu's comments.

src/Converter.cc Outdated

/////////////////////////////////////////////////
// TODO(jenn) delete, used for debugging
std::string PrintElement(const tinyxml2::XMLElement *_elem)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit Perhaps this is useful to keep around? Perhaps implement using a trace or debug logging level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PrintElement is now ElementToString put in XmlUtils.cc: 9ed2713

@@ -1,3 +1,9 @@
<convert name="sdf">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Blocking item: Should remove debug-based shims. (Just putting it here for review-based tracking)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed 3e0cd5d

src/Converter.cc Outdated

if (elemAttrName.empty() ||
elemAttrName.compare(0, _newNameIdx - 2, newModelName) != 0 ||
(elemName != "frame" && elemName != "joint" &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit This set of if checks are repeated; intent isn't clear due to repetition.

Can you give it semantics and wrap it? e.g. bool IsInterfaceElement(elem) { return elemName == "asdf" || ...; }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/Converter.cc Outdated
elemAttrName = elem->Attribute("name");

if (elemAttrName.empty() ||
elemAttrName.compare(0, _newNameIdx - 2, newModelName) != 0 ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit _newNameIdx has semantics, but they aren't clear. Also, this term is repeated.

Perhaps state something like this?

const size_t kSeparatorLen = 2;  // "::"
size_t possibleParentNameIdx = _newNameIdx - kSeparatorLen;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, you may want to consider making str.compare(0, posibleParentNameIdx) a bit more robust, and use a more focused function to name splitting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How's this? I've updated _newNameIdx to be _childNameIdx. Also, instead of using _newNameIdx - 2 it uses size_t newModelNameSize = newModelName.size(): 9ed2713

Copy link
Collaborator

Choose a reason for hiding this comment

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

Excellent, thanks!

src/Converter.cc Outdated
tinyxml2::XMLElement *e = elem->FirstChildElement("parent");
std::string eText = e->GetText();

SDF_ASSERT(eText.compare(0, _newNameIdx - 2, newModelName) == 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rule of 3 on _newNameIdx - 2: Raising to defect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

xmlDoc.Clear();
xmlDoc.Parse(xmlString.c_str());

sdf::Converter::Convert(&xmlDoc, &convertXmlDoc);
Copy link
Collaborator

Choose a reason for hiding this comment

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

For readability, could you also add a mutliline test on generated XML?

While the below EXPECT* statements reallllly drill into semantics, it makes it a tad harder to quickly assess that the spec example is fully represented w/ this implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
@jennuine jennuine changed the title Unnesting flattened models Unflatten flattened models Mar 12, 2021
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
@chapulina chapulina added the beta Targeting beta release of upcoming collection label Mar 18, 2021
Copy link
Collaborator

@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.

This is really close! Just a few more minor comments

src/Converter.hh Outdated Show resolved Hide resolved
(elemName != "frame" && elemName != "joint" &&
elemName != "link" && elemName != "model"))
{
if (elemName != "gripper")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm surprised that //gripper/@name is not flattened. I'm guessing it's a bug. I like your approach of checking if //gripper/gripper_link has the model name prefix. To future proof this a little bit, when we determine the gripper needs to be moved to a child model, we can check if //gripper/@name has the model prefix and strip it. This would ensure that this would continue to work if someone fixes the flattening at some point.

src/Converter.cc Outdated Show resolved Hide resolved
src/Converter_TEST.cc Outdated Show resolved Hide resolved
src/Converter_TEST.cc Outdated Show resolved Hide resolved
src/Converter_TEST.cc Show resolved Hide resolved
test/integration/converter.cc Outdated Show resolved Hide resolved
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Copy link
Collaborator

@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.

This looks great! Thanks for iterating.

@jennuine jennuine merged commit 1333f59 into master Mar 18, 2021
@jennuine jennuine deleted the jennuine/unnesting branch March 18, 2021 23:10
@EricCousineau-TRI
Copy link
Collaborator

Indeed! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Targeting beta release of upcoming collection 🏢 edifice Ignition Edifice
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should implement unflattening per propsal
5 participants