source: src/mlx/acft.py@ 1092:f3c535a548c2

python3
Last change on this file since 1092:f3c535a548c2 was 1087:73fbd444b7fe, checked in by István Váradi <ivaradi@…>, 20 months ago

It is possible to provide an extra parameter for the SimBrief cruise profile.

File size: 49.2 KB
Line 
1
2from . import const
3from . import gates
4from . import checks
5from . import fs
6from .i18n import xstr
7from . import util
8
9import sys
10import time
11import traceback
12
13from collections import deque
14
15#---------------------------------------------------------------------------------------
16
17## @package mlx.acft
18#
19# The simulator-independent aircraft classes.
20#
21# This module contains the aircraft classes that contain some general data
22# about each aircraft type in the MAVA Fleet. The base class, \ref Aircraft
23# also implements some parts of the logging and traces some data. The classes
24# are also responsible for creating the \ref mlx.checks "checkers". Most of
25# them are created by the \ref Aircraft class' constructor, but there can be
26# type-specific differences. For example the lights are different for different
27# types, so there is a \ref Aircraft._appendLightsLoggers "function" which can
28# be reimplemented in child classes, if needed. This class maintains also the
29# \ref SmoothedValue "smoothed values" of the IAS and the VS and set these
30# values in the \ref mlx.fs.AircraftState "aircraft state" when it is received
31# from the simulator.
32
33#---------------------------------------------------------------------------------------
34
35# Derate type: no derate possible
36DERATE_NONE = 0
37
38# Derate type: Boeing, i.e. a percentage value.
39# For logging, the percentage value is expected as a string (i.e. whatever the
40# pilot enters into the text field).
41DERATE_BOEING = 1
42
43# Derate type: EPR, i.e. an EPR value.
44# For logging, the EPR value is expected as a string (i.e. whatever the pilot
45# enters into the text field).
46DERATE_EPR = 2
47
48# Derate type: Tupolev, i.e. nominal or takeoff
49# For logging, one of the DERATE_TUPOLEV_xxx values are expected.
50DERATE_TUPOLEV = 3
51
52# Tupolev derate value: nominal
53DERATE_TUPOLEV_NOMINAL = 1
54
55# Tupolev derate value: takeoff
56DERATE_TUPOLEV_TAKEOFF = 2
57
58# Derate type: BAe-146, i.e. enabled or not
59# For logging, a boolean is expected.
60DERATE_B462 = 4
61
62#---------------------------------------------------------------------------------------
63
64class SmoothedValue(object):
65 """A smoothed value."""
66 def __init__(self):
67 """Construct the value."""
68 self._deque = deque()
69 self._sum = 0
70
71 def add(self, length, value):
72 """Add the given value and smooth with the given length."""
73 dequeLength = len(self._deque)
74 while dequeLength>=length:
75 self._sum -= self._deque.popleft()
76 dequeLength -= 1
77
78 self._sum += value
79 self._deque.append(value)
80
81 def get(self):
82 """Get the average."""
83 return self._sum / len(self._deque)
84
85#---------------------------------------------------------------------------------------
86
87class SimBriefData(object):
88 """Data to be used when creating SimBrief briefings."""
89 def __init__(self, climbProfiles, cruiseProfiles, descentProfiles,
90 cruiseParameters = {}):
91 """Construct the SimBrief data with the given profiles.
92
93 cruiseParameters is a dictionary keyed by the cruise profile index. It
94 contains a tuple of:
95 - a boolean indicating if the parameter is mandatory,
96 - the name of the parameter for the SimBrief API
97 """
98 self.climbProfiles = climbProfiles
99 self.cruiseProfiles = cruiseProfiles
100 self.descentProfiles = descentProfiles
101 self.cruiseParameters = cruiseParameters
102
103#---------------------------------------------------------------------------------------
104
105class Aircraft(object):
106 """Base class for aircraft."""
107 @staticmethod
108 def create(flight, bookedFlight):
109 """Create an aircraft instance for the type in the given flight."""
110 acft = _classes[flight.aircraftType](flight)
111 acft.setBookedFlight(bookedFlight)
112 return acft
113
114 def __init__(self, flight, minLandingFuel = None,
115 recommendedLandingFuel = None):
116 """Construct the aircraft for the given type."""
117 self._flight = flight
118 self._minLandingFuel = minLandingFuel
119 self._recommendedLandingFuel = recommendedLandingFuel
120
121 self._name = None
122 self._modelName = None
123
124 self._aircraftState = None
125
126 self._maxVS = -10000.0
127 self._minVS = 10000.0
128
129 self._v1r2LineIndex = None
130 self._derateLineID = None
131 self._takeoffAntiIceLineID = None
132 self._vrefLineIndex = None
133 self._landingAntiIceLineID = None
134
135 self.humanWeight = 82.0
136
137 self.initialClimbSpeedAltitude = 1500
138 self.reverseMinSpeed = 50
139
140 self.hasStrobeLight = True
141
142 self.maxTakeOffPitch = 15.0
143 self.maxTouchDownPitch = 15.0
144 self.brakeCoolTime = 10.0
145
146 self.simBriefData = None
147
148 self._checkers = []
149
150 config = flight.config
151 # Loggers
152
153 self._checkers.append(checks.StageChecker())
154 self._checkers.append(checks.TakeOffLogger())
155
156 self._checkers.append(checks.AltimeterLogger())
157
158 self._ilsLogger = checks.ILSLogger()
159 self._checkers.append(self._ilsLogger)
160 self._nav1Logger = checks.NAV1Logger()
161 self._checkers.append(self._nav1Logger)
162 self._nav2Logger = checks.NAV2Logger()
163 self._checkers.append(self._nav2Logger)
164
165 self._adf1Logger = checks.ADF1Logger()
166 self._checkers.append(self._adf1Logger)
167 self._adf2Logger = checks.ADF2Logger()
168 self._checkers.append(self._adf2Logger)
169
170 self._checkers.append(checks.SquawkLogger())
171
172 self._appendLightsLoggers()
173
174 self._checkers.append(checks.FlapsLogger())
175
176 self._checkers.append(checks.GearsLogger())
177 self._checkers.append(checks.InitialClimbSpeedLogger())
178 self._checkers.append(checks.CruiseSpeedLogger())
179 self._checkers.append(checks.SpoilerLogger())
180 self._checkers.append(checks.APLogger())
181
182 if config.isMessageTypeFS(const.MESSAGETYPE_VISIBILITY):
183 self._checkers.append(checks.VisibilityChecker())
184
185 # FIXME: we should have a central data model object, and not collect
186 # the data from the GUI. However, some pieces of data (e.g. V-speeds,
187 # etc. that is entered into the GUI) *should* be a part of the GUI and
188 # queried from it, so the model should have a reference to the GUI as
189 # well and access such data via the GUI!
190 if config.onlineACARS and flight.loggedIn and not flight.entranceExam:
191 self._checkers.append(checks.ACARSSender(flight._gui))
192
193 # Fault checkers
194
195 self._appendLightsCheckers()
196
197 self._checkers.append(checks.TransponderChecker())
198
199 self._checkers.append(checks.BankChecker())
200
201 self._checkers.append(checks.FlapsRetractChecker())
202 self._checkers.append(checks.FlapsSpeedLimitChecker())
203
204 self._checkers.append(checks.GearsDownChecker())
205 self._checkers.append(checks.GearSpeedLimitChecker())
206
207 self._checkers.append(checks.GLoadChecker())
208
209 self._checkers.append(checks.MLWChecker())
210 self._checkers.append(checks.MTOWChecker())
211 self._checkers.append(checks.MZFWChecker())
212 self._checkers.append(checks.PayloadChecker())
213
214 self._checkers.append(checks.SpeedChecker())
215 self._checkers.append(checks.VSChecker())
216
217 timeout = 30.0 + config.realIASSmoothingLength - 1
218 self._checkers.append(checks.OverspeedChecker(faultTimeout = timeout))
219
220 self._checkers.append(checks.StallChecker())
221
222 self._checkers.append(checks.PitotChecker())
223
224 self._checkers.append(checks.ReverserLogger())
225 self._checkers.append(checks.ReverserChecker())
226
227 if flight.aircraftType is not None and config.enableApproachCallouts:
228 approachCallouts = flight.config.getApproachCallouts(flight.aircraftType)
229 if approachCallouts:
230 self._checkers.append(checks.ApproachCalloutsPlayer(approachCallouts))
231
232 self._smoothedIAS = SmoothedValue()
233 self._smoothedVS = SmoothedValue()
234
235 @property
236 def type(self):
237 """Get the type of the aircraft."""
238 return self._flight.aircraftType
239
240 @property
241 def flight(self):
242 """Get the flight the aircraft belongs to."""
243 return self._flight
244
245 @property
246 def minLandingFuel(self):
247 """Get the minimum acceptable amount of the landing fuel."""
248 return self._minLandingFuel
249
250 @property
251 def recommendedLandingFuel(self):
252 """Get the recommended amount of the landing fuel."""
253 return self._recommendedLandingFuel
254
255 @property
256 def logger(self):
257 """Get the logger to use for the aircraft."""
258 return self._flight.logger
259
260 @property
261 def state(self):
262 """Get the current aircraft state."""
263 return self._aircraftState
264
265 @property
266 def speedInKnots(self):
267 """Indicate if the speed is in knots.
268
269 This default implementation returns True."""
270 return True
271
272 @property
273 def aglInFeet(self):
274 """Indicate if AGL altitudes are to be logged in feet.
275
276 This default implementation returns True."""
277 return True
278
279 @property
280 def timestamp(self):
281 """Get the timestamp of the current state."""
282 return None if self._aircraftState is None \
283 else self._aircraftState.timestamp
284
285 @property
286 def derateType(self):
287 """Get the derate type for this aircraft.
288
289 This default implementation returns DERATE_NONE."""
290 return DERATE_NONE
291
292 def setBookedFlight(self, bookedFlight):
293 """Update the aircraft based on the booked flight data (e.g. tail number).
294
295 This default implementation does nothing."""
296
297 def getDerateLine(self, value):
298 """Get the log line for the given derate value.
299
300 It uses the the derate type and produces the standard message for
301 each. This children need not override it, although they can."""
302 dt = self.derateType
303
304 if dt==DERATE_BOEING:
305 return "Derate calculated by the pilot: %s %%" % \
306 ("-" if value is None else value,)
307 elif dt==DERATE_EPR:
308 return "EPR calculated by the pilot: %s" % \
309 ("-" if value is None else value,)
310 elif dt==DERATE_TUPOLEV:
311 return "Thrust setting calculated by the pilot: %s" % \
312 ("-" if value is None else
313 "nominal" if value==DERATE_TUPOLEV_NOMINAL else "takeoff",)
314 elif dt==DERATE_B462:
315 return "Derate setting: %s" % \
316 ("-" if value is None else "enabled" if value else "disabled",)
317 elif dt!=DERATE_NONE:
318 print("mlx.acft.getDerateLine: invalid derate type: " + dt)
319
320 return None
321
322 def getFlapsSpeedLimit(self, flaps):
323 """Get the speed limit for the given flaps setting."""
324 return self.flapSpeedLimits[flaps] if flaps in self.flapSpeedLimits \
325 else None
326
327 def modelChanged(self, timestamp, aircraftName, modelName):
328 """Called when the simulator's aircraft changes."""
329 self._name = aircraftName
330 self._modelName = modelName
331 if self._flight.stage is not None:
332 self._logNameAndModel(timestamp)
333
334 def handleState(self, aircraftState):
335 """Called when the state of the aircraft changes.
336
337 This is the function that the simulator calls directly with the new
338 state."""
339 try:
340 config = self._flight.config
341
342 self._smoothedIAS.add(config.realIASSmoothingLength, aircraftState.ias)
343 aircraftState.smoothedIAS = self._smoothedIAS.get()
344
345 self._smoothedVS.add(config.realVSSmoothingLength, aircraftState.vs)
346 aircraftState.smoothedVS = self._smoothedVS.get()
347
348 for checker in self._checkers:
349 try:
350 checker.check(self._flight, self, self._flight.logger,
351 self._aircraftState, aircraftState)
352 except:
353 print("Checker", checker, "failed", file=sys.stderr)
354 traceback.print_exc()
355
356 self._flight.handleState(self._aircraftState, aircraftState)
357
358 self._maxVS = max(self._maxVS, aircraftState.vs)
359 self._minVS = min(self._minVS, aircraftState.vs)
360 except:
361 print("Failed to handle the state", file=sys.stderr)
362 traceback.print_exc()
363 finally:
364 self._aircraftState = aircraftState
365
366 def setStage(self, aircraftState, newStage):
367 """Set the given stage as the new one and do whatever should be
368 done."""
369 if newStage==const.STAGE_BOARDING:
370 self._logNameAndModel(aircraftState.timestamp)
371
372 oldStage = self._flight.stage
373
374 if self._flight.setStage(aircraftState.timestamp, newStage):
375 if newStage==const.STAGE_PUSHANDTAXI:
376 self.logger.message(aircraftState.timestamp, "Block time start")
377 self._flight.logFuel(aircraftState)
378 self.logger.message(aircraftState.timestamp,
379 "ZFW: %.2f kg" % (aircraftState.zfw))
380 flight = self._flight
381 if flight.v1 is None or flight.vr is None or flight.v2 is None:
382 fs.sendMessage(const.MESSAGETYPE_HELP,
383 "Don't forget to set the takeoff V-speeds!",
384 5)
385 elif newStage==const.STAGE_TAKEOFF:
386 if oldStage == const.STAGE_RTO and self._flight.hasRTO:
387 rtoState = self._flight.rtoState
388 if (aircraftState.timestamp - rtoState.timestamp) < \
389 (self.brakeCoolTime * 60.0):
390 self.logger.fault("brakeCoolTime",
391 aircraftState.timestamp,
392 "Did not cool the brakes for at least %.f minutes after the RTO" % (self.brakeCoolTime,),
393 15.0)
394 self.logger.message(aircraftState.timestamp,
395 "Flight time start")
396 self.logger.message(aircraftState.timestamp,
397 "Takeoff weight: %.0f kg, MTOW: %.0f kg" % \
398 (aircraftState.grossWeight, self.mtow))
399 self._logQNH(aircraftState)
400 self.logger.message(aircraftState.timestamp,
401 "Wind %03.0f/%.0f" % \
402 (aircraftState.windDirection,
403 aircraftState.windSpeed))
404 self._logRadios(aircraftState)
405 self._logV1R2(aircraftState)
406 self._logDerate(aircraftState)
407 self._logTakeoffAntiIce(aircraftState)
408 elif newStage==const.STAGE_DESCENT or newStage==const.STAGE_LANDING:
409 self._logRadios(aircraftState)
410 if newStage==const.STAGE_LANDING:
411 self._logQNH(aircraftState)
412 elif newStage==const.STAGE_GOAROUND:
413 from .logger import Logger
414 self._flight.handleFault("goaround",
415 aircraftState.timestamp,
416 "Go-around detected, please, explain!",
417 Logger.NO_SCORE)
418 elif newStage==const.STAGE_TAXIAFTERLAND:
419 flight = self._flight
420 bookedFlight = flight.bookedFlight
421 config = flight.config
422 if config.onlineGateSystem and \
423 flight.loggedIn and \
424 not flight.entranceExam and \
425 bookedFlight.arrivalICAO=="LHBP" and \
426 config.isMessageTypeFS(const.MESSAGETYPE_GATE_SYSTEM):
427 self._flight.getFleet(callback = self._fleetRetrieved,
428 force = True)
429 self.logger.message(aircraftState.timestamp, "Flight time end")
430 self._flight.logFuel(aircraftState)
431 if self._minLandingFuel is not None and \
432 aircraftState.totalFuel<self._minLandingFuel:
433 self._flight.handleFault(self.__class__,
434 aircraftState.timestamp,
435 "The amount of the landing fuel is less than the minimum for this type: %ukgs (possible NO GO!)" %
436 (self._minLandingFuel,), 0)
437 self.logger.message(aircraftState.timestamp,
438 "Landing weight: %.0f kg, MLW: %.0f" % \
439 (aircraftState.grossWeight, self.mlw))
440 self.logger.message(aircraftState.timestamp,
441 "Vertical speed range: %.0f..%.0f feet/min" % \
442 (self._minVS, self._maxVS))
443 # elif newStage==const.STAGE_PARKING:
444 # self.logger.message(aircraftState.timestamp, "Block time end")
445 elif newStage==const.STAGE_END:
446 flightLength = self._flight.flightTimeEnd - self._flight.flightTimeStart
447 self.logger.message(aircraftState.timestamp, "Block time end")
448 self.logger.message(aircraftState.timestamp,
449 "Flight time: " +
450 util.getTimeIntervalString(flightLength))
451 self.logger.message(aircraftState.timestamp,
452 "Flown distance: %.2f NM" % \
453 (self._flight.flownDistance,))
454 blockLength = self._flight.blockTimeEnd - self._flight.blockTimeStart
455 self.logger.message(aircraftState.timestamp,
456 "Block time: " +
457 util.getTimeIntervalString(blockLength))
458
459 def prepareFlare(self):
460 """Called when it is detected that we will soon flare.
461
462 On the first call, it should start monitoring some parameters more
463 closely to determine flare time."""
464 self.flight.simulator.startFlare()
465
466 def flareStarted(self, windSpeed, windDirection, visibility,
467 flareStart, flareStartFS):
468 """Called when the flare has started."""
469 self.logger.message(self._aircraftState.timestamp, "The flare has begun")
470 self.logger.message(self._aircraftState.timestamp,
471 "Wind %03.0f/%.0f" % \
472 (windDirection, windSpeed))
473 self.logger.message(self._aircraftState.timestamp,
474 "Visibility: %.0f metres" % (visibility,))
475 self._logQNH(self._aircraftState)
476 self._logVRef()
477 self._logLandingAntiIce(self._aircraftState)
478 self.flight.flareStarted(flareStart, flareStartFS)
479 fs.sendMessage(const.MESSAGETYPE_INFORMATION, "Flare-time", 3)
480
481 def flareFinished(self, flareEnd, flareEndFS, tdRate, tdRateCalculatedByFS,
482 ias, pitch, bank, heading):
483 """Called when the flare has finished."""
484 (flareTimeFromFS, flareTime) = self.flight.flareFinished(flareEnd,
485 flareEndFS,
486 tdRate)
487 self.logger.message(self._aircraftState.timestamp,
488 "Flaretime: %.3f (from %s)" % \
489 (flareTime,
490 "the simulator" if flareTimeFromFS else "real time",))
491 self.logger.message(self._aircraftState.timestamp,
492 "Touchdown rate: %.0f feet/min" % (tdRate,))
493 self.logger.message(self._aircraftState.timestamp,
494 "Touchdown rate was calculated by the %s" % \
495 ("simulator" if tdRateCalculatedByFS else "logger",))
496 flight = self._flight
497 self.logger.message(self._aircraftState.timestamp,
498 "Touchdown speed: %.0f %s" % \
499 (flight.speedFromKnots(ias),
500 flight.getEnglishSpeedUnit()))
501 self.logger.message(self._aircraftState.timestamp,
502 "Touchdown pitch: %.1f degrees" % (pitch,))
503 self.logger.message(self._aircraftState.timestamp,
504 "Touchdown bank: %.1f degrees" % (bank,))
505 self.logger.message(self._aircraftState.timestamp,
506 "Touchdown heading: %03.0f degrees" % (heading,))
507 self.logger.message(self._aircraftState.timestamp,
508 "CG: %.1f%%" % \
509 (self._aircraftState.cog*100.0,))
510
511 if abs(pitch)>self.maxTouchDownPitch:
512 self._flight.handleNoGo("TDPitch", self._aircraftState.timestamp,
513 "Touchdown pitch higher than aircraft maximum (%.2f)" % \
514 (self.maxTouchDownPitch,),
515 "TD TAILSTRIKE NO GO")
516
517 def cancelFlare(self):
518 """Cancel flare, if it has started."""
519 self.flight.simulator.cancelFlare()
520
521 def checkFlightEnd(self, aircraftState):
522 """Check if the end of the flight has arrived.
523
524 This default implementation checks the N1 values, but for
525 piston-powered aircraft you need to check the RPMs."""
526 if aircraftState.n1 is not None:
527 for n1 in aircraftState.n1:
528 if n1 is not None and n1>=0.5: return False
529 return True
530
531 def updateV1R2(self):
532 """Update the V1, Vr and V2 values from the flight, if the these values
533 have already been logged."""
534 if self._v1r2LineIndex is not None:
535 self._logV1R2()
536
537 def updateDerate(self):
538 """Update the derate value from the flight, if the these values
539 have already been logged."""
540 if self._derateLineID is not None:
541 self._logDerate()
542
543 def updateTakeoffAntiIce(self):
544 """Update the take-off anti-ice setting."""
545 if self._takeoffAntiIceLineID is not None:
546 self._logTakeoffAntiIce()
547
548 def _appendLightsLoggers(self):
549 """Append the loggers needed for the lights.
550
551 This default implementation adds the loggers for the anti-collision
552 lights, the landing lights, the strobe lights and the NAV lights."""
553 self._checkers.append(checks.AnticollisionLightsLogger())
554 self._checkers.append(checks.LandingLightsLogger())
555 self._checkers.append(checks.StrobeLightsLogger())
556 self._checkers.append(checks.NavLightsLogger())
557
558 def _appendLightsCheckers(self):
559 """Append the checkers needed for the lights.
560
561 This default implementation adds the checkers for the anti-collision
562 lights, the landing lights, the strobe lights and the NAV lights."""
563 self._checkers.append(checks.AntiCollisionLightsChecker())
564 self._checkers.append(checks.LandingLightsChecker())
565 self._checkers.append(checks.NavLightsChecker())
566 self._checkers.append(checks.StrobeLightsChecker())
567
568 def _speedToLog(self, speed):
569 """Convert the given speed (being either None or expressed in the
570 flight's speed unit into a string."""
571 if speed is None:
572 return "-"
573 else:
574 return str(speed) + " " + self._flight.getEnglishSpeedUnit()
575
576 def _logV1R2(self, state = None):
577 """Log the V1, Vr and V2 value either newly, or by updating the
578 corresponding line."""
579 message = "Calc. TO speeds: V1: %s, VR: %s, V2: %s" % \
580 (self._speedToLog(self._flight.v1),
581 self._speedToLog(self._flight.vr),
582 self._speedToLog(self._flight.v2))
583
584 if self._v1r2LineIndex is None:
585 if state is None:
586 state = self._aircraftState
587 self._v1r2LineIndex = \
588 self.logger.message(state.timestamp, message)
589 else:
590 self.logger.updateLine(self._v1r2LineIndex, message)
591
592 def _logDerate(self, state = None):
593 """Log the derate values either newly or by updating the corresponding
594 line."""
595 dt = self.derateType
596 if dt==DERATE_NONE:
597 return
598
599 message = self.getDerateLine(self._flight.derate)
600 if message is not None:
601 if self._derateLineID is None:
602 if state is None:
603 state = self._aircraftState
604 self._derateLineID = \
605 self.logger.message(state.timestamp, message)
606 else:
607 self.logger.updateLine(self._derateLineID, message)
608
609 def _logTakeoffAntiIce(self, state = None):
610 """Log the take-off anti-ice setting either newly or by updating the
611 corresponding line."""
612 antiIceOn = self._flight.takeoffAntiIceOn
613 if state is not None:
614 antiIceOn = antiIceOn or state.antiIceOn is True
615 self._flight.takeoffAntiIceOn = antiIceOn
616
617 message = "Anti-ice was turned %s" % \
618 ("ON" if antiIceOn else "OFF")
619
620 if self._takeoffAntiIceLineID is None:
621 if state is None:
622 state = self._aircraftState
623 self._takeoffAntiIceLineID = \
624 self.logger.message(state.timestamp, message)
625 else:
626 self.logger.updateLine(self._takeoffAntiIceLineID, message)
627
628 def updateVRef(self):
629 """Update the Vref value from the flight, if the Vref value has already
630 been logged."""
631 if self._vrefLineIndex is not None:
632 self._logVRef()
633
634 def _logVRef(self):
635 """Log the Vref value either newly, or by updating the corresponding
636 line."""
637 message = "VRef speed calculated by the pilot: %s" % \
638 (self._speedToLog(self._flight.vref),)
639 if self._vrefLineIndex is None:
640 self._vrefLineIndex = \
641 self.logger.message(self._aircraftState.timestamp, message)
642 else:
643 self.logger.updateLine(self._vrefLineIndex, message)
644
645 def updateLandingAntiIce(self):
646 """Update the landing anti-ice setting."""
647 if self._landingAntiIceLineID is not None:
648 self._logLandingAntiIce()
649
650 def _logLandingAntiIce(self, state = None):
651 """Log the landing anti-ice setting either newly or by updating the
652 corresponding line."""
653 antiIceOn = self._flight.landingAntiIceOn
654 if state is not None:
655 antiIceOn = antiIceOn or state.antiIceOn is True
656 self._flight.landingAntiIceOn = antiIceOn
657
658 message = "Anti-ice was turned %s" % \
659 ("ON" if antiIceOn else "OFF")
660
661 if self._landingAntiIceLineID is None:
662 if state is None:
663 state = self._aircraftState
664 self._landingAntiIceLineID = \
665 self.logger.message(state.timestamp, message)
666 else:
667 self.logger.updateLine(self._landingAntiIceLineID, message)
668
669 def _fleetRetrieved(self, fleet):
670 """Callback for the fleet retrieval result."""
671 if fleet is not None:
672 gateList = ""
673 occupiedGateNumbers = fleet.getOccupiedGateNumbers()
674 for gate in gates.lhbpGates.gates:
675 if gate.isAvailable(gates.lhbpGates, occupiedGateNumbers):
676 if gateList: gateList += ", "
677 gateList += gate.number
678 fs.sendMessage(const.MESSAGETYPE_GATE_SYSTEM,
679 "Free gates: " + gateList, 20)
680
681
682 def _logRadios(self, aircraftState):
683 """Log the radios from the given aircraft state."""
684 flight = self._flight
685 logger = flight.logger
686
687 self._ilsLogger.forceLog(flight, logger, aircraftState)
688 self._nav1Logger.forceLog(flight, logger, aircraftState)
689 self._nav2Logger.forceLog(flight, logger, aircraftState)
690 self._adf1Logger.forceLog(flight, logger, aircraftState)
691 self._adf2Logger.forceLog(flight, logger, aircraftState)
692
693 def _logQNH(self, aircraftState):
694 """Log the current QNH along with the altimeter setting."""
695 self.logger.message(aircraftState.timestamp,
696 "QNH: %.2f hPa, altimeter: %.2f hPa" % \
697 (aircraftState.qnh, aircraftState.altimeter))
698
699 def _logNameAndModel(self, timestamp):
700 """Log the aircraft's name and model with taking the timestamp from the
701 given state."""
702 self._flight.logger.message(timestamp,
703 "Aircraft: name='%s', model='%s'" % \
704 (self._name, self._modelName))
705
706#---------------------------------------------------------------------------------------
707
708class Boeing737(Aircraft):
709 """Base class for the various aircraft in the Boeing 737 family.
710
711 The aircraft type-specific values in the aircraft state have the following
712 structure:
713 - fuel: left, centre, right
714 - n1: left, right
715 - reverser: left, right"""
716 def __init__(self, flight, minLandingFuel = 2500,
717 recommendedLandingFuel = 3500):
718 super(Boeing737, self).__init__(flight,
719 minLandingFuel = minLandingFuel,
720 recommendedLandingFuel =
721 recommendedLandingFuel)
722
723 self.gearSpeedLimit = 270
724 self.flapSpeedLimits = { 1 : 260,
725 2 : 260,
726 5 : 250,
727 10 : 210,
728 15 : 200,
729 25 : 190,
730 30 : 175,
731 40 : 162 }
732
733 @property
734 def derateType(self):
735 """Get the derate type for this type."""
736 return DERATE_BOEING
737
738#---------------------------------------------------------------------------------------
739
740class B736(Boeing737):
741 """Boeing 737-600 aircraft."""
742 dow = 38307
743
744 def __init__(self, flight):
745 super(B736, self).__init__(flight)
746 self.mtow = 58328
747 self.mlw = 54657
748 self.mzfw = 51482
749 self.maxTakeOffPitch = 16.2
750 self.maxTouchDownPitch = 14.7
751 self.simBriefData = SimBriefData(["250/280/78"],
752 ["CI", "M75", "M78", "M79", "M80", "LRC"],
753 ["78/280/250"],
754 cruiseParameters = {0: (False, "civalue")})
755
756#---------------------------------------------------------------------------------------
757
758class B737(Boeing737):
759 """Boeing 737-700 aircraft."""
760 dow = 39250
761
762 def __init__(self, flight):
763 super(B737, self).__init__(flight)
764 self.mtow = 61410
765 self.mlw = 58059
766 self.mzfw = 54657
767 self.maxTakeOffPitch = 14.7
768 self.maxTouchDownPitch = 13.2
769 self.simBriefData = SimBriefData(["250/280/78"],
770 ["CI", "M75", "M78", "M79", "M80", "LRC"],
771 ["78/280/250", "78/250/250"],
772 cruiseParameters = {0: (False, "civalue")})
773
774#---------------------------------------------------------------------------------------
775
776class B738(Boeing737):
777 """Boeing 737-800 aircraft."""
778 dow = 42690
779
780 def __init__(self, flight):
781 super(B738, self).__init__(flight)
782 self.mtow = 71791
783 self.mlw = 65317
784 self.mzfw = 61688
785 self.maxTakeOffPitch = 11
786 self.maxTouchDownPitch = 9.5
787 self.simBriefData = SimBriefData(["250/280/78"],
788 ["CI", "M76", "M78", "M79", "M80", "LRC"],
789 ["78/280/250", "78/250/250"],
790 cruiseParameters = {0: (False, "civalue")})
791
792#---------------------------------------------------------------------------------------
793
794class B738Charter(B738):
795 """Boeing 737-800 aircraft used for charters."""
796 def __init__(self, flight):
797 super(B738Charter, self).__init__(flight)
798 self.mtow = 77791
799 self.simBriefData = SimBriefData(["AUTO"],
800 ["280/M74"],
801 ["AUTO"])
802
803#---------------------------------------------------------------------------------------
804
805class Boeing737CL(Boeing737):
806 """Base class for the various aircraft in the Boeing 737 Classic family."""
807 def __init__(self, flight):
808 super(Boeing737CL, self).__init__(flight, minLandingFuel = 3500,
809 recommendedLandingFuel = None)
810
811#---------------------------------------------------------------------------------------
812
813class B732(Boeing737CL):
814 """Boeing 737-200 aircraft."""
815 dow = 27646
816
817 def __init__(self, flight):
818 super(B732, self).__init__(flight)
819 self.mtow = 52390
820 self.mlw = 46720
821 self.mzfw = 43091
822 self.maxTakeOffPitch = 15.5
823 self.maxTouchDownPitch = 15.5
824
825#---------------------------------------------------------------------------------------
826
827class B733(Boeing737CL):
828 """Boeing 737-300 aircraft."""
829 dow = 32900
830
831 def __init__(self, flight):
832 super(B733, self).__init__(flight)
833 self.mtow = 56472
834 self.mlw = 51710
835 self.mzfw = 47625
836 self.maxTakeOffPitch = 13.4
837 self.maxTouchDownPitch = 12.0
838
839#---------------------------------------------------------------------------------------
840
841class B734(Boeing737CL):
842 """Boeing 737-400 aircraft."""
843 def __init__(self, flight):
844 super(B734, self).__init__(flight)
845 self.dow = 35100
846 self.mtow = 62822
847 self.mlw = 54885
848 self.mzfw = 51256
849 self.maxTakeOffPitch = 11.4
850 self.maxTouchDownPitch = 10
851
852#---------------------------------------------------------------------------------------
853
854class B735(Boeing737CL):
855 """Boeing 737-500 aircraft."""
856 dow = 31900
857
858 def __init__(self, flight):
859 super(B735, self).__init__(flight)
860 self.mtow = 62823
861 self.mlw = 49895
862 self.mzfw = 46720
863 self.maxTakeOffPitch = 14.7
864 self.maxTouchDownPitch = 13.2
865
866#---------------------------------------------------------------------------------------
867
868class DH8D(Aircraft):
869 """Bombardier Dash-8 Q400 aircraft.
870
871 The aircraft type-specific values in the aircraft state have the following
872 structure:
873 - fuel: left, right
874 - n1: left, right
875 - reverser: left, right."""
876 dow = 18508
877
878 def __init__(self, flight):
879 super(DH8D, self).__init__(flight, minLandingFuel = 2000)
880 self.mtow = 29574
881 self.mlw = 28123
882 self.mzfw = 26308
883 self.gearSpeedLimit = 215
884 self.flapSpeedLimits = { 5 : 200,
885 10 : 181,
886 15 : 172,
887 35 : 158 }
888 self.maxTakeOffPitch = 8.0
889 self.maxTouchDownPitch = 7.0
890 self.simBriefData = SimBriefData(["I-900", "II-900", "III-900",
891 "I-850", "II-850", "III-850"],
892 ["MCR", "ISC", "LRC", "HSC"],
893 ["I-850", "II-850", "III-850"])
894
895#---------------------------------------------------------------------------------------
896
897class Boeing767(Aircraft):
898 """Base class for the various aircraft in the Boeing 767 family.
899
900 The aircraft type-specific values in the aircraft state have the following
901 structure:
902 - fuel: left, centre, right
903 - n1: left, right
904 - reverser: left, right"""
905
906 def __init__(self, flight, minLandingFuel = 7000):
907 super(Boeing767, self).__init__(flight, minLandingFuel = minLandingFuel)
908 self.gearSpeedLimit = 270
909 self.flapSpeedLimits = { 1 : 255,
910 5 : 235,
911 10 : 215,
912 20 : 215,
913 25 : 185,
914 30 : 175 }
915
916 @property
917 def derateType(self):
918 """Get the derate type for this type."""
919 return DERATE_BOEING
920
921#---------------------------------------------------------------------------------------
922
923class B762(Boeing767):
924 """Boeing 767-200 aircraft."""
925 dow = 84507
926
927 def __init__(self, flight):
928 super(B762, self).__init__(flight)
929 self.mtow = 159210
930 self.mlw = 126098
931 self.mzfw = 114758
932 self.maxTakeOffPitch = 13.1
933 self.maxTouchDownPitch = 11.6
934
935#---------------------------------------------------------------------------------------
936
937class B763(Boeing767):
938 """Boeing 767-300 aircraft."""
939 dow = 91311
940
941 def __init__(self, flight):
942 super(B763, self).__init__(flight)
943 self.mtow = 181436
944 self.mlw = 137892
945 self.mzfw = 114758
946 self.maxTakeOffPitch = 9.6
947 self.maxTouchDownPitch = 8.1
948 self.simBriefData = SimBriefData(["250/290/78"],
949 ["CI", "M76", "M78", "M80", "M82", "M84", "LRC"],
950 ["78/290/250"])
951
952 def setBookedFlight(self, bookedFlight):
953 """Update the aircraft based on the booked flight data (e.g. tail number)."""
954 if bookedFlight.tailNumber=="HA-LHD":
955 self.mtow = 159210
956 self.mlw = 126098
957
958#---------------------------------------------------------------------------------------
959
960class CRJ2(Aircraft):
961 """Bombardier CRJ-200 aircraft.
962
963 The aircraft type-specific values in the aircraft state have the following
964 structure:
965 - fuel: left, centre, right
966 - n1: left, right
967 - reverser: left, right."""
968 dow = 14549
969
970 def __init__(self, flight):
971 super(CRJ2, self).__init__(flight, minLandingFuel = 1000)
972 self.mtow = 22995
973 self.mlw = 21319
974 self.mzfw = 19958
975 self.gearSpeedLimit = 240
976 self.flapSpeedLimits = { 8 : 260,
977 20 : 220,
978 30 : 190,
979 45 : 175 }
980 self.maxTakeOffPitch = 18.0
981 self.maxTouchDownPitch = 18.0
982 self.simBriefData = SimBriefData(["250/70", "290/74"],
983 ["CI", "LRC", "M70", "M72", "M74", "M77", "M80"],
984 ["74/290/250", "77/320/250"])
985
986#---------------------------------------------------------------------------------------
987
988class F70(Aircraft):
989 """Fokker 70 aircraft.
990
991 The aircraft type-specific values in the aircraft state have the following
992 structure:
993 - fuel: left, centre, right
994 - n1: left, right
995 - reverser: left, right."""
996 dow = 24283
997
998 def __init__(self, flight):
999 super(F70, self).__init__(flight, minLandingFuel = 1900)
1000 self.mtow = 38100 # FIXME: differentiate by registration number,
1001 # MTOW of HA-LMF: 41955
1002 self.mlw = 36740
1003 self.mzfw = 32655
1004 self.gearSpeedLimit = 200
1005 self.flapSpeedLimits = { 8 : 250,
1006 15 : 220,
1007 25 : 220,
1008 42 : 180 }
1009 self.reverseMinSpeed = 50
1010 self.maxTakeOffPitch = 16.0
1011 self.maxTouchDownPitch = 16.0
1012
1013 @property
1014 def derateType(self):
1015 """Get the derate type for this type."""
1016 return DERATE_EPR
1017
1018#---------------------------------------------------------------------------------------
1019
1020class DC3(Aircraft):
1021 """Lisunov Li-2 (DC-3) aircraft.
1022
1023 The aircraft type-specific values in the aircraft state have the following
1024 structure:
1025 - fuel: left aux, left, right, right aux
1026 - rpm: left, right
1027 - reverser: left, right."""
1028 dow = 8627
1029
1030 def __init__(self, flight):
1031 super(DC3, self).__init__(flight)
1032 self.mtow = 11884
1033 self.mlw = 11793
1034 self.mzfw = 11780
1035 self.gearSpeedLimit = 148
1036 self.flapSpeedLimits = { 15 : 135,
1037 30 : 99,
1038 45 : 97 }
1039
1040 def _checkFlightEnd(self, aircraftState):
1041 """Check if the end of the flight has arrived.
1042
1043 This implementation checks the RPM values to be 0."""
1044 for rpm in aircraftState.rpm:
1045 if rpm>0: return False
1046 return True
1047
1048#---------------------------------------------------------------------------------------
1049
1050class T134(Aircraft):
1051 """Tupolev Tu-134 aircraft.
1052
1053 The aircraft type-specific values in the aircraft state have the following
1054 structure:
1055 - fuel: left tip, left aux, centre, right aux, right tip, external 1,
1056 external 2
1057 - n1: left, right
1058 - reverser: left, right."""
1059 dow = 29500
1060
1061 def __init__(self, flight):
1062 super(T134, self).__init__(flight, minLandingFuel = 3000)
1063 self.mtow = 49000
1064 self.mlw = 43000
1065 self.mzfw = 38500
1066 self.gearSpeedLimit = 216
1067 self.flapSpeedLimits = { 10 : 450,
1068 20 : 400,
1069 30 : 300 }
1070 self.reverseMinSpeed = 50
1071
1072 self.hasStrobeLight = False
1073
1074 self.maxTakeOffPitch = 16.0
1075 self.maxTouchDownPitch = 16.0
1076
1077 @property
1078 def derateType(self):
1079 """Get the derate type for this type."""
1080 return DERATE_TUPOLEV
1081
1082 @property
1083 def speedInKnots(self):
1084 """Indicate if the speed is in knots."""
1085 return False
1086
1087 @property
1088 def aglInFeet(self):
1089 """Indicate if AGL altituedes are in feet."""
1090 return False
1091
1092 def _appendLightsLoggers(self):
1093 """Append the loggers needed for the lights."""
1094 self._checkers.append(checks.AnticollisionLightsLogger())
1095 self._checkers.append(checks.LandingLightsLogger())
1096 self._checkers.append(checks.NavLightsLogger())
1097
1098 def _appendLightsCheckers(self):
1099 """Append the checkers needed for the lights."""
1100 self._checkers.append(checks.TupolevAntiCollisionLightsChecker())
1101 self._checkers.append(checks.TupolevLandingLightsChecker())
1102 self._checkers.append(checks.LandingLightsChecker())
1103 self._checkers.append(checks.NavLightsChecker())
1104
1105#---------------------------------------------------------------------------------------
1106
1107class T154(Aircraft):
1108 """Tupolev Tu-154 aircraft.
1109
1110 The aircraft type-specific values in the aircraft state have the following
1111 structure:
1112 - fuel: left aux, left, centre, centre 2, right, right aux
1113 - n1: left, centre, right
1114 - reverser: left, right"""
1115 dow = 53259
1116
1117 def __init__(self, flight):
1118 super(T154, self).__init__(flight, minLandingFuel = 5000)
1119 self.mtow = 98000
1120 self.mlw = 78000
1121 self.mzfw = 72000
1122 self.gearSpeedLimit = 216
1123 self.flapSpeedLimits = { 15 : 227,
1124 28 : 194,
1125 45 : 162 }
1126 self.reverseMinSpeed = 50
1127
1128 self.hasStrobeLight = False
1129
1130 self.maxTakeOffPitch = 16.0
1131 self.maxTouchDownPitch = 16.0
1132 self.simBriefData = SimBriefData(["AUTO"],
1133 ["300/M80"],
1134 ["AUTO"])
1135
1136 @property
1137 def speedInKnots(self):
1138 """Indicate if the speed is in knots."""
1139 return False
1140
1141 @property
1142 def aglInFeet(self):
1143 """Indicate if AGL altituedes are in feet."""
1144 return False
1145
1146 @property
1147 def derateType(self):
1148 """Get the derate type for this type."""
1149 return DERATE_TUPOLEV
1150
1151 def setBookedFlight(self, bookedFlight):
1152 """Update the aircraft based on the booked flight data (e.g. tail number)."""
1153 if bookedFlight.tailNumber in ["HA-LCM", "HA-LCN", "HA-LCO", "HA-LCP",
1154 "HA-LCR", "HA-LCU", "HA-LCV"]:
1155 self.mtow = 100000
1156 self.mlw = 80000
1157 elif bookedFlight.tailNumber=="HA-LCX":
1158 self.mtow = 100000
1159 self.mlw = 80000
1160 self.mzfw = 74000
1161
1162 self.flapSpeedLimits = { 15 : 227,
1163 28 : 194,
1164 36 : 178,
1165 45 : 162 }
1166
1167 def _appendLightsLoggers(self):
1168 """Append the loggers needed for the lights."""
1169 self._checkers.append(checks.AnticollisionLightsLogger())
1170 self._checkers.append(checks.LandingLightsLogger())
1171 self._checkers.append(checks.NavLightsLogger())
1172
1173 def _appendLightsCheckers(self):
1174 """Append the checkers needed for the lights."""
1175 self._checkers.append(checks.AntiCollisionLightsChecker())
1176 self._checkers.append(checks.TupolevLandingLightsChecker())
1177 self._checkers.append(checks.LandingLightsChecker())
1178 self._checkers.append(checks.NavLightsChecker())
1179
1180#---------------------------------------------------------------------------------------
1181
1182class YK40(Aircraft):
1183 """Yakovlev Yak-40 aircraft.
1184
1185 The aircraft type-specific values in the aircraft state have the following
1186 structure:
1187 - fuel: left, right
1188 - n1: left, right
1189 - reverser: left, right"""
1190 dow = 9400
1191
1192 def __init__(self, flight):
1193 super(YK40, self).__init__(flight)
1194 self.mtow = 17200
1195 self.mlw = 16800
1196 self.mzfw = 12100
1197 self.gearSpeedLimit = 165
1198 self.flapSpeedLimits = { 20 : 165,
1199 35 : 135 }
1200
1201 self.hasStrobeLight = False
1202
1203 @property
1204 def speedInKnots(self):
1205 """Indicate if the speed is in knots."""
1206 return False
1207
1208 @property
1209 def aglInFeet(self):
1210 """Indicate if AGL altituedes are in feet."""
1211 return False
1212
1213 @property
1214 def derateType(self):
1215 """Get the derate type for this type."""
1216 return DERATE_TUPOLEV
1217
1218 def _appendLightsLoggers(self):
1219 """Append the loggers needed for the lights."""
1220 self._checkers.append(checks.AnticollisionLightsLogger())
1221 self._checkers.append(checks.LandingLightsLogger())
1222 self._checkers.append(checks.NavLightsLogger())
1223
1224 def _appendLightsCheckers(self):
1225 """Append the checkers needed for the lights."""
1226 self._checkers.append(checks.AntiCollisionLightsChecker())
1227 self._checkers.append(checks.LandingLightsChecker())
1228 self._checkers.append(checks.NavLightsChecker())
1229
1230#---------------------------------------------------------------------------------------
1231
1232class B462(Aircraft):
1233 """British Aerospace BAe-146 aircraft.
1234
1235 The aircraft type-specific values in the aircraft state have the following
1236 structure:
1237 - fuel: left, centre, right
1238 - n1: left outer, left inner, right inner, right outer
1239 - reverser: empty (the plane has no reversers)"""
1240 dow = 25706
1241
1242 def __init__(self, flight):
1243 super(B462, self).__init__(flight)
1244 self.mtow = 43998
1245 self.mlw = 38599
1246 self.mzfw = 33792
1247 self.gearSpeedLimit = 210
1248 self.flapSpeedLimits = { 18 : 217,
1249 24 : 180,
1250 30 : 170,
1251 33 : 150 }
1252
1253 @property
1254 def derateType(self):
1255 """Get the derate type for this type."""
1256 return DERATE_B462
1257
1258#---------------------------------------------------------------------------------------
1259
1260mostFuelTanks = [const.FUELTANK_LEFT_TIP, const.FUELTANK_EXTERNAL1,
1261 const.FUELTANK_LEFT_AUX,
1262 const.FUELTANK_CENTRE,
1263 const.FUELTANK_RIGHT_AUX,
1264 const.FUELTANK_EXTERNAL2, const.FUELTANK_RIGHT_TIP]
1265
1266#---------------------------------------------------------------------------------------
1267
1268_classes = { const.AIRCRAFT_B736 : B736,
1269 const.AIRCRAFT_B737 : B737,
1270 const.AIRCRAFT_B738 : B738,
1271 const.AIRCRAFT_B738C : B738Charter,
1272 const.AIRCRAFT_B732 : B732,
1273 const.AIRCRAFT_B733 : B733,
1274 const.AIRCRAFT_B734 : B734,
1275 const.AIRCRAFT_B735 : B735,
1276 const.AIRCRAFT_DH8D : DH8D,
1277 const.AIRCRAFT_B762 : B762,
1278 const.AIRCRAFT_B763 : B763,
1279 const.AIRCRAFT_CRJ2 : CRJ2,
1280 const.AIRCRAFT_F70 : F70,
1281 const.AIRCRAFT_DC3 : DC3,
1282 const.AIRCRAFT_T134 : T134,
1283 const.AIRCRAFT_T154 : T154,
1284 const.AIRCRAFT_YK40 : YK40,
1285 const.AIRCRAFT_B462 : B462 }
1286
1287#---------------------------------------------------------------------------------------
1288
1289def getClass(aircraftType):
1290 """Get the class representing the given aircraft types"""
1291 return _classes[aircraftType]
1292
1293#---------------------------------------------------------------------------------------
1294
1295if __name__ == "__main__":
1296 value = SmoothedValue()
1297
1298 print("Adding 1, 12.0")
1299 value.add(1, 12.0)
1300 print(value.get())
1301
1302 print("Adding 1, 15.0")
1303 value.add(1, 15.0)
1304 print(value.get())
1305
1306 print("Adding 2, 18.0")
1307 value.add(2, 18.0)
1308 print(value.get())
1309
1310 print("Adding 2, 20.0")
1311 value.add(2, 20.0)
1312 print(value.get())
1313
1314 print("Adding 5, 22.0")
1315 value.add(5, 22.0)
1316 print(value.get())
1317
1318 print("Adding 5, 25.0")
1319 value.add(5, 25.0)
1320 print(value.get())
1321
1322 print("Adding 5, 29.0")
1323 value.add(5, 29.0)
1324 print(value.get())
1325
1326 print("Adding 5, 21.0")
1327 value.add(5, 21.0)
1328 print(value.get())
1329
1330 print("Adding 5, 26.0")
1331 value.add(5, 26.0)
1332 print(value.get())
1333
1334 print("Adding 2, 30.0")
1335 value.add(2, 30.0)
1336 print(value.get())
1337
1338 print("Adding 2, 55.0")
1339 value.add(2, 55.0)
1340 print(value.get())
1341
1342#---------------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.