-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCessna_model.py
329 lines (222 loc) · 10.6 KB
/
Cessna_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 1 17:54:22 2021
Symmetrical aircraft responses for a rigid aircraft in symmetrical atmospheric turbulence conditions.
Cessna Ce500 Citation I - configuration start (2)
@author: vladg
"""
import numpy as np
import control.matlab as cm
import control as c
np.set_printoptions(precision=5)
class Cessna:
def __init__(self,V=59.9,muc=113,sigma_u=2,sigma_w=3,Lg=150):
"""
Cessna contrusctor
Input: V, muc, sigma_u, sigma_w, Lg
"""
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Prelimianry checks.
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if muc < 90 or muc > 130:
print("\n\n Error in the input parameters ! \n\n")
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# AIRCRAFT FLIGHT CONDITION 'Start(2)'.
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
self.V = V
g0 = 9.80665
m = 6035
self.muc = muc
twmuc = 2*muc
KY2 = 0.893
c = 2.022
S = 24.2
lh = 5.5
# TURBULENCE PARAMETERS
# sigma_u = 2
# sigma_w = 3
# Lg = 150
self.sigma_u = sigma_u
self.sigma_w = sigma_w
self.sigma_ug = sigma_u/V;
self.sigma_ag = sigma_w/V;
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# AIRCRAFT SYMMETRIC AERODYNAMIC DERIVATIVES
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CX0 = 0.0000
CZ0 =-1.250
Cm0 = 0.0000
CXu =-0.2510
CZu =-2.5000
Cmu = 0.0000
CXa = 0.5120
CZa = -5.160
Cma = -0.430
CXq = 0.0000
CZq =-3.8600
Cmq = -7.040
CXd = 0.0000
CZd =-0.6238
Cmd = -1.553
CXfa = 0.0000
CZfa =-1.4700
Cmfa = -3.750
CZfug = 0.000
Cmfug = -Cm0*lh/c;
CZfag= CZfa-CZq;
Cmfag= Cmfa-Cmq;
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# CALCULATION OF AIRCRAFT SYMMETRIC STABILITY DERIVATIVES
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xu = (V/c)*(CXu/twmuc)
xa = (V/c)*(CXa/twmuc)
xt = (V/c)*(CZ0/twmuc)
xd = (V/c)*(CXd/twmuc)
xug = xu
xfug = 0
xag = xa
xfag = 0
zu = (V/c)*( CZu/(twmuc-CZfa))
za = (V/c)*( CZa/(twmuc-CZfa))
zt = (V/c)*(-CX0/(twmuc-CZfa))
zq = (V/c)*((CZq+twmuc)/(twmuc-CZfa))
zd = (V/c)*( CZd/(twmuc-CZfa));
zug = zu
zfug = (V/c)*( CZfug/(twmuc-CZfa))
zag = za
zfag = (V/c)*( CZfag/(twmuc-CZfa))
mu = (V/c)*(( Cmu+CZu*Cmfa/(twmuc-CZfa))/(twmuc*KY2))
ma = (V/c)*(( Cma+CZa*Cmfa/(twmuc-CZfa))/(twmuc*KY2))
mt = (V/c)*((-CX0*Cmfa/(twmuc-CZfa))/(twmuc*KY2))
mq = (V/c)*(Cmq+Cmfa*(twmuc+CZq)/(twmuc-CZfa))/(twmuc*KY2)
md = (V/c)*((Cmd+CZd*Cmfa/(twmuc-CZfa))/(twmuc*KY2))
mug = mu
mfug = (V/c)*(Cmfug+CZfug*Cmfa/(twmuc-CZfa))/(twmuc*KY2)
mag = ma;
mfag = (V/c)*(Cmfag+CZfag*Cmfa/(twmuc-CZfa))/(twmuc*KY2)
# Matrix Dimensions
n = 4 # 4 orignal a/c states
m = 1 # 1 input (elevator deflection)
p = (5,2) # 5 outputs
# # Creating the different c-matrices (c1, c2 &c3) for symmetrical flight
# #c1 matrix
# c1 = np.zeros((n,n))
# c1[0,0] = -2*muc*(c/V)
# c1[1,1] = (CZfa - 2*muc)*(c/V)
# c1[2,2] = -(c/V)
# c1[3,1] = Cmfa*(c/V)
# c1[3,3] = -2*muc*KY2*((c/V)**2)
# #c2 matrix
# c2 = np.zeros((n,n))
# c2[0,0] = -CXu
# c2[0,1] = -CXa
# c2[0,2] = -CZ0
# c2[0,3] = -CXq*(c/V)
# c2[1,0] = -CZu
# c2[1,1] = -CZa
# c2[1,2] = -CX0
# c2[1,3] = -(CZq + 2*muc)*(c/V)
# c2[2,3] = -(c/V)
# c2[3,0] = -Cmu
# c2[3,1] = -Cma
# c2[3,3] = -Cmq*(c/V)
# #c3 matrix
# c3 = np.zeros((n,m))
# c3[0,0] = -CXd
# c3[1,0] = -CZd
# c3[3,0] = -Cmd
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Basic Aircraft Symmetric Model
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A_s = np.array([[xu, xa, xt, 0],
[zu, za, zt, zq],
[0, 0, 0, V/c],
[mu, ma, mt, mq]])
B_s = np.array([[xd],
[zd],
[0],
[md]])
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Symmetric Response to Turbulence
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A_12 = np.zeros((n,3))
A_12 = np.array([[xug, xag, 0],
[zug-zfug*(c/Lg), zag, zfag*(c/V)],
[0, 0, 0],
[mug-mfug*(c/Lg), mag, mfag *(c/V)]])
A_22 = np.zeros((3,3))
A_22 = np.array([[-V/Lg, 0, 0],
[0, 0, 1],
[0, -V**2/(Lg**2), -2*(V/Lg)]])
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Complete Aircraft Dynamics Model (symmetric + turbulence)
# A = [A_11 A_12]
# [0 A_22]
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
self.A = np.zeros((n+3,n+3))
self.B = np.zeros((n+3,3))
self.A[:n,:n] = A_s
self.A[:n,n:] = A_12
self.A[n:,n:] = A_22
self.B[:n,:1] = B_s
self.B[:,1:] = np.array([[0.0, 0.0 ],
[zfug*(c/V)*self.sigma_ug*np.sqrt(2*V/Lg), zfag*(c/V)*self.sigma_ag*np.sqrt(3*V/Lg)],
[0.0, 0.0 ],
[mfug*(c/V)*self.sigma_ug*np.sqrt(2*V/Lg), mfag*(c/V)*self.sigma_ag*np.sqrt(3*V/Lg)],
[self.sigma_ug*np.sqrt(2*V/Lg), 0.0],
[0.0 , self.sigma_ag*np.sqrt(3*V/Lg)],
[0.0, (1-2*np.sqrt(3))*self.sigma_ag*np.power(V/Lg,1.5)]])
self.Bnew = np.array([[ xd, 0.0, 0.0 ],
[ zd, zfug*(c/V)*self.sigma_ug*np.sqrt(2*V/Lg), zfag*(c/V)*self.sigma_ag*np.sqrt(3*V/Lg)],
[ 0.0 , 0.0, 0.0 ],
[ md, mfug*(c/V)*self.sigma_ug*np.sqrt(2*V/Lg), mfag*(c/V)*self.sigma_ag*np.sqrt(3*V/Lg)],
[ 0.0 , self.sigma_ug*np.sqrt(2*V/Lg), 0.0 ],
[ 0.0, 0.0 , self.sigma_ag*np.sqrt(3*V/Lg)],
[ 0.0, 0.0, (1-2*np.sqrt(3))*self.sigma_ag*np.power(V/Lg,1.5)]])
if not np.allclose(self.B,self.Bnew):
print("Error in !?")
print(self.B)
print(self.Bnew)
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Aircraft State Space
# az = V*q - V * alpha
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
p = 5
# self.C = np.array([[1, 0, 0, 0, 0, 0, 0],
# [0, 1, 0, 0, 0, 0, 0],
# [0, 0, 1, 0, 0, 0, 0],
# [0, 0, 0, 1, 0, 0, 0],
# [-V*zu/g0, -V*za/g0, -zt/g0, (V*V/c - V*zq)/g0, -V*(zug-zfug*(c/Lg))/g0, -V*zag/g0, -V*zfag*(c/V)/g0]])
self.C =np.array([[1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]],dtype=float)
self.C[4,:] = V/g0 * (self.A[2,:] - self.A[1,:]) # n_z = V/g0 *theta_dot - V/g0 * alpha_dot
self.D = np.zeros((p,3),dtype=float)
self.D[4,:] = -V*np.array([zd, zfug*(c/V)*self.sigma_ug*np.sqrt(2*V/Lg), zfag*(c/V)*self.sigma_ag*np.sqrt(3*V/Lg)])/g0
#Check the \g0 !!!
def state_space(self):
"""
Method to return the Cessna continuous-time State-Space model
for the selected configuration paramters.
If a different configuration is deisred -> initiliase the aircraft with new parameters
Input : -
Output: control.matlab.StatePsace Object (LTI system)
x = [u ,alpha ,theta, qc/V, u_g, alpha_g, alpha*_g]
u = [delta_e , w1 , w3]
y = [u ,alpha ,theta, qc/V, n_z ]
"""
# prelimianry checks
if(np.shape(self.A) != (7,7)):
print("Wrong matrix A\n")
if(np.shape(self.B) != (7,3)):
print("Wrong matrix B\n")
if(np.shape(self.C) != (5,7)):
print("Wrong matrix C\n")
if(np.shape(self.D) != (5,3)):
print("Wrong matrix D\n")
system = cm.ss(self.A,self.Bnew,self.C,self.D)
return system
cessna = Cessna()
model_ss = cessna.state_space()