Arland Thompson Chief Scientist Advanced Technology Associates

advertisement
Arland Thompson
Chief Scientist
Advanced Technology Associates
(www.atacolorado.com)
I) Introduction
Though quaternions are gaining popularity of usage throughout the aerospace
industry, there is still a great deal of unfamiliarity on the part of engineers. This
document is intended to give a “working knowledge” of quaternions and their use in
simulation.
The concept of quaternion algebra was introduced by Sir William Rowan Hamilton
in the 19th century. The following is an excerpt from a letter to his son Rev. Archibald H.
Hamilton:
“But on the 16th day of the same month - which happened to be a
Monday, and a Council day of the Royal Irish Academy - I was
walking in to attend and preside, and your mother was walking with
me, along the Royal Canal, to which she had perhaps driven; and
although she talked with me now and then, yet an under-current of
thought was going on in my mind, which gave at last a result, whereof
it is not too much to say that I felt at once the importance. An electric
circuit seemed to close; and a spark flashed forth, the herald (as I
foresaw, immediately) of many long years to come of definitely
directed thought and work, by myself if spared, and at all events on
the part of others, if I should even be allowed to live long enough
distinctly to communicate the discovery. Nor could I resist the
impulse - unphilosophical as it may have been - to cut with a knife on
a stone of Brougham Bridge, as we passed it, the fundamental formula
with the symbols, i, j, k; namely,
i2 = j2 = k2 = ijk = -1
which contains the Solution of the Problem, but of course, as an inscription, has
long since mouldered away.”
And so, the quaternion was born. The above excerpt refers to the quaternion as a hypercomplex number. In order to gain a “working knowledge” of quaternions, this paper will
not delve into such abstract algebra. It will focus on more applied aspects of the
quaternion without sacrificing mathematical correctness.
II) Elementary Rotations
The notion of an elementary rotation is now introduced. An elementary rotation is
the rotation about an arbitrary axis of an orthogonal coordinate frame by some arbitrary
angle.
zI, zF

yF

yI

xF
xI
Figure 1
In figure 1, the “I” frame is rotated by  about the z axis (third axis) to obtain the “F”
frame. The following equation can be used to transform a vector represented in the “I”
frame to a vector represented in the “F” frame:
 cos 

X F   sin 
 0
sin 
cos 
0
0

0 X I Eq. 1
1
This relationship is known as a coordinate transformation. It takes a vector whose
coordinates are expressed in the “I” frame and “maps” it to its corresponding coordinates
in the “F” frame. The orientation of the vector is not thought of as being altered. It has a
representation in the “I” frame, and a corresponding representation in the “F” frame. Any
arbitrary coordinate frame can be “mapped” to any other coordinate frame by a series of
elementary rotations performed in the proper order. The order of the rotations is
extremely important. An identical sequence of elementary rotations performed in an
alternate order would result in a different representation. A coordinate frame
transformation can be computed by multiplying (in the proper order) the matrices
representing the corresponding elementary rotations. For example, a “123” sequence (xyz
axes) of elementary rotations by the angles  would be represented as follows:
XF
 cos
  sin 
 0
sin 
cos
0
0 cos 
0  0
1  sin 
0  sin   1
0
0 


1
0  0 cos  sin   X I Eq. 2
0 cos   0  sin  cos  
III) Direction Cosine Matrices
Of course, the matrices in Eq. 2 can be multiplied together to form one transformation
matrix that maps vectors from the “I” frame to the “F” frame.
XF
 cos   cos 
  cos   sin 
 sin 
cos   sin   sin   sin   cos  sin   sin   cos   sin   cos  
cos   cos   sin   sin   sin  sin   cos   cos   sin   sin   X I

 sin   cos 
cos   cos 
Eq. 3
The resulting matrix from the multiplication is typically called a direction cosine matrix.
Take the two following general coordinate frames:
F
I
I



Figure 2
It may be instructive to see that there is a series of fundamental rotations (in the proper
order) that will bring the two coordinate frames into alignment. The corresponding
matrices multiplied together in the proper sequence form the coordinate transformation
(direction cosine matrix) between the two frames.
IV) Quaternions
There is an alternate way of thinking of the coordinate frame transformation. In
figure 2, there exists a single axis about which the “I” frame can be rotated by some angle
to bring it into alignment with the “F” frame. This is illustrated by Figure 3.
F
I
I
e

Figure 3
One way of viewing the quaternion (there are others) is as a coordinate frame
transformation, and is equivalent to the previously discussed direction cosine matrix. The
form of which can be taken directly from the axis of rotation and the angle of rotation
about that axis in figure 3. This form of the quaternion is 4 dimensional and is said to
have a “vector portion” which is 3 dimensional, and a “scalar” portion. For most
engineering applications, the scalar portion seems to be listed last. For most academic
applications, the scalar seems to be listed first.

  
e[0] * sin  2  
 


 e[1] * sin    

 2 
q
 
e[ 2] * sin  

 2 


  
 cos  
2 

Eq: 4
Note the form. The vector portion (first three components) is the coordinates of the axis
of rotation in the “I” frame (and “F” frame for that matter) multiplied by the sine of half
the rotation angle. The reason that it has half the rotation angle is not presented here. The
scalar portion is the cosine of half the rotation angle. Also note that a quaternion must be
of unit magnitude to be of use in coordinate frame transformation. As a practical
example, take the coordinate frame transformation from figure 1 for a rotation angle of
/4. The axis of rotation is the z axis.


4
e  0 0 1
Eq 5

  
0 * sin  8 
 

0 * sin   

 8  Eq: 6
q
 
1 * sin   

 8 

  
 cos  
8 

0




0
 Eq; 7
q
0.382683432


0.923879533
The above example is generalized in the theory developed by the great 18 th century
mathematician Leonard Euler that bears his name.

 
 e[0] sin  2



 e[1] sin 


 2
q  

e[ 2] sin 


 2

  
cos


 2 

Euler’s theorem and quaternions:


e
F













I Rotated
from t to t+t
I Frame at t
Euler’s theorem states that a rigid body can be brought from any arbit rary
initial orientation to an arbitrary final orientation by a single rotation about a
judiciously chosen axis fixed in both the initial and final frames by some angle.
Figure 4
When transforming a vector form one coordinate frame to another, the quaternion
can be used directly. This method is not presented here. As previously stated the
quaternion is equivalent to a direction cosine matrix and can be converted to it using the
appropriate algorithm.
q00 = qUnit[0]*qUnit[0]
q11 = qUnit[1]*qUnit[1]
q22 = qUnit[2]*qUnit[2]
q33 = qUnit[3]*qUnit[3]
q01 = qUnit[0]*qUnit[1]
q02 = qUnit[0]*qUnit[2]
q03 = qUnit[0]*qUnit[3]
q12 = qUnit[1]*qUnit[2]
q13 = qUnit[1]*qUnit[3]
q23 = qUnit[2]*qUnit[3]
Eqs; 8
dcm[0][0] = q00 - q11 - q22 + q33
dcm[0][1] = 2.0*(q01 + q23)
dcm[0][2] = 2.0*(q02 - q13)
dcm[1][0] = 2.0*(q01 - q23)
dcm[1][1] = -q00 + q11 - q22 + q33
dcm[1][2] = 2.0*(q12 + q03)
dcm[2][0] = 2.0*(q02 + q13)
dcm[2][1] = 2.0*(q12 - q03)
dcm[2][2] = -q00 - q11 + q22 + q33
Then, the direction cosine matrix is used to perform the transformation as
presented earlier (Eqs: 1 and 2).
V) Introduction to Simulation
In many 3 Degree of Freedom (Vehicle is free to translate about 3 orthogonal axes)
or 6 Degree of Freedom simulation (Vehicle is free to translate and rotate about 3
orthogonal axes), there are two coordinate systems of prime importance. The first is the
inertial frame of reference, and the second is the vehicle body frame. The inertial frame is
a non-rotating, non-accelerating (it can be translating) coordinate frame where Newton’s
laws of motion apply. The equations of motion are integrated in this frame to maintain
the position, velocity, and attitude of the vehicle during simulation execution. In practice,
a truly inertial frame of reference is difficult to actualize, and a “quasi-inertial” reference
frame is used (e.g. An Earth Centered, non-rotating frame. Note that this frame is
experiencing acceleration due to solar gravity). The second is the vehicle body frame.
This is a rotating, accelerating and translating reference frame relative to the inertial
frame attached to the vehicle body with center located at the center of gravity of the
vehicle. It is important to maintain the orientation of the vehicle body frame relative to
the inertial frame during simulation execution, and to be able to transform vector
quantities between the two frames. Quaternions provide many advantages over other
implementations such as Euler angles for doing this. Quaternions require less storage
space than direction cosine matrices (4 elements as opposed to 9), and require fewer, less
complicated mathematical operations in keeping track of the time evolution of the
quaternion during the simulation. This enhances the speed and accuracy of the
simulation. In addition, there are no singularities in this process as there are with using
Euler angles.
VI) Numerical Integration of Ordinary Linear Systems
The equations of motion governing the time evolution of a vehicle state often take
the form of a coupled set of ordinary, linear differential equations of the form:
X  f (t , X ) Eq. 9
That is, the time derivative of the state is a function of time, and the state. These
types of systems can be integrated using a numerical scheme such as 4th order Rungekutta.

K1  f t k , X k

dt
dt


K 2  f  tk  , X k  * K1
2
2


dt
dt


K 3  f  tk  , X k  * K 2 
2
2




K 4  f tk  dt , X k  K 3
X k 1  X k 

dt * K1  2 * K 2  2 * K 3  K 4
6
Eqs; 10

Where dt is the integration step size and the subscript k indicates the current time t,
and the subscript k+1 indicates the time at t + dt.
VII) Equations of Motions
The following equations of motion can be used to track the state (position,
velocity, attitude, and mass) of a vehicle as it evolves in time under the accelerations due
to thrust, aerodynamics, and gravity; and torques due to aerodynamics and thrusters
mounted on moment arms in the vehicle body frame. In these equations, a subscript “I”
attached to a vector denotes a vector resolved in the inertial frame of reference, and
subscript “B” attached to a vector denotes a vector resolved in the body frame of
reference. The subscript “IB” denotes inertial to body. The superscript “T” denotes
transpose. Note that inertia tensors and external torque vectors are most directly
expressed in the body frame. Therefore, the rotational equations of motion are solved in
the body frame.
Let the state vector be defined as follows:
rI 
 
v I 
X  qIB  Eq; 11
 
w 
 B
m 
The derivative of the state is as follows:
v I 
 
 aI 
 
X  q IB 
Eq; 12
w
B 
 
m
 
 
Where:
rI - Inertial position vector of the vehicle
v I - Inertial velocity vector of the vehicle
qIB - Quaternion representing attitude of the vehicle (Inertial to body)
wB - Angular velocity of vehicle body frame relative to the inertial frame expressed in the body frame
aI - Translational acceleration of the vehicle in the inertial frame
q IB - Derivative of the quaternion representing the vehicle attitude
w B - Angular acceleration of vehicle body frame relative to the inertial frame expressed in the body
frame
m – Vehicle mass
 - Change in vehicle mass with respect to time
m
Translational (position and velocity) Equations of motion:
rI  vI
qIB  C IB


T
vI  C IB  aThB  aAeroB  aGI
m   flowrate
Eqs; 13
Where:
rI
CIB
- Derivative of Inertial position vector of the vehicle (velocity)
- Inertial to body transformation DCM
aThB
- Acceleration of vehicle due to thrust in the vehicle body frame
aAeroB
- Acceleration of vehicle due to aerodynamics in the vehicle body frame
aGI
- Acceleration of vehicle due to gravity in the inertial frame
vI

m
- Derivative of Inertial velocity vector of the vehicle (acceleration)
- Derivative of mass with respect to time
 thrust 

flowrate - Mass flow rate 
 gSl * ISP 
- Engine thrust
thrust
- Engine specific impulse
ISP
gSl
- Constant relating kilograms force to Newtons
Rotational (attitude) Equations of motion
1
 4 X 4 ( wb )qIB
2
Eqs; 14
1

w B  I * [ B  I wB  3 X 3 wB * hB ]
q IB 
 
Where:
 4 X 4 ( wb ) - 4X4 skew symmetric matrix from angular rate vector in the body frame
 
3 X 3 wB - 3X3 skew symmetric matrix from angular rate vector in the body frame
B
- External torque vector in the vehicle body frame
hB
- Angular momentum vector in the vehicle body frame.
I - Inertia tensor of the vehicle in the vehicle body frame with moments of inertia in the
diagonal elements and products of inertia on the off-diagonal elements.
 I XY
 I XZ 
IYY
 I YZ  Eq; 15
 I ZY
I ZZ 
I - Derivative of the inertia tensor in the vehicle body frame
 I XX
I    IYX
 I ZX
Derivation of angular acceleration relative to the inertial frame resolved in the body
frame:
hI  CIB  hB
T


d
d
CIB T hB
hI 
dt
dt
T
 I  C IB T hB  C IB hB
  C T I w  I w  C
   w * h
  C   C C  I w  I w  C C   w * h
  I w  I w   w * h
w  I   I w   w * h 
I

 
IB
B
B
T
IB
3X 3
B
B
B
IB
IB
T
B
B
IB
I
IB
B
T
IB
B
B
3X 3
Eqs; 16
B
3X 3
B
B
B
1
B
B
B
3X 3
B
B
Where:
hI - Angular momentum vector in the inertial frame.
 I - Torque acting on the vehicle expressed in the inertial frame
Sources of torque in the body frame are aerodynamics, gravity gradients, and thrusters
mounted on moment arms relative to the center of gravity of the vehicle.
As a special note, the quaternion that represents the inertial frame to body frame
transformation (attitude) should be re-normalized periodically to avoid divergence of the
simulation using the following relationships. The most accurate way to re-normalize a
quaternion just turns out to be the projection of the quaternion onto the 4-dimensional
unit hypersphere.
magnitude  qIB [0]2  qIB [1]2  qIB [2]2  qIB [3]2
qIB [0]
magnitude
qIB [1]
qIB [1] 
magnitude
qIB [2]
qIB [2] 
magnitude
qIB [3]
qIB [3] 
magnitude
qIB [0] 
Eqs; 17
References:
1) http://www.maths.tcd.ie/pub/HistMath/People/Hamilton/Letters/BroomeBridge.html
2) Spacecraft Attitude Determination and Control; Edited by James R. Wertz
3) Numerical Methods for Mathematics, Science, and Engineering; John H. Mathews
4) Quaternions and Rotation Sequences; Jack B. Kuipers
Download