Вы находитесь на странице: 1из 16

AERO3560

FLIGHT MECHANICS 1
TUTORIAL ASSIGNMENT 1
NICHOLAS GIANNELIS
308150856
Monday 22nd August 2011



2

Contents
Page No.
1. Question 1 3
1.1 Part A 3
1.2 Part B 3
2. Question 2 4
3. Question 3 5
3.1 Part A 5
3.2 Part B 6
3.3 Part C 6
4. Question 4 7
4.1 Part A 7
4.2 Part B 8
5. Appendix A-Matlab Script to Question 3 11
5.1 Part A 11
5.2 Part B 12
6. Appendix B-Matlab Script to Question 4 13
6.1 Quaternion Integration 13
6.2 Euler Angle Integration 14














3

1. Question 1
1.1 Part A

p
q
r
= _
2S
u
u
_
In order to convert from body frame to LVLH we require the transformation matrix I
vB.

I
Bv
= I
1
(())I
2
(0())I
3
(())
I
1
(X
1
) = _
1 u u
u cos X
1
sinX
1
u sinX
1
cos X
1
_
I
2
(X
2
) = _
cos X
2
u sinX
2
u 1 u
sinX
2
u cos X
2
_
I
3
(X
3
) = _
cos X
3
sinX
3
u
sinX
3
cos X
3
u
u u 1
_
As we only have a rolling body rate we can express X
1
as a function of time, explicitly
X
1
= 2S =
Sn
S6
ro
The transformation matrix from the LVLH frame to the body frame thus becomes:
I
Bv
= I
1
_
Sn
S6
] I
2
(u)I
3
(u) =
l
l
l
l
l
1 u u
u cos
Sn
S6
Sn
S6
u sin
Sn
S6
cos
Sn
S6
1
1
1
1
1

However, we require the transformation matrix from body to LVLH; this is merely the transpose of
the above:
I
vB
=
l
l
l
l
l
1 u u
u cos
Sn
S6
sin
Sn
S6
u sin
Sn
S6
cos
Sn
S6
1
1
1
1
1

1.2 Part B
In order to allow for simultaneous pitching the governing equations incorporate highly coupled
nonlinear terms. In order to determine the aircraft attitude one would have to calculate the Euler
angle rates of change and integrate these rates over the time of simulation. The integration
procedure may involve simple Euler integration, incrementing the original value of each Euler angle
by the product of the time differential and the rate of change.
4

2. Question 2
In order to establish a transformation matrix from the Sydney reference frame (=151, = -34) to
the Saskatoon reference frame (=-106.66, = 52.13) we consider three separate rotations. The first
of which is a -124 rotation about the y-axis (easterly direction) to bring the system to the North
Pole. The transformation matrix is as below:
I
2
(124) = _
cos 124 u sin124
u 1 u
sin124 u cos 124
_ = _
u.SS9 u u.829
u 1 u
u.829 u u.SS9
_
The North Pole acts as a singularity on the Earths surface with respect to the North East Down
reference frame, as such we may then make a rotation about the x-axis of -257.66 to bring the
system to the same longitude as Saskatoon as below:
I
1
(2S7) = _
1 u u
u cos 2S7.66 sin2S7.66
u sin2S7.66 cos 2S7.66
_ = _
1 u u
u u.214 u.977
u u.977 u.214
_
The system is then brought to the correct latitude as Saskatoon by considering a 37.87 rotation
about the y-axis:
I
2
(S7.87) = _
cos S7.87 u sinS7.87
u 1 u
sinS7.87 u cos S7.87
_ = _
u.789 u u.614
u 1 u
u.614 u u.789
_
The transformation matrix relating the Sydney and Saskatoon reference frame is thus a product of
the aforementioned rotation matrices, explicitly:
I
Sus-S
= I
2
(124) I
1
(2S7) I
2
(S7.87)
The matrix multiplication is performed in Matlab, yielding:
I
Sus-S
= _
u.SSu2 u.8u99 u.2uS4
u.S997 u.21S7 u.7712
u.S811 u.S46S u.6uSS
_
In order to best describe the relative orientation of a person standing at Saskatoon with respect to
Sydney reference frame we consider the Saskatoon up vector. We take the Inverse of the I
Sus-S

transformation matrix and multiply this by a unit up vector in the Saskatoon frame, yielding:
I
Sus-S
-1
= I
S-Sus
= _
u.SSu2 u.S997 u.S811
u.8u99 u.21S7 u.S46S
u.2uS4 u.7712 u.6uSS
_
_
u.SSu2 u.S997 u.S811
u.8u99 u.21S7 u.S46S
u.2uS4 u.7712 u.6uSS
_ _
u
u
1
_ = _
u.S46S
u.S811
u.6uSS
_
In the Sydney reference frame. The Saskatoon up vector is illustrated in dark blue below:

5

-0.5
0
0.5
1
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
-1
-0.8
-0.6
-0.4
-0.2
0

North
Sydney North-East-Down
East

D
o
w
n
Saskatoon Up Vector
North
East
Down












3. Question 3
3.1 Part A
The Matlab script written to convert Euler Angles to Quaternions is provided in the appendix. The
table of provided Euler Angles is supplied below, followed by the corresponding Quaternions output
from the function file E2Q.
EulerAngles
Case
1 0 0 90
2 0 -90 0
3 -90 0 0
4 0 90 -90
5 45 45 45
6 45 -30 100
7 -150 -10 -120
8 97 -103 43

Quaternions
Case
0

1

2

3

1 0.7071 0 0 0.7071
2 0.7071 0 -0.7071 0
3 0.7071 -0.7071 0 0
4 0.5000 0.5000 0.5000 -0.5000
5 0.8446 0.1913 0.4619 0.1913
6

6 0.4977 0.4208 0.1295 0.7473
7 0.0560 -0.5007 0.8221 -0.2654
8 0.1690 0.6239 -0.3116 0.6965

3.2 Part B
The Matlab script to convert from Quaternions to Euler Angles is provided in the appendix. The table
below provides the Quaternions, their conversion to Euler angles and a conversion back to
Quaternions using the E2Q function to confirm its functionality.
Quaternions
Case
0

1

2

3

1 0.5862 -0.6941 0.1349 0.3954
2 0.4822 -0.8698 0.0914 -0.0507

Euler Angles
Case
1 -90.0046 45.0007 23.0034
2 -121.9938 -0.0030 -11.9992

E2Q(ans)

Case
0

1

2

3

1 0.5862 -0.6941 0.1349 0.3954
2 0.4822 -0.8698 0.0914 -0.0507
As the conversion confirms the precise input arguments we may ascertain the codes function
correctly.
3.3 Part C
>> Q2E(ans)

Case
1 0 0 90.0000
2 0 -90.0000 0
3 -90.0000 0 0
4 0 90.0000 -90.0000
5 45.0000 45.0000 45.0000
6 45.0000 -30.0000 100.0000
7 -150.0000 -10.0000 -120.0000
8 -83.0000 -77.0000 -137.0000

In employing the inversion quaternion function to convert back to Euler angles it is evident that all
bar the last case are identical to the input arguments. Although the final arguments may appear to
differ when input into the trigonometric functions governing the quaternion and Euler angle
conversion equations they yield identical results. As such the script cannot discern between
trigonometrically identical arguments.
7

0 2 4 6 8 10 12 14 16 18 20
-200
-150
-100
-50
0
50
100
150
200
Euler Angles Derived from Quaternion Integration
Time(s)
E
u
l
e
r

A
n
g
l
e
s

(
d
e
g
)


Phi
Theta
Psi
0 2 4 6 8 10 12 14 16 18 20
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Quaternions Derived from Quaternion Integration
Time(s)
Q
u
a
t
e
r
n
i
o
n
s

(
r
a
d
)


e0
e1
e2
e3
0 2 4 6 8 10 12 14 16 18 20
0
50
100
150
200
250
300
Euler Angles Derived Directly from Euler Rates
Time(s)
E
u
l
e
r

A
n
g
l
e
s

(
d
e
g
)


Phi
Theta
Psi
0 2 4 6 8 10 12 14 16 18 20
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Quaternions Derived Directly from Euler Rates
Time(s)
Q
u
a
t
e
r
n
i
o
n
s

(
r
a
d
)


e0
e1
e2
e3
4. Question 4
4.1 Part A
Presented below are the output plots of Euler angle and Quaternion variation with time, as derived
from the quat_int and euler_int functions over a twenty second time interval with yaw rate of 5.6
seconds (Student Number 308150856).
Quaternion Integration with normalising correction










Euler angle Direct Integration











8

0 2 4 6 8 10 12 14 16 18 20
-200
-150
-100
-50
0
50
100
150
200
250
300
Euler Angles Derived from Quaternion Integration
Time(s)
E
u
l
e
r

A
n
g
l
e
s

(
d
e
g
)


Phi
Theta
Psi
0 2 4 6 8 10 12 14 16 18 20
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Quaternions Derived from Quaternion Integration
Time(s)
Q
u
a
t
e
r
n
i
o
n
s

(
r
a
d
)


e0
e1
e2
e3
Discussion of difference in results
As evident when comparing the prior Euler angle and Quaternion integration not a great deal of
discrepancy can be seen, bar a distinct jump in the Quaternion integration Euler Angle plot. The
Quaternion angles are bounded between the range 180 and thus the apparent discontinuity is
simply a switch from 180 to -180, the same point. The Euler angles derived from the Euler rate
integration however are unbounded and continuous.
In order to better observe any difference in results the plots for Euler rate and Quaternion rate
integration are overlayed below with dashed segments representing Euler rate integration and solid
lines Quaternion integration. Small differences are evident as the time of simulation increase, with
the curves appearing to diverge. This divergence is an expected characteristic as the direct
integration of Euler rates accumulates the error resulting from the linear segmented Euler
integration method. The Quaternion integration however employs a normalising factor in order to
mitigate this error at each time step. As such as the length of simulation is increased we would
expect a greater divergence of the two curves. Further the timestep of 0.1 s is quite large relative to
the rotation rates and as such has quite a bearing on the results. The Quaternions split this time step
across four variables rather than three, again mitigating error.










4.2 Part B
By imposing a zero roll rate on the system it necessarily assures that the aircraft will exhibit a vertical
nose up attitude, the point of singularity regarding Euler angle attitude representation. Distinct
discrepancies are evident between the quaternion and Euler rate integration methods with zero roll
rate. It is evident that at the point of singularity (approximately 15 seconds) theta attains a
maximum value regarding quaternion integration and phi and psi attain their equivalent
trigonometric values. The Euler rate integration plot however permits the unbounded increase of
theta.

9

0 2 4 6 8 10 12 14 16 18 20
-100
-50
0
50
100
150
200
Euler Angles Derived from Quaternion Integration
Time(s)
E
u
l
e
r

A
n
g
l
e
s

(
d
e
g
)


Phi
Theta
Psi
0 2 4 6 8 10 12 14 16 18 20
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
Quaternions Derived from Quaternion Integration
Time(s)
Q
u
a
t
e
r
n
i
o
n
s

(
r
a
d
)


e0
e1
e2
e3
0 2 4 6 8 10 12 14 16 18 20
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
Quaternions Derived Directly from Euler Rates
Time(s)
Q
u
a
t
e
r
n
i
o
n
s

(
r
a
d
)


e0
e1
e2
e3
0 2 4 6 8 10 12 14 16 18 20
0
20
40
60
80
100
120
140
Euler Angles Derived Directly from Euler Rates
Time(s)
E
u
l
e
r

A
n
g
l
e
s

(
d
e
g
)


Phi
Theta
Psi
r = 0 deg/s


























10

0 2 4 6 8 10 12 14 16 18 20
-100
-50
0
50
100
150
200
Euler Angles Derived from Quaternion Integration
Time(s)
E
u
l
e
r

A
n
g
l
e
s

(
d
e
g
)


Phi
Theta
Psi
0 2 4 6 8 10 12 14 16 18 20
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
Quaternions Derived from Quaternion Integration
Time(s)
Q
u
a
t
e
r
n
i
o
n
s

(
r
a
d
)


e0
e1
e2
e3
0 2 4 6 8 10 12 14 16 18 20
0
200
400
600
800
1000
1200
1400
Euler Angles Derived Directly from Euler Rates
Time(s)
E
u
l
e
r

A
n
g
l
e
s

(
d
e
g
)


Phi
Theta
Psi
0 2 4 6 8 10 12 14 16 18 20
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
Quaternions Derived Directly from Euler Rates
Time(s)
Q
u
a
t
e
r
n
i
o
n
s

(
r
a
d
)


e0
e1
e2
e3
As another means of comparison we consider the system experiencing a near zero roll rate. At the
singularity point it is evident the Euler rate integration yields nonsensical results, indicating an
increase in phi and psi on the order of 1200%. The Quaternion integration procedure remains well
behaved at this point of singularity. The Quaternion plots accentuate this interpretation, as we see
kinks in the Quaternion plot at the singularity point whereas the Quaternion rate integration
maintains a smooth continuous curve.























11

5. Appendix A-Matlab Script Q3
5.1 Part A-Euler Angle to Quaternions
function [ Quaternions ] = E2Q( EulerAngles )
%Function file to convert Euler angles to Quaternions
% Each set of Euler angles is entered as a row vector
% EulerAngles = [phi1 theta1 psi1;phi2 theta2 psi2;etc]
% Quaternions are output in sets of row vectors corresponding to
% the relevant Euler angle row vector
% Quaternions = [e01 e11 e21 e31;e02 e12 e22 e32;etc]

%%%Convert Euler angles to half angles in radians
euler = 0.5*EulerAngles*pi/180;

%%%Convert Euler angle to Quaternion components through relevant
% equations (Lecture Notes Week 2 Pg 37a)
e0 = cos(euler(:,3)).*cos(euler(:,2)).*sin(euler(:,1))-
sin(euler(:,3))...
.*sin(euler(:,2)).*cos(euler(:,1));

e1 =
cos(euler(:,3)).*cos(euler(:,2)).*cos(euler(:,1))+sin(euler(:,3))...
.*sin(euler(:,2)).*sin(euler(:,1));

e2 =
cos(euler(:,3)).*sin(euler(:,2)).*cos(euler(:,1))+sin(euler(:,3))...
.*cos(euler(:,2)).*sin(euler(:,1));

e3 = -
cos(euler(:,3)).*sin(euler(:,2)).*sin(euler(:,1))+sin(euler(:,3))...
.*cos(euler(:,2)).*cos(euler(:,1));

%%%Check root sum square of quaternion components to ensure
%%%equations have been input in correct format
musquared = e0.^2+e1.^2+e2.^2+e3.^2;

if musquared > 2
fprintf('Calculation Error-Root Sum square too large\n');
end

%%%Output Quaternion Matrix
Quaternions = [e0 e1 e2 e3];

end

M-file to call Euler angle conversion
clc
clear all
close all
EulerAngles = [0 0 90;0 -90 0;-90 0 0;0 90 -90; 45 45 45;45 -30
100;-150 -10 -120;97 -103 43]
E2Q(EulerAngles)
12

5.2 Part B-Quaternions to Euler Angles
function [ EulerAngles ] = Q2E( quat )
%Function file to convert Quaternions to Euler angles
% Each set of Quaternions is entered as a row vector
% quat = [e01 e11 e21 e31;e02 e12 e22 e32;etc]
% Euler Angles are output in sets of row vectors corresponding to
% the relevant Quaternion row vector
% EulerAngles = [phi1 theta1 psi1;phi2 theta2 psi2;etc]

%%%Convert Quaternions to Euler Angles through relevant equations
% (Lecture Notes Week 2 Pg 37)
phi =
atan2((quat(:,3).*quat(:,4)+quat(:,1).*quat(:,2)),(quat(:,1)...
.^2+quat(:,4).^2-0.5));

theta = atan2((quat(:,1).*quat(:,3)-
quat(:,2).*quat(:,4)),((quat(:,1)...
.^2+quat(:,2).^2-
0.5).^2+(quat(:,2).*quat(:,3)+quat(:,1).*quat(:,4)).^2).^0.5);

psi =
atan2((quat(:,2).*quat(:,3)+quat(:,1).*quat(:,4)),(quat(:,1)...
.^2+quat(:,2).^2-0.5));

%%%Output Euler Angles in degrees
EulerAngles = [phi theta psi]*180/pi;

end

M-file to call Quaternion conversion
clc
clear all
close all
quat = [0.5862 -0.6941 0.1349 0.3954;0.4822 -0.8698 0.0914 -0.0507]
Q2E(quat)









13

6. Appendix B-Matlab Script Q4
6.1 Quaternion Integration
function [ euler,quat ] = quat_int( initial_euler, body_rates )
%Function file integrating Quaternion rates to determine aircraft attitude
% Initial conditions are input as below
% initial_euler = [phi theta psi]-initial Euler angles
% body_rates = [p q r]-initial rotation rates about body axis

% Both Euler angles and Quaternions are output as matricies with a unit
% timestep increase from row to row.
% Plots are output for both Quaternion and Euler angle variation with
% time

%%%Initialise Euler angles vector for initial values
phi = initial_euler(1);

theta = initial_euler(2);

psi = initial_euler(3);

euler = [phi theta psi];

%%%Convert Euler angles to Quaternions for Quaternion Integration, take
% transpose of vector for subsequent calculations such that values
% increasing with timestep are stored as new columns in the Quaternion
% (quat) matrix
quat = E2Q(euler)';

%%%Initialise body rotation rates in rad/sec
p = body_rates(1)*pi/180;

q = body_rates(2)*pi/180;

r = body_rates(3)*pi/180;

%%%Initialise Time/Step Variables
time = 20; %Duration of simulation

dt = 0.1; %Time step

n = time/dt; %Number of iterations

%%%Input equation for Quaternion rates calculation as per Lecture Notes
% Week 2 Pg 37.
quat_dot(:,:) = 0.5*[-quat(2,:) -quat(3,:) -quat(4,:);...
quat(1,:) -quat(4,:) quat(3,:);...
quat(4,:) quat(1,:) -quat(2,:);...
-quat(3,:) quat(2,:) quat(1,:)]*[p;q;r];

%%%Define for loop for duration of simulation, apply Euler Integration
for i = 1:n
%%%Euler Integration
quat(:,i+1) = quat(:,i)+quat_dot(:,i)*dt;

14

%%%Normalise Quaternions for correction
Mu = (quat(1,i+1)^2+quat(2,i+1)^2+quat(3,i+1)^2+quat(4,i+1)^2)^0.5;

quat(:,i+1) = quat(:,i+1)./Mu;

%%%Increment Euler angle rates
quat_dot(:,i+1) = 0.5*[-quat(2,i) -quat(3,i) -quat(4,i);...
quat(1,i) -quat(4,i) quat(3,i);...
quat(4,i) quat(1,i) -quat(2,i);...
-quat(3,i) quat(2,i) quat(1,i)]*[p;q;r];

end

%%%Transpose quaternion vector to output as matrix with unit time step
% increasing from row to row
quat = quat';

%%%Convert quaternions to Euler angles
euler = Q2E(quat);

%%%Plot Results
plot(0:0.1:20, euler);
title('Euler Angles Derived from Quaternion Integration');
xlabel('Time(s)');
ylabel('Euler Angles (deg)');
legend('Phi','Theta','Psi');
grid on;
grid minor;

figure

plot(0:0.1:20, quat);
title('Quaternions Derived from Quaternion Integration');
xlabel('Time(s)');
ylabel('Quaternions (rad)');
legend('e0','e1','e2','e3');
grid on;
grid minor;
end

M-file to call Quaternion Integration
clc;
clear all;
close all;
initial_euler = [0 0 90];
body_rates = [0 6 5.6];
quat_int(initial_euler,body_rates)

6.2 Euler Angle Integration
function [ euler,quaternions ] = euler_int( initial_euler, body_rates )
%Function file integrating Euler rates to determine aircraft attitude
% Initial conditions are input as below
% initial_euler = [phi theta psi]-initial Euler angles
% body_rates = [p q r]-initial rotation rates about body axis

% Both Euler angles and Quaternions are output as matricies with a unit
% timestep increase from row to row.
15

% Plots are output for both Quaternion and Euler angle variation with
% time

%%%Initialise euler angles in radians
phi = initial_euler(1)*pi/180;

theta = initial_euler(2)*pi/180;

psi = initial_euler(3)*pi/180;

euler = [phi; theta; psi];

%%%Initialise body rotation rates in rad/sec
p = body_rates(1)*pi/180;

q = body_rates(2)*pi/180;

r = body_rates(3)*pi/180;

%%%Initialise Time/Step Variables
time = 20; %Duration of simulation

dt = 0.1; %Time step

n = time/dt; %Number of iterations

%%%Input equation for Euler rates calculation as per Lecture Notes Week 2
% Pg 31
euler_dot(:,:) = [1 sin(euler(1,:))*tan(euler(2,:))
cos(euler(1,:))*tan(euler(2,:));...
0 cos(euler(1,:)) -sin(euler(1,:));...
0 sin(euler(1,:))*sec(euler(2,:)) cos(euler(1,:))*sec(euler(2,:))]*...
[p;q;r];

%%%Define for loop for duration of simulation, apply Euler Integration

for i = 1:n
%%%Euler Integration
euler(:,i+1) = euler(:,i)+euler_dot(:,i)*dt;

%%%Increment Euler angle rates
euler_dot(:,i+1) = [1 sin(euler(1,i))*tan(euler(2,i))
cos(euler(1,i))*tan(euler(2,i));...
0 cos(euler(1,i)) -sin(euler(1,i));...
0 sin(euler(1,i))*sec(euler(2,i)) cos(euler(1,i))*sec(euler(2,i))]*...
[p;q;r];
end

%%%Transpose euler vector to output as matrix with unit time step
% increasing from row to row
euler = (euler*180/pi)';

%%%Convert Euler angles to quaternions
quaternions = E2Q(euler)

%%%Plot Results
plot(0:0.1:20, euler);
title('Euler Angles Derived Directly from Euler Rates');
16

xlabel('Time(s)');
ylabel('Euler Angles (deg)');
legend('Phi','Theta','Psi');
grid on;
grid minor;

figure

plot(0:0.1:20, quaternions);
title('Quaternions Derived Directly from Euler Rates');
xlabel('Time(s)');
ylabel('Quaternions (rad)');
legend('e0','e1','e2','e3');
grid on;
grid minor;
end


M-file to call Euler Angle Integration
clc;
clear all;
close all;
initial_euler = [0 0 90];
body_rates = [0 6 5.6];
euler_int(initial_euler,body_rates)

Вам также может понравиться