Maths - Quaternion Arithmetic - Forum Discussion

By: Prospero999 - prospero999
file Quaternions and Aircraft Roll Demand Control*  
2005-10-21 17:16
Hi all, 
 
I'm writing a roll angle demand control loop for X-Plane (the flight simulation), but I'm coming up against what I suspect are the "usual problems" with a Euler Angles representation of attitude. 
 
To start with, I should mention that X-Plane outputs roll, pitch and yaw as Euler angles. Roll has range +/-180 degrees. Pitch has range +/-90 degrees. Yaw has range +/-180 degrees. I should also mention that the roll demand control loop's error signal is generated by calculating "desired roll angle minus actual roll angle." 
 
So, here's an example of the problem I'm having: 
 
Let's say that the aircraft starts out flying straight and level (pitch is about 0 degrees) and then pulls up into an almost vertical climb (pitch is almost 90 degrees). Well, now the roll value is just about to flip over from 0 to 180 degrees, and becomes VERY noisy, which in turn means my error signal is very noisy and my control loop doesn't function nearly as well as it does when the aircraft is flying straight and level with pitch around 0. 
 
I believe that quaternions may provide the answer, but I'm trying to work out how I actually use them to determine the roll error signal. I'm afraid I have only a little experience of quaternion mathematics. 
 
X-plane outputs the aircraft's attitude as Euler Angles, so if one's going to work with quaternions, I presume that the first stage would be to convert from a Euler Angles representation of attitude to a quaternion representation of attitude thusly (note that roll, pitch and yaw are in degrees, and q1w, q1x, q1y and q1z are the four elements of the quaternion, and DEGTORAD is Pi/180): 
 
 
q1w = Cos(roll * DEGTORAD / 2) * Cos(pitch * DEGTORAD / 2) * Cos(yaw * DEGTORAD / 2) + Sin(roll * DEGTORAD / 2) * Sin(pitch * DEGTORAD / 2) * Sin(yaw * DEGTORAD / 2) 
 
q1x = Sin(roll * DEGTORAD / 2) * Cos(pitch * DEGTORAD / 2) * Cos(yaw * DEGTORAD / 2) - Cos(roll * DEGTORAD / 2) * Sin(pitch * DEGTORAD / 2) * Sin(yaw * DEGTORAD / 2) 
 
q1y = Sin(roll * DEGTORAD / 2) * Cos(pitch * DEGTORAD / 2) * Sin(yaw * DEGTORAD / 2) + Cos(roll * DEGTORAD / 2) * Sin(pitch * DEGTORAD / 2) * Cos(yaw * DEGTORAD / 2) 
 
q1z = Cos(roll * DEGTORAD / 2) * Cos(pitch * DEGTORAD / 2) * Sin(yaw * DEGTORAD / 2) - Sin(roll * DEGTORAD / 2) * Sin(pitch * DEGTORAD / 2) * Cos(yaw * DEGTORAD / 2) 
 
 
And one can form the corresponding direction cosine matrix from the attitude quaternion like this: 
 
 
m11 = q1w ^ 2 + q1x ^ 2 - q1y ^ 2 - q1z ^ 2 
m12 = 2 * (q1x * q1y + q1w * q1z) 
m13 = 2 * (q1x * q1z - q1w * q1y) 
m21 = 2 * (q1x * q1y - q1w * q1z) 
m22 = q1w ^ 2 - q1x ^ 2 + q1y ^ 2 - q1z ^ 2 
m23 = 2 * (q1y * q1z + q1w * q1x) 
m31 = 2 * (q1x * q1z + q1w * q1y) 
m32 = 2 * (q1y * q1z - q1w * q1x) 
m33 = q1w ^ 2 - q1x ^ 2 - q1y ^ 2 + q1z ^ 2 
 
 
And the roll Euler Angle can be extracted from the direction cosine matrix like this (RADTODEG is 180/Pi): 
 
 
roll = Atn2(m23, m33) * RADTODEG 
 
 
But that's as far as I can get. What I need to be doing is finding the roll error signal - i.e. the difference between desired roll and actual roll. Could some kind person help? 
 
Many thanks, 
 
Anthony



metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

 

cover us uk de jp fr ca Quaternions and Rotation Sequences.

Terminology and Notation

Specific to this page here:

 

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2017 Martin John Baker - All rights reserved - privacy policy.