Add import and export of iDynTree::Model from custom iDynTree format idyntree-model-json#1295
Merged
traversaro merged 2 commits intomasterfrom Mar 23, 2026
Merged
Add import and export of iDynTree::Model from custom iDynTree format idyntree-model-json#1295traversaro merged 2 commits intomasterfrom
idyntree-model-json#1295traversaro merged 2 commits intomasterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #1294 .
Whenever we worked with
iDynTree::Model, we frequently have the need to export the state of theiDynTree::Model. This is important especially in environements that are tricky to debug, for example when iDynTree is running inside Creo, as part of https://github.com/icub-tech-iit/creo2urdf .This PR adds the support for import and export of a idyntree-specific .json format, called in the docs, parameters and cli options
idyntree-model-json.Differently from
urdfandsdfformats, the goal of this format is not interoperability with other systems (at least not the main goal) but just to have a reliable direct serialization of exactly the content of aniDynTree::Model.For example, this is how a simple
.urdfmodel is converted, using the newidyntree-model-convertcli tool, added as well in this PR:Click to see the example of URDF to json
{ "additional_frames": [], "collision_solid_shapes": [ { "link_name": "link1", "shapes": [] } ], "default_base_link": "link1", "idyntree_model_json_version": 1, "joints": [], "links": [ { "inertia": { "center_of_mass": [ 0.0, 0.0, 0.0 ], "mass": 1.0, "rotational_inertia_wrt_frame_origin": [ [ 0.01, 0.0, 0.0 ], [ 0.0, 0.01, 0.0 ], [ 0.0, 0.0, 0.01 ] ] }, "name": "link1" } ], "sensors": [], "visual_solid_shapes": [ { "link_name": "link1", "shapes": [ { "has_material": true, "has_name": false, "length": 0.6, "link_H_geometry": { "position": [ 0.0, 0.0, 0.0 ], "rotation_matrix": [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] }, "material": { "color": [ 0.0, 0.0, 0.8, 1.0 ], "has_color": true, "has_texture": false, "name": "" }, "radius": 0.2, "type": "cylinder" } ] } ] }This permits to easily export any kind of
iDynTree::Modelwithout having to deal with the specific limitations of the specific file format.Note: the format is by definition quite related to the iDynTree internals, and can change without backward compatibility from one version of iDynTree to another. The specific format version is tracked by the
idyntree_model_json_versiontop level json attribute.The
nlohmann_jsonC++ dependency has been added to permit to import and export the.jsonfiles, the support for it is controlled via theIDYNTREE_USES_NLOHMANN_JSONoption.As it frequently happens with Agent-assisted coding, the amount of code in the PR may be challenging for review. For this reason, I strongly suggest any reviewer interested in the PR to ignore the
src/model_io/codecs/src/ModelJSONImportExport.cppimport/export code, and instead check out the important test code, that is the one that actually ensures that everything works as expected.