Rhoban / onshape-to-robot

Converting OnShape assembly to robot definition (SDF or URDF) through OnShape API
MIT License
231 stars 49 forks source link

Refactor: use JSON/Python Dict as an intermediary representation before exporting to URDF file #111

Closed T-K-233 closed 9 months ago

T-K-233 commented 9 months ago

Often times in ROS we require a specific order of joints. The current onshape-to-robot builds XML on the fly when parsing the Onshape model, which makes changing the order of fields impossible.

This PR proposes that instead of generating XML line-by-line, the program first parses the Onshape model into a GData-formatted JSON/Python Dict data format, and then exports the XML file at the last step. This enables adding, changing, and re-ordering robot configuration fields per user's request.

Gregwar commented 9 months ago

Hello,

Before I review this I need to understand the use case

I happened to post-process some onshape-to-robot exported URDF already using Python XML parser to tweak a few things, why do you say that changing the URDF afterhand is "impossible"? Can you give an example of something that is possible to do while exporting and not by post-processing the URDF produced?

T-K-233 commented 9 months ago

Hello Gregwar,

Thank you for your fast reply. To clarify, this PR is still under active change and is not yet ready for review.

I do understand that it is possible to post-process the XML with Python parser to tweak things. However, this approach can sometimes be less reliable and may not fully capture all the intricacies of the original model. (e.g. when having multiple bodies with the same name, the tool will dump the STL file to a single filename, and multiple linkage will point to this STL file. However, the origin of the bodies may not be the same, which results in weird offset in the URDF visualization; e.g.2 if the user wants to change the number of precision digits of the transforms).

Additionally, in our ongoing efforts, we are working on enhancing this tool by introducing support for MJCF format alongside URDF and SDF. By doing so, we aim to provide a more comprehensive solution to the robotics research community. With support to three formats (MJCF, URDF, SDF), having an intermediary representation to parse the onshape model into will facilitate a cleaner and more streamlined workflow. After parsing, the program can then proceed to dump to user's selection of model file format, ensuring a more robust and versatile experience.

Thank you. I hope I have cleared things out.