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.78k stars 375 forks source link

Best way to compute forward dynamics and M inverse #1215

Closed andreadelprete closed 4 years ago

andreadelprete commented 4 years ago

Hi,

it seems that pinocchio offers different ways to compute forward dynamics and M inverse. For the forward dynamics we have:

For computing M inverse instead we have:

jcarpent commented 4 years ago

To quickly answer your question and according to Analytical Derivatives of Rigid Body Dynamics Algorithms, the direct computation of Minv is much faster than all the other approaches:

If you just want to perform the operation Minv times a vector, then you should privilege the Cholesky decomposition, because, you don't need the full expression of the Mass Matrix inverse. I would say, you just need the full expression when you do matrix-matrix operations, e.g. when computing derivatives.

andreadelprete commented 4 years ago

Thanks for the answer @jcarpent ! I didn't know that paper also dealt with the computation of M inverse, but it actually makes a lot of sense because that's the derivative of the dynamics w.r.t. the control!

In my case I need to compute the whole matrix J*Minv*J because then I have to compute a matrix exponential with that. The Jacobian J is the contact Jacobian with 3k rows, with k being the number of contacts, so typically 3k is (slightly) smaller than nv (size of M), such as 3k=12 and nv=18. According to you suggestions I should then use computeMinverse. Do you confirm?

jcarpent commented 4 years ago

For getting this matrix, I would suggest taking insparition from this code: https://github.com/stack-of-tasks/pinocchio/blob/ada5b11e5881e3fbc28e3bac717075ed8fa6855c/src/algorithm/contact-dynamics.hxx#L39

andreadelprete commented 4 years ago

Thanks @jcarpent , but before you wrote

if you've already computed the forward dynamics (via ABA), then you should prefer the call to computeMinverse

Instead, in the code of contact-dynamics.hxx you're using Cholesky. Since I have to call ABA, and I don't need M, I thought computeMinverse would be the best option.

jcarpent commented 4 years ago

I will close this issue. @andreadelprete Feel free to reopen it when needed.