/
transition_segment_test.py
388 lines (304 loc) · 16.4 KB
/
transition_segment_test.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# transition_segment_test.py
#
# Created: Mar 2022, R. Erhard
# Modified:
""" setup file for transition segment test regression with a tiltrotor"""
# ----------------------------------------------------------------------
# Imports
# ----------------------------------------------------------------------
import SUAVE
from SUAVE.Core import Units
from SUAVE.Methods.Performance.estimate_stall_speed import estimate_stall_speed
from SUAVE.Input_Output.VTK.save_vehicle_vtk import save_vehicle_vtks
from SUAVE.Plots.Performance import *
from SUAVE.Core import Data
import scipy as sp
import numpy as np
import pylab as plt
import sys
import os
sys.path.append('../Vehicles')
# the analysis functions
from Tiltrotor import vehicle_setup, configs_setup
# ----------------------------------------------------------------------
# Main
# ----------------------------------------------------------------------
def main():
# -----------------------------------------
# Setup the vehicle configs and analyses
# -----------------------------------------
configs, analyses = full_setup()
configs.finalize()
analyses.finalize()
# Evaluate the mission
mission = analyses.missions.base
results = mission.evaluate()
# Plot results
plot_mission(results,configs)
# Generate vtks for animation of the tiltrotor through the transition segment
#save_transition_animation_paraview(results,configs,save_path=None)
# Check throttles
departure_throttle = results.segments.departure.conditions.propulsion.throttle[:,0]
transition_1_throttle = results.segments.transition_1.conditions.propulsion.throttle[:,0]
cruise_throttle = results.segments.cruise.conditions.propulsion.throttle[:,0]
print(departure_throttle)
print(transition_1_throttle)
print(cruise_throttle)
# Truth values
departure_throttle_truth = 0.6516875478807475
transition_1_throttle_truth = 0.6013997974737667
cruise_throttle_truth = 0.46492807449474316
# Store errors
error = Data()
error.departure_throttle = np.abs(departure_throttle[-1] - departure_throttle_truth)
error.transition_1_throttle = np.abs(transition_1_throttle[-1] - transition_1_throttle_truth)
error.cruise_throttle = np.abs(cruise_throttle[-1] - cruise_throttle_truth)
print('Errors:')
print(error)
for k,v in list(error.items()):
assert(np.abs(v)<1e-6)
plt.show()
return
# ----------------------------------------------------------------------
# Analysis Setup
# ----------------------------------------------------------------------
def full_setup():
# vehicle data
vehicle = vehicle_setup()
configs = configs_setup(vehicle)
# vehicle analyses
configs_analyses = analyses_setup(configs)
# mission analyses
mission = mission_setup(configs_analyses,vehicle)
missions_analyses = missions_setup(mission)
analyses = SUAVE.Analyses.Analysis.Container()
analyses.configs = configs_analyses
analyses.missions = missions_analyses
return configs, analyses
# ----------------------------------------------------------------------
# Define the Vehicle Analyses
# ----------------------------------------------------------------------
def analyses_setup(configs):
analyses = SUAVE.Analyses.Analysis.Container()
# build a base analysis for each config
for tag,config in list(configs.items()):
analysis = base_analysis(config)
analyses[tag] = analysis
return analyses
def base_analysis(vehicle):
# ------------------------------------------------------------------
# Initialize the Analyses
# ------------------------------------------------------------------
analyses = SUAVE.Analyses.Vehicle()
# ------------------------------------------------------------------
# Basic Geometry Relations
sizing = SUAVE.Analyses.Sizing.Sizing()
sizing.features.vehicle = vehicle
analyses.append(sizing)
# ------------------------------------------------------------------
# Weights
weights = SUAVE.Analyses.Weights.Weights_eVTOL()
weights.vehicle = vehicle
analyses.append(weights)
# ------------------------------------------------------------------
# Aerodynamics Analysis
aerodynamics = SUAVE.Analyses.Aerodynamics.Fidelity_Zero()
aerodynamics.geometry = vehicle
analyses.append(aerodynamics)
# ------------------------------------------------------------------
# Energy
energy= SUAVE.Analyses.Energy.Energy()
energy.network = vehicle.networks
analyses.append(energy)
# ------------------------------------------------------------------
# Planet Analysis
planet = SUAVE.Analyses.Planets.Planet()
analyses.append(planet)
# ------------------------------------------------------------------
# Atmosphere Analysis
atmosphere = SUAVE.Analyses.Atmospheric.US_Standard_1976()
atmosphere.features.planet = planet.features
analyses.append(atmosphere)
# done!
return analyses
# ----------------------------------------------------------------------
# Define the Mission
# ----------------------------------------------------------------------
def mission_setup(analyses,vehicle):
vehicle_mass = vehicle.mass_properties.takeoff
reference_area = vehicle.reference_area
V_stall = estimate_stall_speed(vehicle_mass,reference_area,altitude=0*Units.feet,maximum_lift_coefficient=1.2)
max_vertical_rate = 3.6 * Units['m/s']
# ------------------------------------------------------------------
# Initialize the Mission
# ------------------------------------------------------------------
mission = SUAVE.Analyses.Mission.Sequential_Segments()
mission.tag = 'tiltrotor_mission'
#airport
airport = SUAVE.Attributes.Airports.Airport()
airport.altitude = 0.0 * Units.ft
airport.delta_isa = 0.0
airport.atmosphere = SUAVE.Attributes.Atmospheres.Earth.US_Standard_1976()
mission.airport = airport
# unpack Segments module
Segments = SUAVE.Analyses.Mission.Segments
# base segment
base_segment = Segments.Segment()
base_segment.state.numerics.number_control_points = 4
ones_row = base_segment.state.ones_row
base_segment.process.initialize.initialize_battery = SUAVE.Methods.Missions.Segments.Common.Energy.initialize_battery
# -------------------------------------------------------------------------
# Segment 0: Takeoff Vertically
# -------------------------------------------------------------------------
segment = Segments.Hover.Climb(base_segment)
segment.tag = "Departure"
segment.analyses.extend( analyses.hover_climb)
segment.altitude_start = 0.0 * Units.ft
segment.altitude_end = 40. * Units.ft
segment.climb_rate = 300. * Units['ft/min']
segment.battery_energy = vehicle.networks.battery_propeller.battery.max_energy
segment.state.unknowns.throttle = 1.0 * ones_row(1)
segment.process.iterate.conditions.stability = SUAVE.Methods.skip
segment.process.finalize.post_process.stability = SUAVE.Methods.skip
segment = vehicle.networks.battery_propeller.add_unknowns_and_residuals_to_segment(segment,\
initial_power_coefficient = 0.06)
# add to mission
mission.append_segment(segment)
# --------------------------------------------------------------------------
# Segment 1: First Transition Segment: Linear Speed, Constant Climb Rate
# --------------------------------------------------------------------------
# Use original transition segment, converge on rotor y-axis rotation and throttle
segment = Segments.Transition.Constant_Acceleration_Constant_Pitchrate_Constant_Altitude(base_segment)
segment.tag = "Transition_1"
segment.analyses.extend( analyses.transition_1 )
segment.altitude = 40.0 * Units.ft
segment.acceleration = 2.3 * Units['m/s/s']
segment.air_speed_start = 0.0 * Units.mph # starts from hover
segment.air_speed_end = 1.2 * V_stall # increases linearly in time to stall speed
segment.pitch_initial = 0.0 * Units.degrees
segment.pitch_final = 3.6 * Units.degrees
segment.state.unknowns.throttle = 0.95 * ones_row(1)
segment.process.iterate.conditions.stability = SUAVE.Methods.skip
segment.process.finalize.post_process.stability = SUAVE.Methods.skip
segment = vehicle.networks.battery_propeller.add_tiltrotor_transition_unknowns_and_residuals_to_segment(segment,
initial_power_coefficient = 0.03)
# add to misison
mission.append_segment(segment)
# --------------------------------------------------------------------------
# Segment 2a: Transition Segment: Linear Speed, Linear Climb
# --------------------------------------------------------------------------
# Use original transition segment, converge on rotor y-axis rotation and throttle
segment = Segments.Transition.Constant_Acceleration_Constant_Angle_Linear_Climb(base_segment)
segment.tag = "Transition_2a"
segment.analyses.extend( analyses.transition_1 )
segment.altitude_start = 40.0 * Units.ft
segment.altitude_end = 100.0 * Units.ft
segment.acceleration = 0.5 * Units['m/s/s']
segment.climb_angle = 7. * Units.deg
segment.pitch_initial = 3.6 * Units.degrees
segment.pitch_final = 4.0 * Units.degrees
segment.state.unknowns.throttle = 0.9 * ones_row(1)
segment.process.iterate.conditions.stability = SUAVE.Methods.skip
segment.process.finalize.post_process.stability = SUAVE.Methods.skip
segment = vehicle.networks.battery_propeller.add_tiltrotor_transition_unknowns_and_residuals_to_segment(segment,
initial_power_coefficient = 0.03)
# add to misison
mission.append_segment(segment)
# --------------------------------------------------------------------------
# Segment 2b: Transition Segment: Linear Speed, Linear Climb
# --------------------------------------------------------------------------
# Use original transition segment, converge on rotor y-axis rotation and throttle
segment = Segments.Transition.Constant_Acceleration_Constant_Angle_Linear_Climb(base_segment)
segment.tag = "Transition_2b"
segment.analyses.extend( analyses.transition_1 )
segment.altitude_start = 100.0 * Units.ft
segment.altitude_end = 40.0 * Units.ft
segment.acceleration = -0.25 * Units['m/s/s']
segment.climb_angle = 7. * Units.deg
segment.pitch_initial = 4.0 * Units.degrees
segment.pitch_final = 3.6 * Units.degrees
segment.state.unknowns.throttle = 0.9 * ones_row(1)
segment.process.iterate.conditions.stability = SUAVE.Methods.skip
segment.process.finalize.post_process.stability = SUAVE.Methods.skip
segment = vehicle.networks.battery_propeller.add_tiltrotor_transition_unknowns_and_residuals_to_segment(segment,
initial_power_coefficient = 0.03)
# add to misison
mission.append_segment(segment)
# ------------------------------------------------------------------
# Segment 3: Mini Cruise; Constant Acceleration, Constant Altitude
# ------------------------------------------------------------------
segment = Segments.Cruise.Constant_Speed_Constant_Altitude(base_segment)
segment.tag = "Cruise"
segment.analyses.extend(analyses.cruise)
segment.altitude = 40.0 * Units.ft
segment.air_speed = 1.2 * V_stall
segment.distance = 2. * Units.miles
segment.state.unknowns.throttle = 0.8 * ones_row(1)
segment.process.iterate.conditions.stability = SUAVE.Methods.skip
segment.process.finalize.post_process.stability = SUAVE.Methods.skip
segment = vehicle.networks.battery_propeller.add_unknowns_and_residuals_to_segment(segment)
# add to mission
mission.append_segment(segment)
# ------------------------------------------------------------------
# Mission definition complete
# ------------------------------------------------------------------
return mission
def missions_setup(base_mission):
# the mission container
missions = SUAVE.Analyses.Mission.Mission.Container()
# ------------------------------------------------------------------
# Base Mission
# ------------------------------------------------------------------
missions.base = base_mission
# done!
return missions
# ----------------------------------------------------------------------
# Plot Results
# ----------------------------------------------------------------------
def plot_mission(results,configs,line_style = 'bo-'):
# Plot Flight Conditions
plot_flight_conditions(results, line_style)
# Plot Aerodynamic Coefficients
plot_aerodynamic_coefficients(results, line_style)
# Plot Aircraft Flight Speed
plot_aircraft_velocities(results, line_style)
# Plot Aircraft Electronics
plot_battery_pack_conditions(results, line_style)
# Plot Propeller Conditions
plot_propeller_conditions(results, line_style)
# Plot Electric Motor and Propeller Efficiencies
plot_eMotor_Prop_efficiencies(results, line_style)
# Plot tiltrotor conditions
plot_tiltrotor_conditions(results,configs,line_style)
# Plot propeller Disc and Power Loading
plot_disc_power_loading(results, line_style)
return
def save_transition_animation_paraview(results,configs,save_path=None):
# create store location
if save_path == None:
base_path = os.path.dirname(os.path.abspath(__file__))
dirname = base_path + "/Tiltrotor_VTKs/"
else:
dirname = save_path + "/Tiltrotor_VTKs/"
if not os.path.exists(dirname):
os.makedirs(dirname)
print("Directory " + dirname + " created.")
s_i = 0
for s, seg in enumerate(results.segments):
config = configs[list(configs.keys())[s]]
y_rot = seg.conditions.propulsion.propeller_y_axis_rotation[:,0]
time = seg.conditions.frames.inertial.time[:,0]
if seg.tag == "Transition_1":
# expand for each second of transition
t_duration = time[-1] - time[0]
y_fun = sp.interpolate.interp1d(time,y_rot)
new_times = np.linspace(time[0],time[-1], int(t_duration))
new_y_rots = y_fun(new_times)
for i in range(len(new_times)):
config.networks.battery_propeller.y_axis_rotation = new_y_rots[i]
# store vehicle for this control point
save_vehicle_vtks(config,time_step=s_i, save_loc=dirname)
s_i += 1
return
if __name__ == '__main__':
main()