-
Notifications
You must be signed in to change notification settings - Fork 95
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
Conversation
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@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.
Did a first pass. Looks pretty good! I left some comments related to performance and handling more SDFormat tags in //model
.
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.
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?
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
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 Report
@@ 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
Continue to review full report at Codecov.
|
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") |
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.
nit: Can this if condition go into the parent if statement? If not, can you add a comment why?
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.
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
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.
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.
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.
How's this? 3e0cd5d
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.
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) |
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.
nit Perhaps this is useful to keep around? Perhaps implement using a trace or debug logging level?
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.
PrintElement
is now ElementToString
put in XmlUtils.cc
: 9ed2713
@@ -1,3 +1,9 @@ | |||
<convert name="sdf"> |
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.
Blocking item: Should remove debug-based shims. (Just putting it here for review-based tracking)
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.
Removed 3e0cd5d
src/Converter.cc
Outdated
|
||
if (elemAttrName.empty() || | ||
elemAttrName.compare(0, _newNameIdx - 2, newModelName) != 0 || | ||
(elemName != "frame" && elemName != "joint" && |
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.
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" || ...; }
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.
src/Converter.cc
Outdated
elemAttrName = elem->Attribute("name"); | ||
|
||
if (elemAttrName.empty() || | ||
elemAttrName.compare(0, _newNameIdx - 2, newModelName) != 0 || |
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.
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;
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.
Alternatively, you may want to consider making str.compare(0, posibleParentNameIdx)
a bit more robust, and use a more focused function to name splitting?
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.
How's this? I've updated _newNameIdx
to be _childNameIdx
. Also, instead of using _newNameIdx - 2
it uses size_t newModelNameSize = newModelName.size()
: 9ed2713
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.
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, |
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.
Rule of 3 on _newNameIdx - 2
: Raising to defect.
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.
xmlDoc.Clear(); | ||
xmlDoc.Parse(xmlString.c_str()); | ||
|
||
sdf::Converter::Convert(&xmlDoc, &convertXmlDoc); |
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.
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.
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.
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@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.
This is really close! Just a few more minor comments
(elemName != "frame" && elemName != "joint" && | ||
elemName != "link" && elemName != "model")) | ||
{ | ||
if (elemName != "gripper") |
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.
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.
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@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.
This looks great! Thanks for iterating.
Indeed! Thank you! |
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
sh tools/code_check.sh
)another open pull request
to support the maintainers
Note to maintainers: Remember to use Squash-Merge