Algorithm Search⌘K

Theoremcore

Quaternion kinematic equation

Also called quaternion derivative.

For a unit quaternion q (Hamilton, scalar first) that maps body to world, dq/dt = (1/2) q (0, w_b) = (1/2) (0, w_s) q, a linear equation with no singular attitude.

The quaternion kinematic equation gives the rate of change of a unit quaternion attitude in terms of the angular velocity. For a unit quaternion q(t)q(t) in the Hamilton convention, with the scalar first, whose rotation R(q)R(q) maps body coordinates to world coordinates, it reads

q˙=12 q (0,ωb)=12 (0,ωs) q,\dot q = \tfrac12\, q\,(0, \omega_b) = \tfrac12\, (0, \omega_s)\, q,

where ωb\omega_b is the angular velocity in the body frame, ωs=R ωb\omega_s = R\,\omega_b is the same angular velocity in the world frame, and (0,ω)(0, \omega) is a pure quaternion. The equation is linear in qq with coefficients that stay bounded, so it has no singular attitude, unlike the rate equations of roll-pitch-yaw angles. Gyroscope integration, attitude filters and simulators of rigid bodies use it.

Notation on this page: rotations are active, [ω][\omega] is the skew-symmetric matrix of ω\omega, q=(w,u)q = (w, u) has the scalar part ww and the vector part uu, and the product of quaternions is (a,u)(b,v)=(ab−u⋅v, av+bu+u×v)(a, u)(b, v) = (ab - u \cdot v,\, av + bu + u \times v).

Statement

Theorem. Let q:[0,T]→S3q : [0, T] \to S^3 be a differentiable curve of unit quaternions, and let R(t)=R(q(t))R(t) = R(q(t)), so that (0,Rv)=q (0,v) q∗(0, Rv) = q\,(0, v)\,q^*. Define the body and the space angular velocities by [ωb]=RTR˙[\omega_b] = R^{\mathsf T}\dot R and [ωs]=R˙RT[\omega_s] = \dot R R^{\mathsf T}. Then

q˙=12 q (0,ωb)=12 (0,ωs) q.\dot q = \tfrac12\, q\,(0, \omega_b) = \tfrac12\, (0, \omega_s)\, q .

In matrix form, with qq as the column (w,u)(w, u),

q˙=12(0−ωbTωb−[ωb])q=12(0−ωsTωs[ωs])q.\dot q = \tfrac12 \begin{pmatrix} 0 & -\omega_b^{\mathsf T} \\ \omega_b & -[\omega_b] \end{pmatrix} q = \tfrac12 \begin{pmatrix} 0 & -\omega_s^{\mathsf T} \\ \omega_s & [\omega_s] \end{pmatrix} q .

Conversely, for every continuous ωb(t)\omega_b(t) and every unit q(0)q(0), the linear equation q˙=12q (0,ωb)\dot q = \frac12 q\,(0, \omega_b) has a unique solution, the solution keeps ∣q(t)∣=1|q(t)| = 1, and R(q(t))R(q(t)) is the attitude that solves R˙=R[ωb]\dot R = R[\omega_b].

Other conventions. If qq maps world to body instead, replace qq by q∗q^*: then q˙=−12(0,ωb) q\dot q = -\frac12 (0, \omega_b)\, q. In the JPL convention (scalar last, ij=−kij = -k), the products appear in the reverse order, and the body form becomes q˙=12(0,ωb)⊗q\dot q = \frac12 (0, \omega_b) \otimes q in that algebra. Many errors in practice come from a formula of one convention used with quaternions of another, so state the convention next to the equation.

In plain words

A quaternion stores an orientation with four numbers. When the body turns, the four numbers change, and this equation tells how fast. The rate is half of the current quaternion times the turning rate of the body, so it needs only a product and a scale. The factor one half comes from the fact that a quaternion stores half of the angle of a turn. The turning rate can be measured in the body, as a gyroscope does, or in the world, and the product is then taken on the right or on the left. Nothing in the equation divides by a quantity that can be zero, so it works at every orientation. A computer that steps the equation in time slowly lets the length of the quaternion drift from one, so it rescales the quaternion after each step.

Proof

Step 1: the derivative of a unit quaternion. Put p=q∗q˙p = q^* \dot q. Differentiating q∗q=1q^* q = 1 gives q˙∗q+q∗q˙=p∗+p=0\dot q^* q + q^* \dot q = p^* + p = 0, so the scalar part of pp is zero and p=(0,12a)p = (0, \frac12 a) for some a∈R3a \in \mathbb{R}^3. Then q˙=qp=12q (0,a)\dot q = q p = \frac12 q\,(0, a).

Step 2: aa is the body angular velocity. Differentiate (0,Rv)=q (0,v) q∗(0, Rv) = q\,(0, v)\,q^* for a fixed vv. With q˙=qp\dot q = qp and q˙∗=p∗q∗=−p q∗\dot q^* = p^* q^* = -p\, q^*,

(0,R˙v)=q˙ (0,v) q∗+q (0,v) q˙∗=q (p (0,v)−(0,v) p) q∗.(0, \dot R v) = \dot q\,(0, v)\,q^* + q\,(0, v)\,\dot q^* = q\,\big(p\,(0, v) - (0, v)\,p\big)\,q^* .

For pure quaternions, (0,x)(0,y)−(0,y)(0,x)=(0,2 x×y)(0, x)(0, y) - (0, y)(0, x) = (0, 2\, x \times y), so p (0,v)−(0,v) p=(0,a×v)p\,(0, v) - (0, v)\,p = (0, a \times v). So (0,R˙v)=q (0,a×v) q∗=(0,R(a×v))(0, \dot R v) = q\,(0, a \times v)\,q^* = (0, R(a \times v)), that is R˙=R[a]\dot R = R[a], and [a]=RTR˙=[ωb][a] = R^{\mathsf T}\dot R = [\omega_b]. This proves q˙=12q (0,ωb)\dot q = \frac12 q\,(0, \omega_b).

Step 3: the space form. ωs=R ωb\omega_s = R\,\omega_b, because R˙RT=R[ωb]RT=[Rωb]\dot R R^{\mathsf T} = R[\omega_b]R^{\mathsf T} = [R\omega_b]. So (0,ωs)=q (0,ωb) q∗(0, \omega_s) = q\,(0, \omega_b)\,q^*, and (0,ωs) q=q (0,ωb)(0, \omega_s)\,q = q\,(0, \omega_b).

Step 4: the matrix forms. The vector part of q (0,ω)q\,(0, \omega) is w ω+u×ω=w ω−[ω]uw\,\omega + u \times \omega = w\,\omega - [\omega]u, and the scalar part is −ω⋅u-\omega \cdot u. For (0,ω) q(0, \omega)\,q the vector part is w ω+[ω]uw\,\omega + [\omega]u.

Step 5: the converse. The equation is linear with a continuous coefficient, so it has a unique solution on [0,T][0, T]. The matrix Ω\Omega of Step 4 is skew-symmetric, so ddt∣q∣2=2 qTq˙=qTΩ q=0\frac{d}{dt}|q|^2 = 2\, q^{\mathsf T}\dot q = q^{\mathsf T}\Omega\, q = 0, and ∣q∣|q| stays 1. Step 2 then applies to the solution and shows R˙=R[ωb]\dot R = R[\omega_b]. □\square

A check by hand

Take a constant ωb=(0,0,1)\omega_b = (0, 0, 1) and q(t)=(cos⁡t2,0,0,sin⁡t2)q(t) = (\cos\frac t2, 0, 0, \sin\frac t2), the rotation by tt about zz. Then q˙=12(−sin⁡t2,0,0,cos⁡t2)\dot q = \frac12(-\sin\frac t2, 0, 0, \cos\frac t2). The product q (0,0,0,1)q\,(0, 0, 0, 1) has the scalar part −u⋅ω=−sin⁡t2-u \cdot \omega = -\sin\frac t2 and the vector part cos⁡t2 (0,0,1)+u×ω=(0,0,cos⁡t2)\cos\frac t2\,(0, 0, 1) + u \times \omega = (0, 0, \cos\frac t2), since uu is parallel to ω\omega. So 12q (0,ωb)=q˙\frac12 q\,(0, \omega_b) = \dot q. Here RR turns about its own zz axis, so ωs=ωb\omega_s = \omega_b, and the space form gives the same result.

Consequences

  • Integration over a step. For a constant ω\omega over a step of length Δt\Delta t, the exact solution is q(t+Δt)=q(t) (cos⁡∣ω∣Δt2,sin⁡∣ω∣Δt2 ω^)q(t + \Delta t) = q(t)\,\big(\cos\frac{|\omega|\Delta t}{2}, \sin\frac{|\omega|\Delta t}{2}\,\hat\omega\big) with ω^=ω/∣ω∣\hat\omega = \omega/|\omega|. This step keeps ∣q∣=1|q| = 1 up to rounding, and it is the usual way to integrate gyroscope samples.
  • The forward Euler step drifts. The step q+Δt2q (0,ω)q + \frac{\Delta t}{2} q\,(0, \omega) multiplies ∣q∣2|q|^2 by 1+(∣ω∣Δt/2)21 + (|\omega|\Delta t/2)^2. At 11 rad/s with Δt=0.01\Delta t = 0.01 s, after 10001000 steps, ∣q∣=1.01258|q| = 1.01258, and after normalization the angle is short by 8.3⋅10−58.3 \cdot 10^{-5} rad, while the exact step above is wrong by 1.3⋅10−151.3 \cdot 10^{-15} rad. Normalize after each step of an Euler or Runge-Kutta method.
  • No gimbal lock. The rate equations of roll-pitch-yaw angles divide by the cosine of the pitch and fail at the gimbal lock. The quaternion equation has no division, so dead reckoning and attitude estimation use it for all attitudes.
  • Filters. The prediction step of the error-state Kalman filter integrates this equation for the nominal attitude, and the nonlinear complementary filter adds a correction term to ω\omega before it integrates.
  • Constant angular velocity gives slerp. For a constant ωb\omega_b, the solution is q(0) exp⁡(t2(0,ωb))q(0)\,\exp(\frac t2 (0, \omega_b)), which is the path of spherical linear interpolation between its end points.

Tightness

  • The factor one half. It cannot be dropped: the quaternion of a rotation by θ\theta uses θ2\frac\theta2, so q˙=q (0,ω)\dot q = q\,(0, \omega) would turn the body at twice the true rate.
  • The side of the product. The body form needs ωb\omega_b on the right and the space form needs ωs\omega_s on the left. With ωb\omega_b on the left, the result is correct only when ωb\omega_b is parallel to the axis of qq, as in the check by hand, where ωs=ωb\omega_s = \omega_b.
  • The unit constraint. For a quaternion with ∣q∣≠1|q| \ne 1, the equation still holds for q/∣q∣q/|q|, because the norm is constant along every solution. Numerical methods do not keep the norm, so the normalization step is needed in practice, not in theory.
  • A nonlinear map in disguise. The equation is linear in qq, but the map from qq to RR is quadratic, and qq and −q-q give the same attitude. A filter that compares quaternions must choose the sign first.

History

William Rowan Hamilton found the quaternions in 1843 and published them from 1844. The kinematic equation is the derivative of his rotation formula q (0,v) q∗q\,(0, v)\,q^*. Sola collects the Hamilton and the JPL forms of the equation and the integration methods built on it.

References

  1. Joan Sola, Quaternion kinematics for the error-state Kalman filter, 2017, Section 4.5 (the time derivatives, equations 200 and 201, and Section 4.5.1 on global and local angular velocities) and Section 4.6.1 (zeroth-order integration, equation 215)
  2. Kevin M. Lynch and Frank C. Park, Modern Robotics, Mechanics, Planning, and Control, Cambridge University Press, 2017, Chapter 3, Section 3.2.2 (angular velocities in the space and the body frames)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/F6CXDF/text.yaml