-
Notifications
You must be signed in to change notification settings - Fork 6
/
msfs_landing_inspector.py
462 lines (411 loc) · 19.8 KB
/
msfs_landing_inspector.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
from flask import Flask, render_template, jsonify, request
from SimConnectCust import *
from threading import Thread
import time
simconnect_dict = {}
# Flask WebApp
def flask_thread_func(threadname):
global simconnect_dict
app = Flask(__name__)
@app.route('/_stuff', methods = ['GET'])
def stuff():
global simconnect_dict
return jsonify(simconnect_dict)
@app.route('/')
def index():
return render_template('body.html')
app.run(host='0.0.0.0', debug=False, use_reloader=False)
# SimConnect App
def simconnect_thread_func(threadname):
global simconnect_dict
# Init SimConnect
sm = SimConnect()
aq = AircraftRequests(sm, _time = 0, _attemps = 3)
# Init variables
run_app = 1
airborne = False
g_force = 0
v_speed = 0
plane_alt_above_ground = 0
sim_on_ground = 0
g_force_prev = 0
v_speed_prev = 0
plane_alt_above_ground_prev = 0
sim_on_ground_prev = 0
v_speed_list_all = []
g_force_list_all = []
v_speed_list = []
g_force_list = []
plane_alt_above_ground_list = []
v_speed_list_ground = []
g_force_list_ground = []
plane_alt_above_ground_list_ground = []
sim_on_ground_list = [1,1,1,1,1,1,1,1]
sim_on_ground_list_all = []
airspeed = 0
airspeed_prev = 0
airspeed_list = []
airspeed_list_ground = []
pitch = 0
pitch_prev = 0
pitch_list = []
pitch_list_ground = []
bank = 0
bank_prev = 0
bank_list = []
bank_list_ground = []
heading = 0
heading_prev = 0
heading_list = []
heading_list_ground = []
wind_speed = 0
wind_speed_prev = 0
wind_speed_list = []
wind_speed_list_ground = []
wind_direction = 0
wind_direction_prev = 0
wind_direction_list = []
wind_direction_list_ground = []
airspeed_list_all = []
pitch_list_all = []
bank_list_all = []
heading_list_all = []
wind_speed_list_all = []
wind_direction_list_all = []
simconnect_dict["G_FORCE"] = 0
simconnect_dict["VERTICAL_SPEED"] = 0
simconnect_dict["SIM_ON_GROUND"] = 0
simconnect_dict["G_FORCE_LANDING"] = "N/A"
simconnect_dict["VERTICAL_SPEED_LANDING"] = "N/A"
simconnect_dict["SIM_ON_GROUND_LIST"] = "N/A"
simconnect_dict["AIRBORNE"] = 0
simconnect_dict["G_FORCE_LIST"] = g_force_list
simconnect_dict["V_SPEED_LIST"] = v_speed_list
simconnect_dict["G_FORCE_LANDING_LIST"] = "N/A"
simconnect_dict["G_FORCE_LANDING_LIST_GROUND"] = "N/A"
simconnect_dict["VERTICAL_SPEED_LANDING_LIST"] = "N/A"
simconnect_dict["VERTICAL_SPEED_LANDING_LIST_GROUND"] = "N/A"
simconnect_dict["PLANE_ALT_ABOVE_GROUND_LIST"] = plane_alt_above_ground_list
simconnect_dict["PLANE_ALT_ABOVE_GROUND_LIST_GROUND"] = plane_alt_above_ground_list_ground
simconnect_dict["LANDING_RATING"] = "N/A"
simconnect_dict["AIRSPEED"] = "N/A"
simconnect_dict["AIRSPEED_LIST"] = airspeed_list
simconnect_dict["AIRSPEED_LIST_GROUND"] = airspeed_list_ground
simconnect_dict["PITCH"] = "N/A"
simconnect_dict["PITCH_LIST"] = pitch_list
simconnect_dict["PITCH_LIST_GROUND"] = pitch_list_ground
simconnect_dict["BANK"] = "N/A"
simconnect_dict["BANK_LIST"] = bank_list
simconnect_dict["BANK_LIST_GROUND"] = bank_list_ground
simconnect_dict["HEADING"] = "N/A"
simconnect_dict["HEADING_LIST"] = heading_list
simconnect_dict["HEADING_LIST_GROUND"] = heading_list_ground
simconnect_dict["WIND_SPEED"] = "N/A"
simconnect_dict["WIND_SPEED_LIST"] = wind_speed_list
simconnect_dict["WIND_SPEED_LIST_GROUND"] = wind_speed_list_ground
simconnect_dict["WIND_DIRECTION"] = "N/A"
simconnect_dict["WIND_DIRECTION_LIST"] = wind_direction_list
simconnect_dict["WIND_DIRECTION_LIST_GROUND"] = wind_direction_list_ground
simconnect_dict["LANDING_COUNTER"] = 0
# Create empty labels for charts
labels_list = []
for i in range(150):
labels_list.append("")
simconnect_dict["LABELS"] = labels_list
# Run Simconnect Calculations
while run_app == 1:
# Get Current Data
# Fix for -999999 values
v_speed = round(aq.get("VELOCITY_WORLD_Y")*60)
if v_speed < -99999:
v_speed = v_speed_prev
else:
v_speed_prev = v_speed
g_force = round(aq.get("G_FORCE"), 2)
if g_force < -99999:
g_force = g_force_prev
else:
g_force_prev = g_force
plane_alt_above_ground = round(aq.get("PLANE_ALT_ABOVE_GROUND"), 1)
if plane_alt_above_ground < -99999:
plane_alt_above_ground = plane_alt_above_ground_prev
else:
plane_alt_above_ground_prev = plane_alt_above_ground
sim_on_ground = aq.get("SIM_ON_GROUND")
if sim_on_ground < -99999:
sim_on_ground = sim_on_ground_prev
else:
sim_on_ground_prev = sim_on_ground
airspeed = round(aq.get("AIRSPEED_TRUE"))
if airspeed < -99999:
airspeed = airspeed_prev
else:
airspeed_prev = airspeed
pitch = round(aq.get("PLANE_PITCH_DEGREES") * 180 / 3.1416, 1) * (-1)
if abs(pitch) > 999:
pitch = pitch_prev
else:
pitch_prev = pitch
bank = round((aq.get("PLANE_BANK_DEGREES") * 180 / 3.1416), 1)
if abs(bank) > 999:
bank = bank_prev
else:
bank_prev = bank
heading = round(aq.get("PLANE_HEADING_DEGREES_TRUE") * 180 / 3.1416)
if abs(heading) > 999:
heading = heading_prev
else:
heading_prev = heading
wind_speed = round(aq.get("AMBIENT_WIND_VELOCITY"), 1)
if wind_speed < -99999:
wind_speed = wind_speed_prev
else:
wind_speed_prev = wind_speed
wind_direction = round(aq.get("AMBIENT_WIND_DIRECTION"))
if wind_direction < -99999:
wind_direction = wind_direction_prev
else:
wind_direction_prev = wind_direction
# Make lists
sim_on_ground_list.insert(0, sim_on_ground)
if len(sim_on_ground_list) > 21:
sim_on_ground_list.pop()
sim_on_ground_list_all.insert(0, sim_on_ground)
if len(sim_on_ground_list_all) > 151:
sim_on_ground_list_all.pop()
v_speed_list_all.insert(0, v_speed)
if len(v_speed_list_all) > 151:
v_speed_list_all.pop()
g_force_list_all.insert(0, g_force)
if len(g_force_list_all) > 151:
g_force_list_all.pop()
airspeed_list_all.insert(0, airspeed)
if len(airspeed_list_all) > 151:
airspeed_list_all.pop()
pitch_list_all.insert(0, pitch)
if len(pitch_list_all) > 151:
pitch_list_all.pop()
bank_list_all.insert(0, bank)
if len(bank_list_all) > 151:
bank_list_all.pop()
heading_list_all.insert(0, heading)
if len(heading_list_all) > 151:
heading_list_all.pop()
wind_speed_list_all.insert(0, wind_speed)
if len(wind_speed_list_all) > 151:
wind_speed_list_all.pop()
wind_direction_list_all.insert(0, wind_direction)
if len(wind_direction_list_all) > 151:
wind_direction_list_all.pop()
# Make lists for graph - separation between airborne and landing
if sim_on_ground == 1:
v_speed_list.insert(0, "null")
if len(v_speed_list) > 151:
v_speed_list.pop()
g_force_list.insert(0, "null")
if len(g_force_list) > 151:
g_force_list.pop()
plane_alt_above_ground_list.insert(0, "null")
if len(plane_alt_above_ground_list) > 151:
plane_alt_above_ground_list.pop()
v_speed_list_ground.insert(0, v_speed)
if len(v_speed_list_ground) > 151:
v_speed_list_ground.pop()
g_force_list_ground.insert(0, g_force)
if len(g_force_list_ground) > 151:
g_force_list_ground.pop()
plane_alt_above_ground_list_ground.insert(0, plane_alt_above_ground)
if len(plane_alt_above_ground_list_ground) > 151:
plane_alt_above_ground_list_ground.pop()
airspeed_list.insert(0, "null")
if len(airspeed_list) > 151:
airspeed_list.pop()
airspeed_list_ground.insert(0, airspeed)
if len(airspeed_list_ground) > 151:
airspeed_list_ground.pop()
pitch_list.insert(0, "null")
if len(pitch_list) > 151:
pitch_list.pop()
pitch_list_ground.insert(0, pitch)
if len(pitch_list_ground) > 151:
pitch_list_ground.pop()
bank_list.insert(0, "null")
if len(bank_list) > 151:
bank_list.pop()
bank_list_ground.insert(0, bank)
if len(bank_list_ground) > 151:
bank_list_ground.pop()
heading_list.insert(0, "null")
if len(heading_list) > 151:
heading_list.pop()
heading_list_ground.insert(0, heading)
if len(heading_list_ground) > 151:
heading_list_ground.pop()
wind_speed_list.insert(0, "null")
if len(wind_speed_list) > 151:
wind_speed_list.pop()
wind_speed_list_ground.insert(0, wind_speed)
if len(wind_speed_list_ground) > 151:
wind_speed_list_ground.pop()
wind_direction_list.insert(0, "null")
if len(wind_direction_list) > 151:
wind_direction_list.pop()
wind_direction_list_ground.insert(0, wind_direction)
if len(wind_direction_list_ground) > 151:
wind_direction_list_ground.pop()
else:
v_speed_list.insert(0, v_speed)
if len(v_speed_list) > 151:
v_speed_list.pop()
g_force_list.insert(0, g_force)
if len(g_force_list) > 151:
g_force_list.pop()
plane_alt_above_ground_list.insert(0, plane_alt_above_ground)
if len(plane_alt_above_ground_list) > 151:
plane_alt_above_ground_list.pop()
v_speed_list_ground.insert(0, "null")
if len(v_speed_list_ground) > 151:
v_speed_list_ground.pop()
g_force_list_ground.insert(0, "null")
if len(g_force_list_ground) > 151:
g_force_list_ground.pop()
plane_alt_above_ground_list_ground.insert(0, "null")
if len(plane_alt_above_ground_list_ground) > 151:
plane_alt_above_ground_list_ground.pop()
airspeed_list.insert(0, airspeed)
if len(airspeed_list) > 151:
airspeed_list.pop()
airspeed_list_ground.insert(0, "null")
if len(airspeed_list_ground) > 151:
airspeed_list_ground.pop()
pitch_list.insert(0, pitch)
if len(pitch_list) > 151:
pitch_list.pop()
pitch_list_ground.insert(0, "null")
if len(pitch_list_ground) > 151:
pitch_list_ground.pop()
bank_list.insert(0, bank)
if len(bank_list) > 151:
bank_list.pop()
bank_list_ground.insert(0, "null")
if len(bank_list_ground) > 151:
bank_list_ground.pop()
heading_list.insert(0, heading)
if len(heading_list) > 151:
heading_list.pop()
heading_list_ground.insert(0, "null")
if len(heading_list_ground) > 151:
heading_list_ground.pop()
wind_speed_list.insert(0, wind_speed)
if len(wind_speed_list) > 151:
wind_speed_list.pop()
wind_speed_list_ground.insert(0, "null")
if len(wind_speed_list_ground) > 151:
wind_speed_list_ground.pop()
wind_direction_list.insert(0, wind_direction)
if len(wind_direction_list) > 151:
wind_direction_list.pop()
wind_direction_list_ground.insert(0, "null")
if len(wind_direction_list_ground) > 151:
wind_direction_list_ground.pop()
# Populate vars to JSON dictionary
simconnect_dict["G_FORCE"] = g_force
simconnect_dict["VERTICAL_SPEED"] = v_speed
simconnect_dict["SIM_ON_GROUND"] = sim_on_ground
simconnect_dict["AIRBORNE"] = airborne
# Make landing/airborne decision
if airborne == True and sum(sim_on_ground_list) == 20:
# Fix - need to get the last value before on ground readings
v_speed_list_touchdown = v_speed_list_ground
g_force_list_touchdown = g_force_list_ground
change_last = False
for idx, element in enumerate(v_speed_list_touchdown):
if idx >= 1:
if element == "null" and sim_on_ground_list_all[idx-1] == 1:
if change_last == False:
v_speed_list_touchdown[idx] = v_speed_list[idx]
g_force_list_touchdown[idx] = g_force_list[idx]
change_last = True
else:
change_last = False
else:
change_last = False
v_speed_list_touchdown = [0 if x=="null" else x for x in v_speed_list_touchdown]
g_force_list_touchdown = [0 if x=="null" else x for x in g_force_list_touchdown]
# Get Values for Touchdown
simconnect_dict["VERTICAL_SPEED_LANDING"] = min(v_speed_list_touchdown)
# Calculate Custom G-Force based on vertical speed
# Model uses Harvsine acceleration model for peak acceleration https://www.nhtsa.gov/sites/nhtsa.dot.gov/files/18esv-000501.pdf
# For time a custom function is used that ranges from 0.25 for GA to 0.35 for airliners. This simulates the rigidness of suspention.
custom_g_force_v_speed_m_per_s = (min(v_speed_list_touchdown) * (-0.3048) / 60)
plane_weight = max(round(aq.get("TOTAL_WEIGHT") * 0.45), 50)
custom_g_force_impact_duration = 0.355 + (-0.103/(1 + (plane_weight/15463)**1.28))
custom_g_force = 1 + (((2 * custom_g_force_v_speed_m_per_s) / custom_g_force_impact_duration) / 9.80665)
custom_g_force = round(custom_g_force, 2)
# Get Index of Touchdown from min Vertical Speed
index_vspeed_touchdown = v_speed_list_touchdown.index(min(v_speed_list_touchdown))
# Check if SimConnect G force is within +/- 10% of custom G force. If not use custom G force
if g_force_list_touchdown[index_vspeed_touchdown] < custom_g_force*0.9 or g_force_list_touchdown[index_vspeed_touchdown] > custom_g_force*1.1:
g_force_list_touchdown[index_vspeed_touchdown] = custom_g_force
g_force_list[index_vspeed_touchdown] = custom_g_force
g_force_list_ground[index_vspeed_touchdown] = custom_g_force
# Get the rest of touchdown data based on vertical speed index
simconnect_dict["G_FORCE_LANDING"] = max(g_force_list_touchdown)
simconnect_dict["AIRSPEED"] = airspeed_list_all[index_vspeed_touchdown]
simconnect_dict["PITCH"] = pitch_list_all[index_vspeed_touchdown]
simconnect_dict["BANK"] = bank_list_all[index_vspeed_touchdown]
simconnect_dict["HEADING"] = heading_list_all[index_vspeed_touchdown]
simconnect_dict["WIND_SPEED"] = wind_speed_list_all[index_vspeed_touchdown]
simconnect_dict["WIND_DIRECTION"] = wind_direction_list_all[index_vspeed_touchdown]
# Create Lists for Graphs
simconnect_dict["G_FORCE_LANDING_LIST"] = g_force_list[::-1]*1
simconnect_dict["G_FORCE_LANDING_LIST_GROUND"] = g_force_list_ground[::-1]*1
v_speed_list_neg = [elem * (-1) if elem != "null" else "null" for elem in v_speed_list]
v_speed_list_ground_neg = [elem * (-1) if elem != "null" else "null" for elem in v_speed_list_ground]
simconnect_dict["VERTICAL_SPEED_LANDING_LIST"] = v_speed_list_neg[::-1]*1
simconnect_dict["VERTICAL_SPEED_LANDING_LIST_GROUND"] = v_speed_list_ground_neg[::-1]*1
simconnect_dict["PLANE_ALT_ABOVE_GROUND_LIST"] = plane_alt_above_ground_list[::-1]*1
simconnect_dict["PLANE_ALT_ABOVE_GROUND_LIST_GROUND"] = plane_alt_above_ground_list_ground[::-1]*1
simconnect_dict["LANDING_COUNTER"] = simconnect_dict["LANDING_COUNTER"] + 1
simconnect_dict["AIRSPEED_LIST"] = airspeed_list[::-1]*1
simconnect_dict["AIRSPEED_LIST_GROUND"] = airspeed_list_ground[::-1]*1
simconnect_dict["PITCH_LIST"] = pitch_list[::-1]*1
simconnect_dict["PITCH_LIST_GROUND"] = pitch_list_ground[::-1]*1
simconnect_dict["BANK_LIST"] = bank_list[::-1]*1
simconnect_dict["BANK_LIST_GROUND"] = bank_list_ground[::-1]*1
simconnect_dict["HEADING_LIST"] = heading_list[::-1]*1
simconnect_dict["HEADING_LIST_GROUND"] = heading_list_ground[::-1]*1
simconnect_dict["WIND_SPEED_LIST"] = wind_speed_list[::-1]*1
simconnect_dict["WIND_SPEED_LIST_GROUND"] = wind_speed_list_ground[::-1]*1
simconnect_dict["WIND_DIRECTION_LIST"] = wind_direction_list[::-1]*1
simconnect_dict["WIND_DIRECTION_LIST_GROUND"] = wind_direction_list_ground[::-1]*1
simconnect_dict["SIM_ON_GROUND_LIST"] = sim_on_ground_list_all[::-1]*1
# Landing Rating Based on G-Forces
if simconnect_dict["VERTICAL_SPEED_LANDING"] > -60:
simconnect_dict["LANDING_RATING"] = "Very soft landing"
elif simconnect_dict["VERTICAL_SPEED_LANDING"] > -120:
simconnect_dict["LANDING_RATING"] = "Soft landing"
elif simconnect_dict["VERTICAL_SPEED_LANDING"] > -200:
simconnect_dict["LANDING_RATING"] = "Average landing"
elif simconnect_dict["VERTICAL_SPEED_LANDING"] > -300:
simconnect_dict["LANDING_RATING"] = "Firm landing"
elif simconnect_dict["VERTICAL_SPEED_LANDING"] > -400:
simconnect_dict["LANDING_RATING"] = "Hard landing"
elif simconnect_dict["VERTICAL_SPEED_LANDING"] > -600:
simconnect_dict["LANDING_RATING"] = "Very hard landing"
else:
simconnect_dict["LANDING_RATING"] = "Structural damage to plane"
airborne = False
# Decision for Airborne
if sum(sim_on_ground_list) == 0 and airborne == False:
airborne = True
if __name__ == "__main__":
thread1 = Thread(target = simconnect_thread_func, args=('Thread-1', ))
thread2 = Thread(target = flask_thread_func, args=('Thread-2', ))
thread1.start()
thread2.start()
time.sleep(.5)
print("\n*********************")
print("MSFS Landing Inspector initialized")
print("Load 'localhost:5000' in your browser to start MSFS Landing Inspector")
print("Tip: You can access MSFS Landing Inspector from your mobile device. Check install_instructions.txt for instructions.")