How to transform pitch and roll to a rotated reference frame?

1.1k Views Asked by At

My problem is the same as that in this unanswered question, as well as this one and this one.

I would like to calculate the pitch and roll of an object with respect to a rotated reference frame. For instance say we have an aircraft fitted with an attitude sensor which is rotated 90 degrees clockwise to the aircraft's reference frame. When the aircraft pitches down 10 degrees, the sensor will roll 10 degrees to the left.

The approach I have taken so far is to use rotation matrices. I create a rotation matrix representing the object orientation and another for the transformation to the rotated reference frame. Then I multiply the matrices and extract pitch and roll from the result. However, when tested in Excel* I do not get exactly the expected result from this method (...although it is close).

Example :-

X positive right, Y positive forwards, Z positive upwards.

I am testing the case where the sensor is mounted on the aircraft with a rotation of 45 degrees around the z axis i.e. yaw. Here I would expect any pitch by the aircraft to be measured as simultaneous pitch and roll by the sensor, with the measured pitch and roll being identical.

For 10 degrees of pitch I construct the following rotation matrix. Numbers are in degrees here for clarity ; in the formulas they are of course radians:

matrixPitch = $\begin{bmatrix} cos(10) & 0 & sin(10) \\ 0 & 1 & 0 \\ -sin(10) & 0 & cos(10) \end{bmatrix}$

And for 45 degrees of yaw:

matrixYaw = $\begin{bmatrix} cos(45) & -sin(45) & 0 \\ sin(45) & cos(45) & 0 \\ 0 & 0 & 1 \end{bmatrix}$

I then multiply the two using the MMULT() worksheet function i.e.

=MMULT( matrixPitch , matrixYaw )

I get the following result, with numbers shown to six decimal places:

$\begin{bmatrix} 0.696364 & -0.696364 & 0.173648 \\ 0.707107 & 0.707107 & 0 \\ -0.122787 & 0.122788 & 0.984808 \end{bmatrix}$

I then extract the pitch and roll from this matrix, using the following formulas (from here):

$R = \begin{bmatrix} R_{11} & R_{12} & R_{13} \\ R_{21} & R_{22} & R_{23} \\ R_{31} & R_{32} & R_{33} \end{bmatrix}$

$\tan \phi = \frac{R_{32}}{R_{33}}$

$\tan \theta = \frac{-R_{31}}{\sqrt{R_{32}^2 + R_{33}^2}}$

Where $\phi$ is roll and $\theta$ is pitch.

I get the following (in degrees and, again, to six decimals):

$\phi$ = 7.107076

$\theta$ = 7.053022

I would expect these numbers to be essentially identical, and I don't think that there is much opportunity for significant rounding errors in the calculations. I have also performed the same calculations using C# (using double precision) and get the same results.

Am I doing something wrong? To validate the method I would have liked the resulting pitch and roll to agree to at least two decimal places.


* Other spreadsheet applications are available

1

There are 1 best solutions below

1
On

The calculations are correct, but I am unsure of what you are expecting e.g., what are you trying to visualize? In general, you need to define a rotation matrix from the sensor to the aircraft, then you need to define the rotations from one step to another step, and so on...

Let $I$ represent the frame of the IMU, and let $B$ represent the body of the aircraft. The rotation matrix from the body to the IMU can then be denoted as ${}^I \mathbf{R}_{B}$ (e.g., 45 degrees yaw in your example).

Now, the aircraft has some motion (e.g., 10 degrees pitch as in your example), then you define the rotation matrix from $B_0$ to $B_1$, which is the rotation from the body at step $t_0$ to the body at step $t_1$. This can be denoted as ${}^{B_1} \mathbf{R}_{B_0}$.

If you want the orientation of the sensor at step $t_1$, then you need to calculate the rotation matrix as follows: ${}^{B_1}R_{I} = {}^{B_1} \mathbf{R}_{B_0} {}^B \mathbf{R}_I$

Now, you can extract the roll, pitch, and yaw of your sensor. Perhaps, you want to calculate a different quantity. If so, the procedure is similar. Note, in general, ${}^B\mathbf{R}_A = {}^A \mathbf{R}_B^{-1}$ for reference frames $A$ and $B$. Be careful with signs because ${}^A \mathbf{R}_B$ represents the orientation of $B$ with respect to $A$.