robotology / idyntree

Multibody Dynamics Library designed for Free Floating Robots
BSD 3-Clause "New" or "Revised" License
177 stars 67 forks source link

Centroidal bias acceleration method is missing #474

Open GiulioRomualdi opened 6 years ago

GiulioRomualdi commented 6 years ago

To implement the task-based torque control I need to evaluate the centroidal bias acceleration, however, the KinDynComputation class seems not providing any method to get this quantity.

More specifically only the angular part of the centroidal bias acceleration is missing indeed the linear one is evaluated by the KinDynComputations::getCenterOfMassBiasAcc() method.

traversaro commented 6 years ago

~Note: to read this issue you need to have some browser plugin that renders LaTeX text in GitHub comments, such as https://github.com/traversaro/github-mathjax-firefox or https://chrome.google.com/webstore/detail/github-with-mathjax/ioemnmodlmafdkllaclgeombjnmnbima), sorry for the trouble.~

I suspect this will be easier that I expected, given that we already have the ComputeLinearAndAngularMomentumDerivativeBias. This is an important piece for this computation, because let's call $J_{ {}_A \mathrm{h}} \in \mathbb{R}^6 \times \mathbb{R}^{6+n}$ the "jacobian" of the linear and angular momentum of the robot expressed in the inertial frame $A$:

{}_A \mathrm{h} = J_{ {}_A \mathrm{h} } \nu

Its derivative will be

{}_A \dot{\mathrm{h}} =  J_{ {}_A \mathrm{h} } \dot{\nu} +  \dot{J}_{{}_A \mathrm{h} }\nu

the ComputeLinearAndAngularMomentumDerivativeBias should compute $\dot{J}_{{}_A \mathrm{h} }\~\nu$ (but I still need to double check), and this can be used for computing the centroidal average angular velocity bias acceleration.

traversaro commented 6 years ago

The non-obvious thing to derive is the composite/locked rotational inertia of whole mechanical system. Basically we have the mixed centroidal angular velocity ${}^{G[A]} \mathrm{v}_G$ is defined, with an abuse of notation (https://traversaro.github.io/preprints/traversaro-phd-thesis.pdf, Section 3.9.3):

{}^{G[A]} \mathrm{v}_G =  ({}_{G[A]} \mathbb{M}^C)^{-1} {}_{G[A]} X^{A} {}_A \mathrm{h}

The matrices involved in this computation are listed in the following.

{}_{G[A]} \mathbb{M}^C = 
\begin{bmatrix}
m^C  1_3 & 0_{3 \times 3} \newline
0_{3 \times 3} & {}_{G[A]} I^C 
\end{bmatrix}

where $m \in \mathbb{R}$ is the total mass of the robot, $13 \in \mathbb{R}^{3 \times 3}$ is the identity matrix, and $ {}{G[A]} I^C $ is the 3D rotational inertia, expressed with the orientation of the inertial frame $A$ and w.r.t. to the center of mass of the system.

Given the nice structure (for the linear part) of the centroidal composite rigid body inertia and the co-adjoint transform, the acceleration of the linear part of the of the centroidal average 6D velocity can be easily expressed as:

{}^{G[A]} \mathrm{v}\_G^{l} = m {}\_A \mathrm{h}^l  

assuming (as usual) that the mass of each link of the multibody system is constant, also the total mass of the multibody system is constant, and so we have that:

{}^{G[A]} \dot{\mathrm{v}}\_G^{l} = m {}\_A \dot{\mathrm{h}}^l  =  J\_{ {}\_A \mathrm{h} }^l \dot{\nu} +  \dot{J}\_{{}\_A \mathrm{h} }^l \~\nu

and so the bias acc is clearly just $\dot{J}_{{}_A \mathrm{h} }^l \~\nu$. For the angular part unfortunately the solution is not so easy, because the angular part of ${}^{G[A]} \mathrm{v}_G$ (${}^{G[A]} \mathrm{v}_G^{l}$) depends in a non trivial way from both the angular and linear part of ${}_A \mathrm{h}$ (due to the co-adjoint transform $ {}_{G[A]} X^{A}$) and on the inverse of the 3D composite rotational inertia (due to the inverse of ${}_{G[A]} \mathbb{M}^C$). In my experience, when the linear and angular part of a computation are coupled, it is better to stick to the 6D formulation to obtain a readable result.

In this case, if we have that the centroidal angular velocity is defined as:

{}^{G[A]} \mathrm{v}\_G =  ({}\_{G[A]} \mathbb{M}^C)^{-1} {}\_{G[A]} X^{A} {}\_A \mathrm{h}

its derivative will be:

{}^{G[A]} \dot{\mathrm{v}}\_G =  
\frac{d}{dt}(({}\_{G[A]} {\mathbb{M}}^C)^{-1})  {}\_{G[A]} X^{A} {}\_A \mathrm{h} +
({}\_{G[A]} \mathbb{M}^C)^{-1} {}\_{G[A]} \dot{X}^{A} {}\_A \mathrm{h} +
({}\_{G[A]} \mathbb{M}^C)^{-1} {}\_{G[A]} X^{A} {}\_A \dot{\mathrm{h}}

Discussion on the three terms:

GiulioRomualdi commented 6 years ago

@traversaro

Given the nice structure (for the linear part) of the centroidal composite rigid body inertia and the co-adjoint transform, the acceleration of the linear part of the of the centroidal average 6D velocity can be easily expressed as:

{} ^ {G[A]} v ^ l _ G= m _ A h ^ l

assuming (as usual) that the mass of each link of the multibody system is constant, also the total mass of the multibody system is constant, and so we have that:

{} ^ {G[A]} \dot{v} ^ l _ G=m _ A \dot{h} ^ l=J ^ l _ { { {} _ A} h} \dot{\nu} + \dot{J} ^ l _ { { {} _ A} h} \nu

Is there a typo here? The following term

{} ^ {G[A]} \dot{v} ^ l _ G=m _ A \dot{h} ^ l=J ^ l _ { { {} _ A} h} \dot{\nu} + \dot{J} ^ l _ { { {} _ A} h} \nu

should be

{} ^ {G[A]} \dot{v} ^ l _ G=m _ A \dot{h} ^ l= m ( J ^ l _ { { {} _ A} h} \dot{\nu} + \dot{J} ^ l _ { { {} _ A} h} \nu)

Do you agree?

GiulioRomualdi commented 6 years ago

Furthermore, in case I want to evaluate the terms that compose ${} {G[A]} \dot{h}$ can I proceed as follows? Recalling that ${} {G[A]} h = {} {G[A]} X ^ A {} A h$ the term ${} _ {G[A]} \dot{h}$ can be evaluated by differentiation. More formally:

{} _ {G[A]} \dot{h} = {} _ {G[A]} \dot{X} ^ A {} _ A h +  {} _ {G[A]} X ^ A {} _ A \dot{h} 

where, as you (@traversaro) suggested, the term ${} {G[A]} \dot{X} ^ A$ can be substituded by ${} {G[A]} {X}^{A} {}^A \mathrm{v} {G[A], A} \bar{\times} ^ { * }$. While ${} A \dot{h}$ can be split into $J{ {} A \mathrm{h} } \dot{\nu} + \dot{J} {{} A \mathrm{h} } \nu$. Here, $J { {} A \mathrm{h} }$ is given by getLinearAngularMomentumJacobian(), while the second term $\dot{J} {{} A \mathrm{h} }~\nu$ can be evaluated using ComputeLinearAndAngularMomentumDerivativeBias().

So collecting all the quantities, ${} _ {G[A]} \dot{h}$ can be written in an elegant form

{} _ {G[A]} \dot{h} = ({} _ {G[A]} \dot{X} ^ A J _ { {} _ A \mathrm{h} } \nu + \dot{J} _ {{} _ A \mathrm{h} } \nu) +J_{ {} _ A \mathrm{h} } \dot{\nu} 

where the first term is a sort of bias acceleration (I do not know if it has a proper name)

traversaro commented 5 years ago

Do you agree?

Yes, sorry for the late reply.

traversaro commented 4 years ago

Do you agree?

Yes, sorry for the late reply.

Actually it seems that this part is wrong:

Here, $J { {} A \mathrm{h} }$ is given by getLinearAngularMomentumJacobian()