-
Notifications
You must be signed in to change notification settings - Fork 70
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
Changed URDF parser to use Gnome libxml2 instead of TinyXML #460
Changed URDF parser to use Gnome libxml2 instead of TinyXML #460
Conversation
I think we should take the occasion to generate a Windows installer for libxml2 and dependencies using |
@traversaro focus first on the design. Feel free to comment. There are a couple of pending todos, but they are more for future development (as even without those, we should have feature-parity with the previous version). Lastly, given how important the model parsing is for the robot controllers, this PR should be thoroughly tested on the robots (as the unit tests do not cover enough the code) |
@francesco-romano is not highlighting the best feature of this new parser. If we take one of our models from icub-models, and we insert a small xml syntax error, such as : diff --git a/iCub/robots/iCubGenova04/model.urdf b/iCub/robots/iCubGenova04/model.urdf
index 3973b4c..09a2110 100644
--- a/iCub/robots/iCubGenova04/model.urdf
+++ b/iCub/robots/iCubGenova04/model.urdf
@@ -1202,7 +1202,7 @@
<child link="r_forearm_skin_19"/>
<dynamics damping="0.1"/>
</joint>
- <link name="r_forearm_skin_22"/>
+ <link name="r_forearm_skin_22">
<joint name="r_forearm_skin_22_fixed_joint" type="fixed">
<origin xyz="-0.0544173950421 -0.0287223 0.0306037516609" rpy="-1.2658242728 -0.234328151379 3.04788317971"/>
<parent link="r_forearm"/> This is the output of the old TinyXML-based parser:
No indication of the kind of error, beside "Invalid XML" (that is quite useless if you deal with a 3K lines XML file such as https://github.com/robotology/icub-models/blob/master/iCub/robots/iCubGenova04/model.urdf).
There is an exact indication of the wrong line, so it is trivial to fix the problem.
|
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. amazing. Thanks @francesco-romano! 🎉
I couldn't review all the details, but I like a lot the entire architecture, no major concerns about it. Not a big fan on indented cpps with namespaces tho, especially on new code.
When I dug into libxml2 some while ago, I found its usage a bit messy. However, it is one of the only xml feature-complete parser with a really open license. Well done!
Approving despite the minor comments.
cc @lucaTagliapietra This is exactly the pattern I was telling you about element callbacks for our qt-based parser.
* @param name name of the element to create | ||
* @return a new parser element for the corresponding tag | ||
*/ | ||
virtual std::shared_ptr<XMLElement> rootElementForName(const std::string& name); |
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.
ForName
sounds a bit odd, maybe FromName
would be better?
* @param name name of the element to create | ||
* @return a new parser element for the corresponding tag | ||
*/ | ||
virtual std::shared_ptr<XMLElement> childElementForName(const std::string& name); |
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.
Same as above.
My fault, I want to do a general clang_format cleanup (using https://github.com/robotology-playground/clang-format) of iDynTree codebase as soon as we merge the pending PRs . |
Meta-comments about the CMake structure:
|
I will answers here to the comments:
PS: @traversaro try the validation agains an XSD. That is much better than the "normal" parser error :D |
I am pushing some properly deprecated headers for all the public symbols of the old class. Once we done that, I think it is safe to just delete the old library. |
418e24d
to
a0843d8
Compare
Travis (on my branch) seems happy now. |
Things missing:
|
@traversaro Can you give me access rights for the repo? For the time being I don't have hands on the robot, so I will try to test the pull request on Gazebo first (also because safety first :)) as suggested by @francesco-romano . |
I'll help @ahmadgazar test this. |
Me and @fjandrad tested the pull request locally on my pc in Gazebo for yoga++, and everything seem to be working just fine. We will be testing it on a physical iCub for a final confirmation. |
We have tested the PR on a physical iCub doing yoga++, and it has done all the yoga completely without problems. However, by adding external perturbations on the arms the robot was unable to get back to it's home position. We suspect though that this behavior has nothing to do with the changes done on the PR (someone can correct me if I am wrong). |
I performed an extra check using a simpler urdf ( the one from iCalibrate. But with the new parser I get: Since it actually changes the behavior of the FT estimation I would hold this PR until we understand why or what it changes. Update: I reverted the merge and tested again to see if the merge somehow messed it up but I got the same result. |
Thanks guys for the work. |
It may be worth to add the problematic model to https://github.com/robotology/idyntree/blob/master/src/tests/data/testModels.h.in#L28 . |
I'll do it. Send me the urdf first so that I can run some tests on it. |
This is the model I used to get those plots. Had to change to txt to upload but is urdf. |
Thanks @fjandrad |
After @traversaro pointed out that the joint order might be different for the parser and that I needed to either set a desired order through model loader or make the mapping in the code, I ran a test with and without the ordering to check.
The original order was :
Using the model loader solved the issue correctly. So the problem was in my code and not the use of the new parser itself. Sorry for the trouble. |
a0843d8
to
95f95a5
Compare
Thanks @fjandrad For a correct workflow there are two options:
|
Yes, this has always been the intended behavior at least. |
Tests are still passing, but this should correctly test the force due to the acceleration
4eb05e7
to
e618a0c
Compare
This is a SAX2 based XML parsing. It supports XSD 1.0 schema validation. Based on the C interface of http://xmlsoft.org
Test files should allow to test the following: - proper schema validation - validation of well-formed XML - failure of parsing of non well-formed XML - failure of validating well-formed XML (not conforming to XSD)
We should use the C++14 [[deprecated]] attributes. Unfortunately they have some issues with SWIG, see robotology#461 Using IDYNTREE_DEPRECATED for now
e618a0c
to
e6e3798
Compare
…xml2) to AppVeyor
ec8721f
to
b023534
Compare
Thanks @francesco-romano ! |
Hello again iDynTree devs, Context Now that you changed the embedded So far the negative points against
Positive points about libxml2: it supports XSD validation... (!) Now Tinyxml2 : https://github.com/leethomason/tinyxml2 So here's my question :
I saw in the Thanks for your help, idyntree is great ! |
Hi @ahoarau, sorry for the short response, hopefully I will reply more in depth during the weekend. Clearly the downside is the additional external dependency, but I think there are proper solution to most of the point you raise, I will answer on that in the weekend. We tried to preemptive address some of those issues as discussed in robotology/community#316 .
I am a bit afraid that having a double backed for |
I understand the need to have a tool to check the XML correctness. According to tinyxml2, it only reports line numbers :
I would still use this very lightweight/c++/embeddable library in the code, but print a message in case of errors saying :
That would be my last point about this change. Sorry for the winning. Meanwhile, I integrated libxml2 as a sub_dir thanks to the cmake example you showed me: This is a very ugly integration, as I had to trim the library, generate files via autoconf on linux/macOS, and copy them. Not very scalable but it seems to work. |
Even if TinyXML is one of the most widespread XML libraries around, it is functionally very limited, and no more maintained, not even for security/bug fixes.
This PR changes the URDF parser of iDynTree to use Gnome libxml2, a C-based XML parser.
The old library has been backed-up in
idyntree-modelio-urdf-legacy
in case we want to keep it around for some time. Given that the new library should be a drop-in replacement of the old one, hopefully (modulo bugs) nobody should see any difference.A new library,
idyntree-modelio-xml
has been created (that depends onlibxml2
). This library supports generic XML parsing (of course the output is a tree of XML elements) and XSD 1.0 validation support. The latter can be useful for configuration files (even if I still think that we should strive to have XSD as much as possible) or other simple XML files.The updated
idyntree-modelio-urdf
depends onidyntree-modelio-xml
and adapts the generated tree to create aModel
andSensorsList
objects.