1. ## Question about rotation and reference

Hi.

Let's suppose to have a car with a reference system called Body-NED with its origin in the center of gravity of the car, Xb-axis (called North) pointing towards the front of the car, Yb-axis (called East) pointing towards the right door and Zb-axis (called Down) pointing...down the street of course

On this car there is a magnetometer to measure the magnetic field.

Finally we have the Earth's magnetic field that has it's own reference system called Earth-NED with center in the Earth's surface where the car is located and with X-North and Y-East axes laying on the plane perpendicular to Earth's gravity field, while Z-Down is parallel to Earth's gravity field: therefore, X-North points toward magnetic North and Y-East is perpendicular to X-North and Z-Down as regards to the right hand rule.

The Earth's magnetic field is a vector H with components He_x, He_y and He_z with respect to Earth-NED X,Y,Z reference.

Three attitude angles for the car are referenced to the local horizontal plane which is perpendicular to Earth’s gravity.

Yaw is defined as the angle between the Xb axis and the magnetic north on the horizontal plane measured in a clockwise direction when viewing from the top of the car.

Pitch is defined as the angle between the Xb axis and the horizontal plane. When the car is rotating around the Yb axis with the Xb axis moving upwards, pitch is positive and increasing.

Roll is defined as the angle between the Yb axis and the horizontal plane. When the car is rotating around the Xb axis with the Yb axis moving downwards, roll is positive and increasing.

What's the magnetic field measured by the magnetometer on the car?

I know that there are three rotation matrices built on yaw, pitch and roll angles and the product of them has to be used, but I'm confused about the sequence and the change of reference system.

Thank you.

2. Originally Posted by fenestren
Hi.

Let's suppose to have a car with a reference system called Body-NED with its origin in the center of gravity of the car, Xb-axis (called North) pointing towards the front of the car, Yb-axis (called East) pointing towards the right door and Zb-axis (called Down) pointing...down the street of course

On this car there is a magnetometer to measure the magnetic field.

Finally we have the Earth's magnetic field that has it's own reference system called Earth-NED with center in the Earth's surface where the car is located and with X-North and Y-East axes laying on the plane perpendicular to Earth's gravity field, while Z-Down is parallel to Earth's gravity field: therefore, X-North points toward magnetic North and Y-East is perpendicular to X-North and Z-Down as regards to the right hand rule.

The Earth's magnetic field is a vector H with components He_x, He_y and He_z with respect to Earth-NED X,Y,Z reference.

Three attitude angles for the car are referenced to the local horizontal plane which is perpendicular to Earth’s gravity.

Yaw is defined as the angle between the Xb axis and the magnetic north on the horizontal plane measured in a clockwise direction when viewing from the top of the car.

Pitch is defined as the angle between the Xb axis and the horizontal plane. When the car is rotating around the Yb axis with the Xb axis moving upwards, pitch is positive and increasing.

Roll is defined as the angle between the Yb axis and the horizontal plane. When the car is rotating around the Xb axis with the Yb axis moving downwards, roll is positive and increasing.

What's the magnetic field measured by the magnetometer on the car?

I know that there are three rotation matrices built on yaw, pitch and roll angles and the product of them has to be used, but I'm confused about the sequence and the change of reference system.

Thank you.
The angles between the axis systems are called Euler angles, and are usually given the following notation:

$\psi = \text{Yaw Angle}$

$\theta = \text{Pitch Angle}$

$\phi = \text{Roll Angle}$

To get from the earth fixed axes to the body fixed axis system, one must perform a transformation which is based on these angles. This is performed using a transformation matrix, which is acquired by multiplying three separate transformation matrices together - one for each euler angle.

So, the process is this:

We begin in Earth body axis, which we will denote by $(Ox_Ey_Ez_E)$.

We will then rotate away from this system through a yaw angle, $\psi$. This will take us to a new intermediate coordinate system which we will call $(Ox_1y_1z_1)$. Since we rotated about the $Z$ axis, $Z_1 = Z_E$.

We will then rotate away from this intermediate system through a pitch angle, $\theta$. This will take us to a new intermediate coordinate system which we will call $(Ox_2y_2z_2)$. Since we rotated about the $Y$ axis, $Y_2 = Y_1$.

Finally, we will rotate away from this intermediate system through a roll angle, $\phi$. This will take us to the body coordinate system which we will call $(Ox_by_bz_b)$. Since we rotated about the $X$ axis, $X_b = X_2$.

So that is the order of events. Mathematically, each of these steps is done simply by multiplying by a rotate matrix like so:

$\left( \begin{array}{ccc}
x_1 \\
y_1 \\
z_1 \end{array} \right) =

\left( \begin{array}{ccc}
\cos(\psi) & \sin(\psi) & 0 \\
-\sin(\psi) & cos(\psi) & 0 \\
0 & 0 & 1 \end{array} \right)
\left( \begin{array}{ccc}
x_E \\
y_E \\
z_E \end{array} \right)$

$\left( \begin{array}{ccc}
x_2 \\
y_2 \\
z_2 \end{array} \right) =

\left( \begin{array}{ccc}
\cos(\theta) & 0 & -\sin(\theta) \\
0 & 1 & 0 \\
\sin(\theta) & 0 & \cos(\theta) \end{array} \right)
\left( \begin{array}{ccc}
x_1 \\
y_1 \\
z_1 \end{array} \right)$

$\left( \begin{array}{ccc}
x_b \\
y_b \\
z_b \end{array} \right) =

\left( \begin{array}{ccc}
1 & 0 & 0 \\
0 & \cos(\phi) & \sin(\phi) \\
0 & -\sin(\phi) & \cos(\phi) \end{array} \right)
\left( \begin{array}{ccc}
x_2 \\
y_2 \\
z_2 \end{array} \right)$

In other words:

$\left( \begin{array}{ccc}
x_b \\
y_b \\
z_b \end{array} \right) =

\left( \begin{array}{ccc}
1 & 0 & 0 \\
0 & \cos(\phi) & \sin(\phi) \\
0 & -\sin(\phi) & \cos(\phi) \end{array} \right)$
$

\left( \begin{array}{ccc}
\cos(\theta) & 0 & -\sin(\theta) \\
0 & 1 & 0 \\
\sin(\theta) & 0 & \cos(\theta) \end{array} \right)

\left( \begin{array}{ccc}
\cos(\psi) & \sin(\psi) & 0 \\
-\sin(\psi) & cos(\psi) & 0 \\
0 & 0 & 1 \end{array} \right)$
$

\left( \begin{array}{ccc}
x_E \\
y_E \\
z_E \end{array} \right)$

So, if you replace that far right vector with your magnetic field vector in earth axis, and multiply it by those three rotation matrices in that order (Yaw first, then Pitch, then Roll), then the result you will get is the magnetic field vector in body axis, i.e., as measured by the car.

3. Thank you!
This confirms my thoughts about it!

Considered this, if I had a magnetometer with some misalignment with respect to Body reference system, the Earth's magnetic field as measured by the magnetometer, I should do the same transformation you suggest me (with the same matrices and sequence) from Body to magnetometer, do you confirm this?

4. Originally Posted by fenestren
Thank you!
This confirms my thoughts about it!

Considered this, if I had a magnetometer with some misalignment with respect to Body reference system, the Earth's magnetic field as measured by the magnetometer, I should do the same transformation you suggest me (with the same matrices and sequence) from Body to magnetometer, do you confirm this?
Yes, Euler transformations allow transformations between any coordinate systems.

5. Originally Posted by Phugoid
Yes, Euler transformations allow transformations between any coordinate systems.
That's not quite true. It'll work for rotations, yes, but translations are a bit different. See this web page for more info on those.