Learning outcomes
- Use MuJoCo's wxyz quaternion order.
- Integrate body angular velocity on the rotation manifold.
- Compute a sign-invariant orientation error.
Prerequisites: Linear algebra, ODEs, and earlier lectures in this sequence.
Quaternion convention
We use a unit quaternion
Integrating angular velocity
For body angular velocity
Normalizing a forward-Euler update repairs quaternion norm but does not make its angular increment exact. Manifold preservation and integration accuracy are different properties.
Worked quarter-turn
Apply
For normalized quaternions, orientation distance is
MuJoCo configuration operations
A free joint stores position followed by wxyz, while velocity has linear and angular components. Use mj_integratePos to update the full configuration, and mj_differentiatePos for tangent differences. Do not infer velocity dimension from qpos length.
Practice 2 cross-checks an independently implemented exponential update against MuJoCo and tests sign equivalence. A non-identity initial orientation and nonparallel angular velocity distinguish left from right multiplication.
Exercise
Identity and negative identity have raw quaternion difference norm 2. What is the physical attitude error? Answer: zero. A raw four-component quadratic penalty can punish a representation change without physical motion. Local orientation control and optimization should use a three-dimensional tangent error.
When importing a scalar-last quaternion, reorder explicitly once at the boundary and test the quarter-turn. Avoid scattered reordering throughout the dynamics code.