ami-iit / jaxsim

A differentiable physics engine and multibody dynamics library for control and robot learning.
https://jaxsim.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
86 stars 11 forks source link

Add possibility to set a base from the `build_from_model_description` method #302

Open CarlottaSartore opened 5 days ago

CarlottaSartore commented 5 days ago

I have seen that it is not possible to set the base from the method build_from_model_description although it is the suggested function for loading a model. It would be useful to allow the user to define any base.

CarlottaSartore commented 5 days ago

I did a first implementation of this in https://github.com/CarlottaSartore/jaxsim/tree/add_base_parameter and I tested it with ergocub, i.e. this model https://github.com/icub-tech-iit/ergocub-software/blob/master/urdf/ergoCub/robots/ergoCubSN001/model.urdf and definite the head as the base link

But it does not work, for instance, if I define head as base, the only links that get parsed are the head and the real sense

the problem seems that the children of the head link contain only the real sense while they should contain other links such as the head imu

the problem seems here

https://github.com/ami-iit/jaxsim/blob/524ad4204e2844bc79c94fd42e22725a349d8a81/src/jaxsim/parsers/kinematic_graph.py#L657-L697

for reference this is the idyntree function that performs the same action :

https://github.com/robotology/idyntree/blob/13cf9e9f0befc6dd08a1b90d21424a043dbf0e48/src/model/src/Model.cpp#L828-L878

flferretti commented 4 days ago

Hi @CarlottaSartore, thanks for working on this! The head and the realsense are the only links parsed because realsense is the only child of the head link. This logic should be changed where the link children are set: https://github.com/ami-iit/jaxsim/blob/524ad4204e2844bc79c94fd42e22725a349d8a81/src/jaxsim/parsers/kinematic_graph.py#L278-L298

In brief, the full ordering of the traversal should be changed, as I guess it's done in iDynTree:

https://github.com/robotology/idyntree/blob/13cf9e9f0befc6dd08a1b90d21424a043dbf0e48/src/model/src/Traversal.cpp#L36-L44