Robotic Systems

Robotic Systems · teaching-draft · v0.2.0

Scalar-first quaternions and attitude integration

Lecture 4 · Week 2 · 90 minutes

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 Q=(w,x,y,z)=(w,r)Q=(w,x,y,z)=(w,r), scalar first, representing a body-to-world rotation. Identity is (1,0,0,0)(1,0,0,0). For axis nn and angle θ\theta,

Q=(cos⁡(θ/2), nsin⁡(θ/2)).Q=(\cos(\theta/2),\ n\sin(\theta/2)).
The Hamilton product is
Q1⊗Q2=(w1w2−r1⊤r2, w1r2+w2r1+r1×r2).Q_1\otimes Q_2=(w_1w_2-r_1^\top r_2,\ w_1r_2+w_2r_1+r_1\times r_2).
Both QQ and −Q-Q represent the same rotation. Four unit-norm components describe three degrees of freedom. Uppercase Q distinguishes one attitude from the full configuration q.

Integrating angular velocity

For body angular velocity ωB\omega^B,

Q˙=12Q⊗(0,ωB).\dot Q=\tfrac12 Q\otimes(0,\omega^B).
A constant body angular velocity over a step gives
Qk+1=Qk⊗Exp⁡Q(ΔtωB),Q_{k+1}=Q_k\otimes\operatorname{Exp}_Q(\Delta t\omega^B),
where Exp⁡Q(ϕ)=(cos⁡(∥ϕ∥/2),ϕsin⁡(∥ϕ∥/2)/∥ϕ∥)\operatorname{Exp}_Q(\phi)=(\cos(\|\phi\|/2),\phi\sin(\|\phi\|/2)/\|\phi\|), using the continuous limit at zero. World angular velocity multiplies on the other side.

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 ωB=(0,0,π/2)\omega^B=(0,0,\pi/2) rad/s for one second from identity. The result is (2/2,0,0,2/2)(\sqrt2/2,0,0,\sqrt2/2), mapping body x to world y. This catches component-order and half-angle mistakes.

For normalized quaternions, orientation distance is 2arccos⁡(min⁡(1,∣⟨Q1,Q2⟩∣))2\arccos(\min(1,|\langle Q_1,Q_2\rangle|)). The absolute dot handles sign equivalence. A logarithm-based calculation can be more accurate near zero.

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.

Reading and source connections

Advanced Robot Dynamics and Simulation — lecture series — CMU 16-715. Companion video series for modeling, integration, rigid-body dynamics, constraints, and contact.

Optimal Control 16-745 — lecture index — Zachary Manchester and CMU course staff. Topic-level connection to discretization, LQR, MPC, trajectory optimization, rotations, and learning.

MuJoCo API functions — MuJoCo contributors. Function-level reference. The lockfile fixes the executable version; stable documentation can move.