TH /TannoHubYOSHINOBU TANNO日本語 ↗
Sensors & Measurement

Nine-axis sensors and quaternions: checking an attitude display

Connect nine-axis sensor readings to attitude display: AHRS inputs, quaternion order, coordinate conventions, and inverse rotations.

← All technical notes

Original material: 2015-10 · Article edited:

Adapted from Yoshinobu Tanno’s published slides with AI assistance. Historical implementation details are distinguished from added explanations.

Read the original slides: さるでも分かりたい9dofで作るクォータニオン姿勢

Separate sensor acquisition, attitude estimation, and rendering. Representing an orientation with a quaternion is also different from controlling a physical object's attitude with actuators. This article covers estimation and display.

Understand the inputs

The October 2015 slides combine three-axis acceleration, angular velocity, and magnetic measurements using Madgwick AHRS (Attitude and Heading Reference System), then convert the resulting quaternion into a rotation matrix. Original slides, 3–6.

Gyroscopes track changes but accumulate bias error. Acceleration provides a gravity reference under approximately static conditions; magnetic readings help with heading but are affected by local disturbances. The algorithm publisher provides the original report and implementations. x-io Technologies resources.

Component order matters

Here, q = (w, x, y, z), with identity (1, 0, 0, 0). Some libraries use (x, y, z, w); SciPy's Rotation.from_quat uses that scalar-last convention by default. SciPy reference.

For a unit axis n and angle θ, w = cos(θ/2) and (x,y,z) = n sin(θ/2). A right-handed active rotation of +90 degrees about Z is (√2/2, 0, 0, √2/2): +X rotates toward +Y. This is a convention check, not a sensor measurement.

Fix conventions first

  1. Map sensor axes to display axes.
  2. Check angular-velocity and time units.
  3. Match quaternion component order.
  4. Update orientation and convert it for rendering.
  5. Check one axis at a time.

When rotation runs backward

Do not always conjugate a quaternion merely because the renderer uses OpenGL. Establish whether the transform rotates an object or changes coordinates, and in which direction. For a unit quaternion, conjugation gives the inverse rotation.

Quaternion representation does not remove sensor errors. Neither the original slides nor this article supplies a complete filter derivation or a new hardware accuracy validation.

Related reading and work

For collaborative research, technical validation, or learning-material development, discuss a project.