Hello, I noticed there is a function mapping local pos/xquat to global ones. But I could not find the reverse function. I am trying to convert global xquat into local xquat w.r.t. another body in the tree (Pelvis body). Attached is the way I try to do this, but the resulting local quaternions do not match with the true data. Is there any built-in way to do this in mj functions? Thank you!
In general, the spatial frame (or pose) of a body has position and orientation, and they should be treated as one object. The functions mju_mulPose and mju_negPose can be used to multiply (i.e. accumulate poses) as well as invert them. If you only need the orientation component, positions can be ignored (while the opposite is not true). It is better to work with quaternions directly instead of converting them to matrices. The functions you need are mju_mulQuat and mju_negQuat. Suppose A is a global quaternion, you apply local quaternion rotation B to it, and obtain global quaternion C: A * B = C To solve for B, multiply both sides by the conjugate of A: B = conjugate(A) * C Using MuJoCo functions: mjtNum A[4], B[4], C[4], Aconjugate[4]; // initialize A and C mju_negQuat(Aconjugate, A); mju_mulQuat(B, Aconjugate, C);