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.91k stars 395 forks source link

differentiation for a unit vector in the world frame #1382

Closed ddliu365 closed 3 years ago

ddliu365 commented 3 years ago

Hi,

I want to differentiate a unit vector in the world frame as in this equation image

where, R{We}(q) is the rotation matrix of end effector in the world frame and v{ey} is a unit vector in the local frame of end effector. the rotation matrix is 3x3 dimension, and v_{ey} is3x1 dimension, so l is 3x1 dimension. For the expected differentiation output, the Jacobian should be 3xnq dimension.

I plan to use pinocchio.getFrameJacobian(model, data, self.Rref.id, pinocchio.ReferenceFrame.WORLD)[3:, :] to calculate the Jacobian of orientation part(3xnq), but if we apply the constant vector v_{ey} on the orientation Jacobian, it seems the output of differentiation is 1xnq.

I think I made a mistake for the derivation. Do you know how to address this issue?

jcarpent commented 3 years ago

The differentiation operator on SO(3) is the cross product: R^t * dR/dt = w x You should then get the Jacobian of l as follows: dl/dq = J x l where the cross operator is defined column-wise.

ddliu365 commented 3 years ago

sorry, I didn't get why it is dl/dq = J x l instead of dl/dq = J x v_{ey} since v_{ey} is a constant vector here Would you mind to give more derivation

ddliu365 commented 3 years ago

for the cross operator here, you mean I should do cross product for l and each column vector in J?

jcarpent commented 3 years ago

l is the expression of v_ey in the world coordinate system.

for the cross operator here, you mean I should do cross product for l and each column vector in J?

Yes.

By the way, I hope you won't forget to cite/acknowledge Pinocchio when publishing your work.

ddliu365 commented 3 years ago

sure, I will. I think I need to make up some geometries stuff, do you have any recommended material for understanding this derivation ? right now I am reading the rigid body dynamics algorithms by Featherstone

jcarpent commented 3 years ago

A Mathematical Introduction to Robotic Manipulation, Murray et al. is of course another very good entry point.

ddliu365 commented 3 years ago

I just quickly went through the content you recommended. Based on my understanding, this Jocobian is not the analytic Jacobian w.r.t to q. My previous notation is totally wrong. It is a geometric Jacobian, I think. For a frame translation Jacobian, we have image For a frame orientation, we have image so, we are basically finding something which connects the derivates of our vector and the joint velocity. Based on this understanding, we have the Jacobian in the following bracket to represent the "derivative w.r.t q" image Do I understand correct?

ddliu365 commented 3 years ago

Another question is: is there a second order differentiation for l w.r.t q if there is, should it be like the following? image

jcarpent commented 3 years ago

I just quickly went through the content you recommended. Based on my understanding, this Jocobian is not the analytic Jacobian w.r.t to q. My previous notation is totally wrong. It is a geometric Jacobian, I think.

I don’t get what you mean. This is not clear.

jcarpent commented 3 years ago

Do I understand correct?

This is exactly what I’ve written before.

jcarpent commented 3 years ago

Another question is: is there a second order differentiation for l w.r.t q if there is, should it be like the following? image

Your derivations are not correct. Did you check twice by yourself first?

PS: what you are asking here is some supervisor's feedback. It is hard at the project level to help everybody on his/her research issues, as we have other obligations which prevent us to be as responsive as you would like. We are already doing our best to provide you with some scientific guidance, either on Pinocchio or Crocoddyl, but you are very demanding. I would suggest asking further helps from your research institution.

ddliu365 commented 3 years ago

Sorry for my unclear question. Thanks for your remind my problem and I will notice this issue in the future question.

Please ignore my understanding about geometry Jacobian.

From the derivation, I understanding why it is J x l instead of J x v_{ey}. Your explanation is absolutely right.

I am working on a crocoddyl problem like you mentioned. The cost function needs a first order differentiation as well as a second order differentiation w.r.t q. I got struck by the dimension issue in the second order differentiation. The previous description is only a part of the problem. here is the full cost function and the first order differentiation based on what you showed to me

image

Based on crocoddyl convention, the second order differentiation (i.e. Hessian )is expected to be approximated by

image

But I am not sure if this is correct for my problem. If I ignore this convention, I derived the second order like this:

image

here, J_O and J_p are the spatial linear Jacobian and spatial angular Jacobian. v_{Wg} is the end effector velocity in the inertial frame. v_{gy} is a vector in the body frame of end effector. R_{Wg} is the rotation matrix map frame of end effector g to inertial frame W. l is the cost function, l_q is the first order differentiation of l w.r.t. q, and l_{qq} is the second order differentiation of l w.r.t q. This derivation I ignored the derivative of this part(marked with red oval shape), but I am not sure if this is right:

image
jcarpent commented 3 years ago

@ddliu365 Did you completely read my message?

PS: what you are asking here is some supervisor's feedback. It is hard at the project level to help everybody on his/her research issues, as we have other obligations which prevent us to be as responsive as you would like. We are already doing our best to provide you with some scientific guidance, either on Pinocchio or Crocoddyl, but you are very demanding. I would suggest asking further helps from your research institution.

ddliu365 commented 3 years ago

sorry, I missed that part.

ddliu365 commented 3 years ago

Please try to response when you are free. Thank you very much.