stack-of-tasks / pinocchio

A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
http://stack-of-tasks.github.io/pinocchio/
BSD 2-Clause "Simplified" License
1.89k stars 392 forks source link

model.nbodies != number of body frames #1597

Closed JonathanKuelz closed 2 years ago

JonathanKuelz commented 2 years ago

Hello, this is issue is partly issue, but also a question:

while playing around with runtime modification of pinocchio models in Python (see #1591 ), I realized that the model parameter nbodies is not equal to the number of body frames. At first I thought this could be explained by multiple frames being attached to a single body (could imagine reasons for that). However, seeing that the methods existBodyName and getBodyId work on a frame basis (as opposed to joints, where the joint ID is not coupled with the joint frame), I am confused about what exactly a body in pinocchio is.

As example, here are the body frame names from a model representing a Universal Robot (UR5) I loaded from URDF: ['world', 'base_link', 'base', 'shoulder_link', 'upper_arm_link', 'forearm_link', 'wrist_1_link', 'wrist_2_link', 'wrist_3_link', 'ee_link', 'tool0']

11 names, model.existBodyName(N) returns true for every name N in this list. (model.getBodyID() works for all of them aswell)

However, model.nbodies = 7 (number of inertias: also 7)

As far as I understand it, there are two "representations" of bodies in a robot model: The "real bodies", which are added using appendBodyToJoint() and then used for dynamic calculations - and the "body frames". However, for me the separation is not really clear. It would be kind if you could help me by either telling me how my described understanding is wrong, or giving me a hint how to deal with the following questions:

Help would be greatly aprreciated, thanks in advance!

jcarpent commented 2 years ago

Bodies are indeed physical bodies defined by spatial inertia. Both existBodyName and getBodyIdoperates from Frame with BODY type.

For real applications, you don't really need the notion of nbodies which is a counter incremented when calling addBodyToJoint. In Pinocchio, we cumulate the body inertia to the inertia supported by a given joint.

In addition in Pinocchio, if you append a BODY frame (via addFrame) with an inertia, then this latest will be added to the joint inertia supporting the given frame.

Hope it this answer will be help you.

JonathanKuelz commented 2 years ago

Thanks, so could wrap it up as follows: nbodies is a helper that's not really necessary, inertias are updated automatically when adding a frame and "one body, one frame" more or less sums it up.

Assuming that's right, I'm gonna close this issue as this allows me to continue working with bodies in the model 👍🏾