-
Notifications
You must be signed in to change notification settings - Fork 6
/
liu_model.py
304 lines (246 loc) · 10.1 KB
/
liu_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
import numpy as np
import pandas as pd
"""Module to calculate the power consumption and estimate the parameters
Note: The arguments in all calculation functions can be of type float or NumPy Array(float) to accomodate different steps in calculation
Bastian Wagner
Carnegie Mellon University - July 2019
Revised:
Arnav Choudhry
Carnegie Mellon University - May 2021
"""
####################################
# Constants for the Calculation
####################################
M = 3.71 # Empty Mass of the drone (kg)
R = 0.175 # Length of a blade (m)
C = 0.03 # Blade Chord width (m)
G = 9.81 # Gravitational constant (m/s²)
N = 4 # Number of props
def thrust(payload, c4, c5, c6, v_air, alpha):
"""Calculate the thrust based on the payload
T=(m+payload)*g
Arguments:
payload {float} -- The payload (g)
Returns:
float -- The thrust (kg*m/s²)
"""
mg = (M + payload) * G
first = np.power(mg - c5 * np.power(v_air * np.cos(alpha), 2), 2)
second = np.power(c4 * np.power(v_air, 2), 2)
return np.sqrt(first + second)
def induced(k1, k2, v_vert, thrust):
"""Calculate the induced power
Arguments:
v_i {float} -- The induced velocity (m/s)
v_air {float} -- The airspeed (m/s)
alpha {float} -- The AOA (rad)
thrust {float} -- The thrust (kg*m/s²)
Returns:
float -- The induced power (W)
"""
return k1 * thrust * ((v_vert / 2) + np.sqrt((v_vert / 2)**2 +
(thrust / (np.power(k2, 2)))))
def angular(thrust, k):
"""Calculate the angular speed
Arguments:
thrust {float} -- The Thrust (kg*m/s²)
k {float} -- The scaling factor k
Returns:
float -- The angular speed
"""
return np.sqrt(thrust / k)
def profile(v_air, thrust, alpha, c2, c3):
"""Calculate the profile power
Arguments:
v_air {float} -- Airspeed (m/s)
thrust {float} -- Thrust (kg*m/s²)
alpha {float} -- AOA (rad)
rho {floar} -- Air Density (kg/m³)
k {float} -- Scaling factor k
c_d {float} -- Drag coefficient of the blades
Returns:
float -- The profile power (W)
"""
return c2 * np.power(thrust, 1.5) + c3 * np.power(
(v_air * np.cos(alpha)), 2) * np.sqrt(thrust)
def parasitic(v_air, c4):
"""Calculate the parasitic power
Arguments:
v_air {float} -- Airspeed (m/s)
rho {floar} -- Air Density (kg/m³)
c_d {float} -- Drag coefficient of the drone
A {float} -- Facing area of the drone (m²)
Returns:
float -- The parasitic power (W)
"""
return c4 * np.power(v_air, 3)
def solve_quart(v_air, thrust, rho, A):
"""Solve the formula for v_i in regard to v_i
Arguments:
v_air {float} -- The airspeed (m/s)
thrust {float} -- The thrust (kg*m/s²)
rho {floar} -- Air Density (kg/m³)
A {float} -- The facing area (m²)
Returns:
float -- The induced speed (m/s)
"""
# Calculate the four solutions for v_i
# Only solution 2 is needed because the others are either negative or unreal
one = -np.sqrt(
np.sqrt((16 * thrust**2) /
(A**2 * rho**2) + 16 * v_air**4) / 8 - v_air**2 / 2)
two = np.sqrt(
np.sqrt((16 * thrust**2) / (A**2 * rho**2) + 16 * v_air**4) / 8 -
v_air**2 / 2)
three = -np.sqrt(-np.sqrt((A**2 * rho**2 * v_air**4 + thrust**2) /
(A**2 * rho**2)) - v_air**2) / np.sqrt(2)
four = np.sqrt(-np.sqrt((A**2 * rho**2 * v_air**4 + thrust**2) /
(A**2 * rho**2)) - v_air**2) / np.sqrt(2)
return two
def power(data, k1, k2, c2, c4, c5):
"""Calculate the combined power consumption
Arguments:
data -- Either an array in scipy x-data format or a tuple of x-data
k {float} -- The scaling factor
c_d {float} -- Drag coefficient of the blade
c_d2 {float} -- Drag coefficient of the dron
A {float} -- Facing area of the drone (m²)
Returns:
float -- The combined power consumption
"""
c1 = k1 / k2
c3 = 0
c6 = 0
# Split the data tuple
vertspd = data.loc["vertspd", :].to_numpy()
airspeed = data.loc["airspeed", :].to_numpy()
aoa = data.loc["aoa", :].to_numpy()
payload = data.loc["payload", :].to_numpy()
density = data.loc["density", :].to_numpy()
results = []
# Calculate the induced power based on the current flight status
# Currently only forward flight data is being read from the flights
# for v_vert, v_air, alpha, pld, rho in zip(vertspd, airspeed, aoa, payload, density):
# Calculate the single powers and needed values
t = thrust(payload, c4, c5, c6, airspeed, aoa)
# When the airspeed is over 1 m/s, the drone is in forward flight
# if np.round(np.abs(v_air), decimals=2) > 1:
# v_i = solve_quart(airspeed, t, density, A)
p_i = induced(k1, k2, vertspd, t)
# # Else, when the vertical speed is between -0.5 and 0.5 m/s, the drone is in hover
# elif np.round(v_vert, decimals=2) < 0.5 and np.round(v_vert, decimals=2) > -0.5:
# v_i = np.sqrt(t/(2*rho*A))
# p_i = t*v_i
# # # Else, when the vertical speed is greater than 0.5 m/s, the drone is in climb
# elif np.round(v_vert, decimals=2) >= 0.5:
# v_i = (-v_vert/2)+np.sqrt(np.power(v_vert/2,2)+t/(2*rho*A))
# p_i = t*(v_i+v_vert)
# # Else, when the vetical speed is less than 0.5 m/s, the drone is in descend
# elif np.round(v_vert, decimals=2) <= -0.5:
# v_i = (-v_vert/2)+np.sqrt(np.power(v_vert/2,2)-t/(2*rho*A))
# p_i = t*(v_i+v_vert)
p_p = profile(airspeed, t, aoa, c2, c3)
p_pa = parasitic(airspeed, c4)
# Combine all powers
result = p_i + p_p + p_pa
return result
def fwd_power(data, c4, c5):
"""Calculate the combined power consumption
Arguments:
data -- Either an array in scipy x-data format or a tuple of x-data
k {float} -- The scaling factor
c_d {float} -- Drag coefficient of the blade
c_d2 {float} -- Drag coefficient of the dron
A {float} -- Facing area of the drone (m²)
Returns:
float -- The combined power consumption
"""
k1 = 0.9999
k2 = 100
c2 = 2.06187671
c1 = k1 / k2
c3 = 0
c6 = 0
# Split the data tuple
vertspd = data.loc["vertspd", :].to_numpy()
airspeed = data.loc["airspeed", :].to_numpy()
aoa = data.loc["aoa", :].to_numpy()
payload = data.loc["payload", :].to_numpy()
density = data.loc["density", :].to_numpy()
results = []
# Calculate the induced power based on the current flight status
# Currently only forward flight data is being read from the flights
# for v_vert, v_air, alpha, pld, rho in zip(vertspd, airspeed, aoa, payload, density):
# Calculate the single powers and needed values
t = thrust(payload, c4, c5, c6, airspeed, aoa)
# When the airspeed is over 1 m/s, the drone is in forward flight
# if np.round(np.abs(v_air), decimals=2) > 1:
# v_i = solve_quart(airspeed, t, density, A)
p_i = induced(k1, k2, 0, t)
# # Else, when the vertical speed is between -0.5 and 0.5 m/s, the drone is in hover
# elif np.round(v_vert, decimals=2) < 0.5 and np.round(v_vert, decimals=2) > -0.5:
# v_i = np.sqrt(t/(2*rho*A))
# p_i = t*v_i
# # # Else, when the vertical speed is greater than 0.5 m/s, the drone is in climb
# elif np.round(v_vert, decimals=2) >= 0.5:
# v_i = (-v_vert/2)+np.sqrt(np.power(v_vert/2,2)+t/(2*rho*A))
# p_i = t*(v_i+v_vert)
# # Else, when the vetical speed is less than 0.5 m/s, the drone is in descend
# elif np.round(v_vert, decimals=2) <= -0.5:
# v_i = (-v_vert/2)+np.sqrt(np.power(v_vert/2,2)-t/(2*rho*A))
# p_i = t*(v_i+v_vert)
p_p = profile(airspeed, t, aoa, c2, c3)
p_pa = parasitic(airspeed, c4)
# Combine all powers
result = p_i + p_p + p_pa
return result
def ascend_power(data, k1, k2, c2):
"""Calculate the combined power consumption
Arguments:
data -- Either an array in scipy x-data format or a tuple of x-data
k {float} -- The scaling factor
c_d {float} -- Drag coefficient of the blade
c_d2 {float} -- Drag coefficient of the dron
A {float} -- Facing area of the drone (m²)
Returns:
float -- The combined power consumption
"""
c1 = k1 / k2
c3 = 0
c6 = 0
# Split the data tuple
vertspd = data.loc["vertspd", :].to_numpy()
airspeed = data.loc["airspeed", :].to_numpy()
aoa = data.loc["aoa", :].to_numpy()
payload = data.loc["payload", :].to_numpy()
density = data.loc["density", :].to_numpy()
results = []
# Calculate the induced power based on the current flight status
# Currently only forward flight data is being read from the flights
# for v_vert, v_air, alpha, pld, rho in zip(vertspd, airspeed, aoa, payload, density):
# Calculate the single powers and needed values
t = (M + payload) * G
# When the airspeed is over 1 m/s, the drone is in forward flight
# if np.round(np.abs(v_air), decimals=2) > 1:
# v_i = solve_quart(airspeed, t, density, A)
p_i = induced(k1, k2, vertspd, t)
# # Else, when the vertical speed is between -0.5 and 0.5 m/s, the drone is in hover
# elif np.round(v_vert, decimals=2) < 0.5 and np.round(v_vert, decimals=2) > -0.5:
# v_i = np.sqrt(t/(2*rho*A))
# p_i = t*v_i
# # # Else, when the vertical speed is greater than 0.5 m/s, the drone is in climb
# elif np.round(v_vert, decimals=2) >= 0.5:
# v_i = (-v_vert/2)+np.sqrt(np.power(v_vert/2,2)+t/(2*rho*A))
# p_i = t*(v_i+v_vert)
# # Else, when the vetical speed is less than 0.5 m/s, the drone is in descend
# elif np.round(v_vert, decimals=2) <= -0.5:
# v_i = (-v_vert/2)+np.sqrt(np.power(v_vert/2,2)-t/(2*rho*A))
# p_i = t*(v_i+v_vert)
p_p = profile(0, t, 0, c2, 0)
# Combine all powers
result = p_i + p_p
return result
def optimum_values():
# default values for liu model
popt = [0.99545857,100.,2.06852797,0.02745631,0.01473469]
return popt