Home > Electronic Compass > Application Notes > Attitude Calculation

Attitude Calculation

Magnetic sensors and accelerometers can be used not only for tilt compensation but also to calculate a attitude of the platform on which the sensors are mounted.

The attitude shows the relative value of how much the sensors’ coordinates have rotated as compared to the fixed absolute coordinate system.

The attitude values can be shown using the below 3 methods.

(1) Express in a matrix (3 vectors)

The sensor’s coordinates in the x, y, and z axes can be expressed using 3 vectors vx, vy, vz of absolute coordinate values.

The 3 vectors can be combined into a 3×3 matrix to express the attitude.

This also refers to the rotation matrix showing the rotation in absolute coordinates.

(2) Euler angles (roll angle, pitch angle, yaw angle)

The attitude can also be expressed as the angle of rotation along each of absolute coordinates’ x, y, and z axes.

(3) Quaternions or rotation vectors

The rotation from absolute coordinates can also be expressed as rotation vectors or in special, complex numbers called quaternions.

It is possible to convert between these three expressions.

The method for calculating an attitude matrix is shown below.

First, find the opposite rotation in the absolute coordinates from the measured values of the sensor’s coordinates.

To do so, first, find the z axis vector from the accelerometer’s recorded value.

Next, using the accelerometer and the earth’s magnetic field, find the orthogonal vector from these two vectors.

The x-axis can be found from this calculation.

Lastly, from the previously calculated z and x axes, find the orthogonal vector.  This calculation produces the y axis.

When you put these 3 vectors together as vx, vy, and vz, you can construct the following matrix.

This matrix is the rotation matrix showing the amount of the rotation from the sensor’s coordinates to the absolute coordinates.

To find the change from the absolute coordinates to the sensor’s coordinates, calculate the inverse matrix.

From the above, we find the matrix that expresses attitude, M'.

※ Please refer to the literature for how to convert from this matrix to quaternions or Euler angles.