[rqt_jtc] Use urdf_parser_py#2254
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2254 +/- ##
==========================================
+ Coverage 84.68% 84.78% +0.10%
==========================================
Files 153 153
Lines 15319 15224 -95
Branches 1332 1315 -17
==========================================
- Hits 12973 12908 -65
+ Misses 1858 1841 -17
+ Partials 488 475 -13
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
christophfroehlich
left a comment
There was a problem hiding this comment.
Thank you! I think it is time for adding unittest with #2253 first, then it's easier to check if this PR is not causing any troubles.
| robot = xml.dom.minidom.parseString(description).getElementsByTagName("robot")[0] | ||
| try: | ||
| # urdf_parser_py does not recognize non-URDF tags such as | ||
| # <ros2_control> and raises an AssertionError. |
There was a problem hiding this comment.
are <gazebo> tags fine here?
There was a problem hiding this comment.
I checked it, in the the current minidom implementation <gazebo> tags are fine because the parser only looks at localName == "joint" nodes — everything else is silently skipped.
But you're right that in this PR , only <ros2_control> is being stripped. I hit that error when testing with ros2_control_demos so I stripped it specifically.
There was a problem hiding this comment.
I am thinking to update it to use a whitelist of known URDF tags (link, joint, transmission, etc) and strip everything else — that way <gazebo> and any other non-standard tags are handled automatically without needing to list them one by one.
Is this a good approach to go?
Closes #891
Description
This PR replaces the manual XML DOM parsing in
joint_limits_urdf.pywithurdf_parser_py.urdf.Robot, resolving the long-standing TODO in the code.This is a fresh implementation inspired by the stale PR #1982. It incorporates the review feedback and also fixes an additional bug that was not handled in that earlier attempt.
Why this change?
The previous implementation used
xml.dom.minidomto manually parse URDF XML, extract attributes, and handle missing values using exceptions. This approach was fragile and unnecessarily complex.The code already had a TODO suggesting migration to
urdf_parser_py, but an earlier attempt failed due to:Required attribute not set in XML: upper.This issue has now been resolved in newer versions ofurdf_parser_py, making the migration possible.What changed?
joint_limits_urdf.pyReplaced manual XML parsing (
xml.dom.minidom) withurdf_parser_py(using
Robot.from_xml_string()androbot.joints)Added preprocessing to remove
<ros2_control>tags before parsing(needed because
urdf_parser_pythrows an error on unknown tags)Fixed how missing joint limits are handled
0.0minval >= maxvalRemoved the old TODO comment.
package.xmlHow to reproduce and test
Setup with RRBot example 1
Expected output should show:
joint_trajectory_position_controllerasactivejoint_state_broadcasterasactiveforward_position_controllerasinactiveLaunch the GUI
# Terminal 3 ros2 run rqt_joint_trajectory_controller rqt_joint_trajectory_controllerExpected behavior
After this PR
urdf_parser_py.