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.8k stars 379 forks source link

How to compute derivative with respect to q #1120

Closed Ke-Wang1017 closed 4 years ago

Ke-Wang1017 commented 4 years ago

Hi I am trying to compute Lie derivatives of some task space variables (for example y_com(q), y_foot(q)), this requires computing derivatives with respect to q, does Pinocchio have such a functionality?

jcarpent commented 4 years ago

You can access them from two sides:

Ke-Wang1017 commented 4 years ago

Hi @jcarpent , thanks! Any ways to get second order derivatives with respect to q, in the way of getting analytical derivatives? Because the algorithm requires second-order Lie derivative

Ke-Wang1017 commented 4 years ago

Also, is there any example code on CppAD? Fortunately I am using C++ now

cmastalli commented 4 years ago

@WangKeAlchemist

Alternatively, you could always use the Gauss-Newton approximation, i.e.:

  Fxx = Fx.transpose() * Fx;

We use extensively in our optimal control software called Crocoddyl. The main benefits is fast computation.

Ke-Wang1017 commented 4 years ago

@WangKeAlchemist

Alternatively, you could always use the Gauss-Newton approximation, i.e.:

  Fxx = Fx.transpose() * Fx;

We use extensively in our optimal control software called Crocoddyl. The main benefits is fast computation.

That is a good idea, thanks! @cmastalli

jcarpent commented 4 years ago

Yes, you can access at least kinematics directivities at both first and second orders analytically.

jcarpent commented 4 years ago

For the CppAD example, please refer to the unit tests or examples.

jcarpent commented 4 years ago

@WangKeAlchemist Which optimization solver do you use as backend?

Ke-Wang1017 commented 4 years ago

@WangKeAlchemist Which optimization solver do you use as backend?

I am using QPOASES

jcarpent commented 4 years ago

@cmastalli Gauss-Newton is only valid for residual quantities, where at optimum, the residual is close to zero. Otherwise, it is a very poor approximation which will to bad behaviours.

jcarpent commented 4 years ago

Are you doing Inverse Kinematics? or are you solving nonlinear optimization problems?

Ke-Wang1017 commented 4 years ago

Are you doing Inverse Kinematics? or are you solving nonlinear optimization problems?

I am solving dynamics, I have already implemented a task space inverse dynamics controller using Pinocchio for the bipedal robot in my lab (https://www.imperial.ac.uk/robot-intelligence/robots/slider/). Now I find another inverse dynamics algorithm using Control Lyapunov Functions (https://arxiv.org/pdf/1910.10824.pdf). And their method requires second order Lie derivatives.

jcarpent commented 4 years ago

OK. If you need specific features, we may think to implement them if we think they might useful for other people.

Ke-Wang1017 commented 4 years ago

OK. If you need specific features, we may think to implement them if we think they might useful for other people.

Hi @jcarpent , for our case, it is enough for now to get kinematics directivities at both first and second orders analytically, If my derivation about the algorithms is correct.

jcarpent commented 4 years ago

OK. So referring to the unit test is currently the best choice, as we don't have enough human power to set examples. If you would like to contribute, providing examples would very useful for everyone ;)

jcarpent commented 4 years ago

I will close this issue as it seems to be solved. Feel free to reopen it if needed.