[298] | 1 |
|
---|
| 2 | import fs
|
---|
| 3 | import const
|
---|
| 4 | import util
|
---|
| 5 | from acars import ACARS
|
---|
| 6 | from sound import startSound
|
---|
| 7 |
|
---|
| 8 | import time
|
---|
| 9 |
|
---|
| 10 | #---------------------------------------------------------------------------------------
|
---|
| 11 |
|
---|
[297] | 12 | ## @package mlx.checks
|
---|
| 13 | #
|
---|
| 14 | # The classes that check the state of the aircraft.
|
---|
| 15 | #
|
---|
| 16 | # During the flight the program periodically queries various data from the
|
---|
| 17 | # simulator. This data is returned in instances of the \ref
|
---|
| 18 | # mlx.fs.AircraftState class and passed to the various "checkers",
|
---|
| 19 | # i.e. instances of subclasses of the \ref StateChecker class. These checkers
|
---|
| 20 | # perform various checks to see if the aircraft's parameters are within the
|
---|
| 21 | # expected limits, or some of them just logs something.
|
---|
| 22 | #
|
---|
| 23 | # There are a few special ones, such as \ref StageChecker which computes the
|
---|
| 24 | # transitions from one stage of the flight to the next one. Or \ref ACARSSender
|
---|
| 25 | # which sends the ACARS periodically
|
---|
[8] | 26 |
|
---|
| 27 | #---------------------------------------------------------------------------------------
|
---|
| 28 |
|
---|
| 29 | class StateChecker(object):
|
---|
| 30 | """Base class for classes the instances of which check the aircraft's state
|
---|
| 31 | from some aspect.
|
---|
| 32 |
|
---|
| 33 | As a result of the check they may log something, or notify of some fault, etc."""
|
---|
| 34 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 35 | """Perform the check and do whatever is needed.
|
---|
| 36 |
|
---|
| 37 | This default implementation raises a NotImplementedError."""
|
---|
| 38 | raise NotImplementedError()
|
---|
[332] | 39 |
|
---|
[8] | 40 | #---------------------------------------------------------------------------------------
|
---|
| 41 |
|
---|
| 42 | class StageChecker(StateChecker):
|
---|
| 43 | """Check the flight stage transitions."""
|
---|
[25] | 44 | def __init__(self):
|
---|
| 45 | """Construct the stage checker."""
|
---|
| 46 | self._flareStarted = False
|
---|
| 47 |
|
---|
[8] | 48 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 49 | """Check the stage of the aircraft."""
|
---|
| 50 | stage = flight.stage
|
---|
| 51 | if stage==None:
|
---|
| 52 | aircraft.setStage(state, const.STAGE_BOARDING)
|
---|
| 53 | elif stage==const.STAGE_BOARDING:
|
---|
| 54 | if not state.parking or \
|
---|
| 55 | (not state.trickMode and state.groundSpeed>5.0):
|
---|
| 56 | aircraft.setStage(state, const.STAGE_PUSHANDTAXI)
|
---|
| 57 | elif stage==const.STAGE_PUSHANDTAXI or stage==const.STAGE_RTO:
|
---|
[477] | 58 | if state.strobeLightsOn or \
|
---|
| 59 | (state.strobeLightsOn is None and state.xpdrC):
|
---|
[8] | 60 | aircraft.setStage(state, const.STAGE_TAKEOFF)
|
---|
| 61 | elif stage==const.STAGE_TAKEOFF:
|
---|
| 62 | if not state.gearsDown or \
|
---|
| 63 | (state.radioAltitude>3000.0 and state.vs>0):
|
---|
| 64 | aircraft.setStage(state, const.STAGE_CLIMB)
|
---|
| 65 | elif not state.landingLightsOn and \
|
---|
[477] | 66 | (state.strobeLightsOn is False or
|
---|
| 67 | (state.strobeLightsOn is None and not state.xpdrC)) and \
|
---|
[8] | 68 | state.onTheGround and \
|
---|
| 69 | state.groundSpeed<50.0:
|
---|
| 70 | aircraft.setStage(state, const.STAGE_RTO)
|
---|
| 71 | elif stage==const.STAGE_CLIMB:
|
---|
| 72 | if (state.altitude+2000) > flight.cruiseAltitude:
|
---|
| 73 | aircraft.setStage(state, const.STAGE_CRUISE)
|
---|
| 74 | elif state.radioAltitude<2000.0 and \
|
---|
| 75 | state.vs < 0.0 and state.gearsDown:
|
---|
| 76 | aircraft.setStage(state, const.STAGE_LANDING)
|
---|
| 77 | elif stage==const.STAGE_CRUISE:
|
---|
| 78 | if (state.altitude+2000) < flight.cruiseAltitude:
|
---|
| 79 | aircraft.setStage(state, const.STAGE_DESCENT)
|
---|
| 80 | elif stage==const.STAGE_DESCENT or stage==const.STAGE_GOAROUND:
|
---|
| 81 | if state.gearsDown and state.radioAltitude<2000.0:
|
---|
| 82 | aircraft.setStage(state, const.STAGE_LANDING)
|
---|
| 83 | elif (state.altitude+2000) > flight.cruiseAltitude:
|
---|
| 84 | aircraft.setStage(state, const.STAGE_CRUISE)
|
---|
| 85 | elif stage==const.STAGE_LANDING:
|
---|
[332] | 86 | if state.onTheGround and state.groundSpeed<25.0:
|
---|
[8] | 87 | aircraft.setStage(state, const.STAGE_TAXIAFTERLAND)
|
---|
| 88 | elif not state.gearsDown:
|
---|
| 89 | aircraft.setStage(state, const.STAGE_GOAROUND)
|
---|
[25] | 90 | elif state.radioAltitude>200 and self._flareStarted:
|
---|
[8] | 91 | aircraft.cancelFlare()
|
---|
[25] | 92 | self._flareStarted = False
|
---|
| 93 | elif state.radioAltitude<150 and not state.onTheGround and \
|
---|
| 94 | not self._flareStarted:
|
---|
| 95 | self._flareStarted = True
|
---|
[9] | 96 | aircraft.prepareFlare()
|
---|
[8] | 97 | elif stage==const.STAGE_TAXIAFTERLAND:
|
---|
[359] | 98 | if state.parking and aircraft.checkFlightEnd(state):
|
---|
[8] | 99 | aircraft.setStage(state, const.STAGE_END)
|
---|
| 100 |
|
---|
| 101 | #---------------------------------------------------------------------------------------
|
---|
| 102 |
|
---|
[139] | 103 | class ACARSSender(StateChecker):
|
---|
| 104 | """Sender of online ACARS.
|
---|
| 105 |
|
---|
| 106 | It sends the ACARS every 3 minutes to the MAVA website."""
|
---|
| 107 |
|
---|
[297] | 108 | ## The interval at which the ACARS are sent
|
---|
[139] | 109 | INTERVAL = 3*60.0
|
---|
[332] | 110 |
|
---|
[139] | 111 | def __init__(self, gui):
|
---|
| 112 | """Construct the ACARS sender."""
|
---|
| 113 | self._gui = gui
|
---|
| 114 | self._lastSent = None
|
---|
[374] | 115 | self._sending = False
|
---|
[139] | 116 |
|
---|
| 117 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 118 | """If the time has come to send the ACARS, send it."""
|
---|
[374] | 119 | if self._sending:
|
---|
| 120 | return
|
---|
| 121 |
|
---|
[139] | 122 | now = time.time()
|
---|
[332] | 123 |
|
---|
[139] | 124 | if self._lastSent is not None and \
|
---|
| 125 | (self._lastSent + ACARSSender.INTERVAL)>now:
|
---|
[332] | 126 | return
|
---|
[139] | 127 |
|
---|
[380] | 128 | self._sending = True
|
---|
[139] | 129 | acars = ACARS(self._gui, state)
|
---|
| 130 | self._gui.webHandler.sendACARS(self._acarsCallback, acars)
|
---|
| 131 |
|
---|
| 132 | def _acarsCallback(self, returned, result):
|
---|
| 133 | """Callback for ACARS sending."""
|
---|
| 134 | if returned:
|
---|
| 135 | print "Sent online ACARS"
|
---|
| 136 | self._lastSent = time.time() if self._lastSent is None \
|
---|
| 137 | else self._lastSent + ACARSSender.INTERVAL
|
---|
| 138 | else:
|
---|
| 139 | print "Failed to send the ACARS"
|
---|
[374] | 140 | self._sending = False
|
---|
[332] | 141 |
|
---|
[139] | 142 | #---------------------------------------------------------------------------------------
|
---|
| 143 |
|
---|
[9] | 144 | class TakeOffLogger(StateChecker):
|
---|
| 145 | """Logger for the cruise speed."""
|
---|
| 146 | def __init__(self):
|
---|
| 147 | """Construct the logger."""
|
---|
| 148 | self._onTheGround = True
|
---|
[332] | 149 |
|
---|
[9] | 150 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 151 | """Log the cruise speed if necessary."""
|
---|
| 152 | if flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 153 | self._onTheGround and not state.onTheGround:
|
---|
| 154 | logger.message(state.timestamp,
|
---|
[241] | 155 | "Takeoff speed: %.0f %s" % \
|
---|
| 156 | (flight.speedFromKnots(state.ias),
|
---|
| 157 | flight.getEnglishSpeedUnit()))
|
---|
[9] | 158 | logger.message(state.timestamp,
|
---|
| 159 | "Takeoff heading: %03.0f degrees" % (state.heading,))
|
---|
| 160 | logger.message(state.timestamp,
|
---|
| 161 | "Takeoff pitch: %.1f degrees" % (state.pitch,))
|
---|
[332] | 162 | logger.message(state.timestamp,
|
---|
[364] | 163 | "Takeoff flaps: %.0f" % (state.flapsSet))
|
---|
| 164 | logger.message(state.timestamp,
|
---|
[340] | 165 | "CG/Trim: %.1f%%/%.2f" % \
|
---|
| 166 | (state.cog*100.0, state.elevatorTrim))
|
---|
[9] | 167 | self._onTheGround = False
|
---|
| 168 |
|
---|
| 169 | #---------------------------------------------------------------------------------------
|
---|
| 170 |
|
---|
| 171 | class CruiseSpeedLogger(StateChecker):
|
---|
| 172 | """Logger for the cruise speed."""
|
---|
| 173 | def __init__(self):
|
---|
| 174 | """Construct the logger."""
|
---|
| 175 | self._lastTime = None
|
---|
[332] | 176 |
|
---|
[9] | 177 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 178 | """Log the cruise speed if necessary."""
|
---|
| 179 | if flight.stage==const.STAGE_CRUISE and \
|
---|
| 180 | (self._lastTime is None or \
|
---|
| 181 | (self._lastTime+800)<=state.timestamp):
|
---|
| 182 | if state.altitude>24500.0:
|
---|
| 183 | logger.message(state.timestamp,
|
---|
[10] | 184 | "Cruise speed: %.3f mach" % (state.mach,))
|
---|
[9] | 185 | else:
|
---|
| 186 | logger.message(state.timestamp,
|
---|
[241] | 187 | "Cruise speed: %.0f %s" %
|
---|
| 188 | (flight.speedFromKnots(state.ias),
|
---|
| 189 | flight.getEnglishSpeedUnit()))
|
---|
[9] | 190 | self._lastTime = state.timestamp
|
---|
| 191 |
|
---|
| 192 | #---------------------------------------------------------------------------------------
|
---|
| 193 |
|
---|
[10] | 194 | class SpoilerLogger(StateChecker):
|
---|
| 195 | """Logger for the cruise speed."""
|
---|
| 196 | def __init__(self):
|
---|
| 197 | """Construct the logger."""
|
---|
| 198 | self._logged = False
|
---|
[13] | 199 | self._spoilersExtension = None
|
---|
[332] | 200 |
|
---|
[10] | 201 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 202 | """Log the cruise speed if necessary."""
|
---|
| 203 | if flight.stage==const.STAGE_LANDING and not self._logged:
|
---|
| 204 | if state.onTheGround:
|
---|
[13] | 205 | if state.spoilersExtension!=self._spoilersExtension:
|
---|
[10] | 206 | logger.message(state.timestamp, "Spoilers deployed")
|
---|
| 207 | self._logged = True
|
---|
[170] | 208 | config = flight.config
|
---|
| 209 | if config.enableSounds and config.speedbrakeAtTD:
|
---|
| 210 | startSound(const.SOUND_SPEEDBRAKE)
|
---|
[10] | 211 | else:
|
---|
[13] | 212 | self._spoilersExtension = state.spoilersExtension
|
---|
[10] | 213 |
|
---|
| 214 | #---------------------------------------------------------------------------------------
|
---|
| 215 |
|
---|
[134] | 216 | class VisibilityChecker(StateChecker):
|
---|
| 217 | """Inform the pilot of the visibility once when descending below 2000 ft,
|
---|
| 218 | then when descending below 1000 ft."""
|
---|
| 219 | def __init__(self):
|
---|
| 220 | """Construct the visibility checker."""
|
---|
| 221 | self._informedBelow2000 = False
|
---|
| 222 | self._informedBelow1000 = False
|
---|
| 223 |
|
---|
| 224 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 225 | """Check if we need to inform the pilot of the visibility."""
|
---|
| 226 | if flight.stage==const.STAGE_DESCENT or \
|
---|
| 227 | flight.stage==const.STAGE_LANDING:
|
---|
| 228 | if (state.radioAltitude<2000 and not self._informedBelow2000) or \
|
---|
| 229 | (state.radioAltitude<1000 and not self._informedBelow1000):
|
---|
| 230 | visibilityString = util.visibility2String(state.visibility)
|
---|
| 231 | fs.sendMessage(const.MESSAGETYPE_VISIBILITY,
|
---|
| 232 | "Current visibility: " + visibilityString,
|
---|
| 233 | 5)
|
---|
| 234 | logger.message(state.timestamp,
|
---|
| 235 | "Pilot was informed about the visibility: " +
|
---|
| 236 | visibilityString)
|
---|
| 237 | self._informedBelow2000 = True
|
---|
| 238 | self._informedBelow1000 = state.radioAltitude<1000
|
---|
| 239 |
|
---|
| 240 | #---------------------------------------------------------------------------------------
|
---|
| 241 |
|
---|
[273] | 242 | class ApproachCalloutsPlayer(StateChecker):
|
---|
| 243 | """A state checker that plays a sequence of approach callouts.
|
---|
| 244 |
|
---|
| 245 | It tracks the altitude during the descent and landing phases and
|
---|
| 246 | if the altitude crosses one that has a callout associated with and
|
---|
[332] | 247 | the vertical speed is negative, that callout will be played."""
|
---|
[273] | 248 | def __init__(self, approachCallouts):
|
---|
| 249 | """Construct the approach callouts player."""
|
---|
| 250 | self._approachCallouts = approachCallouts
|
---|
| 251 | self._altitudes = approachCallouts.getAltitudes(descending = False)
|
---|
| 252 |
|
---|
| 253 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 254 | """Check if we need to play a callout."""
|
---|
| 255 | if (flight.stage==const.STAGE_DESCENT or \
|
---|
| 256 | flight.stage==const.STAGE_LANDING) and state.vs<0:
|
---|
| 257 | oldRadioAltitude = oldState.radioAltitude
|
---|
| 258 | radioAltitude = state.radioAltitude
|
---|
| 259 | for altitude in self._altitudes:
|
---|
| 260 | if radioAltitude<=altitude and \
|
---|
| 261 | oldRadioAltitude>altitude:
|
---|
| 262 | startSound(self._approachCallouts[altitude])
|
---|
| 263 | break
|
---|
| 264 |
|
---|
| 265 | #---------------------------------------------------------------------------------------
|
---|
| 266 |
|
---|
[8] | 267 | class StateChangeLogger(StateChecker):
|
---|
| 268 | """Base class for classes the instances of which check if a specific change has
|
---|
| 269 | occured in the aircraft's state, and log such change."""
|
---|
[356] | 270 | def __init__(self, logInitial = True, excludedStages = None):
|
---|
[8] | 271 | """Construct the logger.
|
---|
| 272 |
|
---|
| 273 | If logInitial is True, the initial value will be logged, not just the
|
---|
| 274 | changes later.
|
---|
| 275 |
|
---|
[356] | 276 | If excludedStages is given, it should be a list containing those stages
|
---|
| 277 | during which the changes should not be logged.
|
---|
| 278 |
|
---|
[8] | 279 | Child classes should define the following functions:
|
---|
| 280 | - _changed(self, oldState, state): returns a boolean indicating if the
|
---|
| 281 | value has changed or not
|
---|
[321] | 282 | - _getMessage(self, flight, state, forced): return a strings containing
|
---|
| 283 | the message to log with the new value
|
---|
[8] | 284 | """
|
---|
[332] | 285 | self._logInitial = logInitial
|
---|
[356] | 286 | self._excludedStages = [] if excludedStages is None else excludedStages
|
---|
[8] | 287 |
|
---|
[324] | 288 | def _getLogTimestamp(self, state, forced):
|
---|
[22] | 289 | """Get the log timestamp."""
|
---|
| 290 | return state.timestamp
|
---|
| 291 |
|
---|
[8] | 292 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 293 | """Check if the state has changed, and if so, log the new state."""
|
---|
[356] | 294 | if flight.stage in self._excludedStages:
|
---|
| 295 | return
|
---|
| 296 |
|
---|
[8] | 297 | shouldLog = False
|
---|
| 298 | if oldState is None:
|
---|
| 299 | shouldLog = self._logInitial
|
---|
| 300 | else:
|
---|
| 301 | shouldLog = self._changed(oldState, state)
|
---|
[332] | 302 |
|
---|
[8] | 303 | if shouldLog:
|
---|
[321] | 304 | self.logState(flight, logger, state)
|
---|
| 305 |
|
---|
| 306 | def logState(self, flight, logger, state, forced = False):
|
---|
| 307 | """Log the state."""
|
---|
| 308 | message = self._getMessage(flight, state, forced)
|
---|
| 309 | if message is not None:
|
---|
[324] | 310 | logger.message(self._getLogTimestamp(state, forced), message)
|
---|
[332] | 311 |
|
---|
[241] | 312 | #-------------------------------------------------------------------------------
|
---|
[8] | 313 |
|
---|
| 314 | class SimpleChangeMixin(object):
|
---|
| 315 | """A mixin that defines a _changed() function which simply calls a function
|
---|
| 316 | to retrieve the value two monitor for both states and compares them.
|
---|
| 317 |
|
---|
| 318 | Child classes should define the following function:
|
---|
| 319 | - _getValue(state): get the value we are interested in."""
|
---|
| 320 | def _changed(self, oldState, state):
|
---|
| 321 | """Determine if the value has changed."""
|
---|
[314] | 322 | currentValue = self._getValue(state)
|
---|
| 323 | return currentValue is not None and self._getValue(oldState)!=currentValue
|
---|
[8] | 324 |
|
---|
| 325 | #---------------------------------------------------------------------------------------
|
---|
| 326 |
|
---|
| 327 | class SingleValueMixin(object):
|
---|
| 328 | """A mixin that provides a _getValue() function to query a value from the
|
---|
| 329 | state using the name of the attribute."""
|
---|
| 330 | def __init__(self, attrName):
|
---|
| 331 | """Construct the mixin with the given attribute name."""
|
---|
| 332 | self._attrName = attrName
|
---|
| 333 |
|
---|
| 334 | def _getValue(self, state):
|
---|
| 335 | """Get the value of the attribute from the state."""
|
---|
| 336 | return getattr(state, self._attrName)
|
---|
[332] | 337 |
|
---|
[8] | 338 | #---------------------------------------------------------------------------------------
|
---|
| 339 |
|
---|
| 340 | class DelayedChangeMixin(object):
|
---|
| 341 | """A mixin to a StateChangeLogger that stores the old value and reports a
|
---|
| 342 | change only if the change has been there for a certain amount of time.
|
---|
| 343 |
|
---|
| 344 | Child classes should define the following function:
|
---|
| 345 | - _getValue(state): get the value we are interested in."""
|
---|
[22] | 346 | def __init__(self, minDelay = 3.0, maxDelay = 10.0):
|
---|
[8] | 347 | """Construct the mixin with the given delay in seconds."""
|
---|
[22] | 348 | self._minDelay = minDelay
|
---|
| 349 | self._maxDelay = maxDelay
|
---|
[8] | 350 | self._oldValue = None
|
---|
| 351 | self._firstChange = None
|
---|
[22] | 352 | self._lastChangeState = None
|
---|
[355] | 353 | self._lastLoggedValue = None
|
---|
| 354 |
|
---|
| 355 | self._logState = lambda flight, logger, state, forced = False: \
|
---|
| 356 | StateChangeLogger.logState(self, flight, logger, state,
|
---|
| 357 | forced = forced)
|
---|
| 358 | self.logState = lambda flight, logger, state, forced = False: \
|
---|
| 359 | DelayedChangeMixin.logState(self, flight, logger, state,
|
---|
| 360 | forced = forced)
|
---|
[332] | 361 |
|
---|
[8] | 362 | def _changed(self, oldState, state):
|
---|
| 363 | """Determine if the value has changed."""
|
---|
| 364 | if self._oldValue is None:
|
---|
| 365 | self._oldValue = self._getValue(oldState)
|
---|
[332] | 366 |
|
---|
[8] | 367 | newValue = self._getValue(state)
|
---|
[321] | 368 | if self._isDifferent(self._oldValue, newValue):
|
---|
[355] | 369 | if self._lastLoggedValue is not None and \
|
---|
| 370 | not self._isDifferent(self._lastLoggedValue, newValue):
|
---|
| 371 | self._firstChange = None
|
---|
| 372 | else:
|
---|
| 373 | if self._firstChange is None:
|
---|
| 374 | self._firstChange = state.timestamp
|
---|
| 375 | self._lastChangeState = state
|
---|
[22] | 376 | self._oldValue = newValue
|
---|
| 377 |
|
---|
| 378 | if self._firstChange is not None:
|
---|
[324] | 379 | if state.timestamp >= min(self._lastChangeState.timestamp +
|
---|
| 380 | self._minDelay,
|
---|
[22] | 381 | self._firstChange + self._maxDelay):
|
---|
[8] | 382 | self._firstChange = None
|
---|
| 383 | return True
|
---|
[332] | 384 |
|
---|
[22] | 385 | return False
|
---|
[8] | 386 |
|
---|
[324] | 387 | def _getLogTimestamp(self, state, forced):
|
---|
[22] | 388 | """Get the log timestamp."""
|
---|
[324] | 389 | return self._lastChangeState.timestamp \
|
---|
| 390 | if not forced and self._lastChangeState is not None \
|
---|
| 391 | else state.timestamp
|
---|
[8] | 392 |
|
---|
[321] | 393 | def _isDifferent(self, oldValue, newValue):
|
---|
| 394 | """Determine if the given values are different.
|
---|
| 395 |
|
---|
| 396 | This default implementation checks for simple equality."""
|
---|
| 397 | return oldValue!=newValue
|
---|
| 398 |
|
---|
[355] | 399 | def logState(self, flight, logger, state, forced):
|
---|
| 400 | """Log the given state.
|
---|
| 401 |
|
---|
| 402 | The value belonging to that state is recorded in _lastLoggedValue.
|
---|
| 403 |
|
---|
| 404 | It calls _logState to perform the real logging."""
|
---|
| 405 | self._lastLoggedValue = self._getValue(state)
|
---|
| 406 | self._logState(flight, logger, state, forced = forced)
|
---|
| 407 |
|
---|
[8] | 408 | #---------------------------------------------------------------------------------------
|
---|
| 409 |
|
---|
| 410 | class TemplateMessageMixin(object):
|
---|
| 411 | """Mixin to generate a message based on a template.
|
---|
| 412 |
|
---|
| 413 | Child classes should define the following function:
|
---|
| 414 | - _getValue(state): get the value we are interested in."""
|
---|
| 415 | def __init__(self, template):
|
---|
| 416 | """Construct the mixin."""
|
---|
| 417 | self._template = template
|
---|
| 418 |
|
---|
[321] | 419 | def _getMessage(self, flight, state, forced):
|
---|
[8] | 420 | """Get the message."""
|
---|
[332] | 421 | value = self._getValue(state)
|
---|
[320] | 422 | return None if value is None else self._template % (value,)
|
---|
[8] | 423 |
|
---|
| 424 | #---------------------------------------------------------------------------------------
|
---|
| 425 |
|
---|
| 426 | class GenericStateChangeLogger(StateChangeLogger, SingleValueMixin,
|
---|
| 427 | DelayedChangeMixin, TemplateMessageMixin):
|
---|
| 428 | """Base for generic state change loggers that monitor a single value in the
|
---|
| 429 | state possibly with a delay and the logged message comes from a template"""
|
---|
[22] | 430 | def __init__(self, attrName, template, logInitial = True,
|
---|
[356] | 431 | excludedStages = None, minDelay = 0.0, maxDelay = 0.0):
|
---|
[8] | 432 | """Construct the object."""
|
---|
[358] | 433 | StateChangeLogger.__init__(self, logInitial = logInitial,
|
---|
| 434 | excludedStages = excludedStages)
|
---|
[8] | 435 | SingleValueMixin.__init__(self, attrName)
|
---|
[329] | 436 | DelayedChangeMixin.__init__(self, minDelay = minDelay,
|
---|
| 437 | maxDelay = maxDelay)
|
---|
[8] | 438 | TemplateMessageMixin.__init__(self, template)
|
---|
[324] | 439 | self._getLogTimestamp = \
|
---|
| 440 | lambda state, forced: \
|
---|
| 441 | DelayedChangeMixin._getLogTimestamp(self, state, forced)
|
---|
[8] | 442 |
|
---|
| 443 | #---------------------------------------------------------------------------------------
|
---|
| 444 |
|
---|
[321] | 445 | class ForceableLoggerMixin(object):
|
---|
[355] | 446 | """A mixin for loggers that can be forced to log a certain state."""
|
---|
[321] | 447 | def forceLog(self, flight, logger, state):
|
---|
| 448 | """Force logging the given state."""
|
---|
| 449 | self.logState(flight, logger, state, forced = True)
|
---|
| 450 |
|
---|
| 451 | #---------------------------------------------------------------------------------------
|
---|
| 452 |
|
---|
[8] | 453 | class AltimeterLogger(StateChangeLogger, SingleValueMixin,
|
---|
| 454 | DelayedChangeMixin):
|
---|
| 455 | """Logger for the altimeter setting."""
|
---|
| 456 | def __init__(self):
|
---|
| 457 | """Construct the logger."""
|
---|
| 458 | StateChangeLogger.__init__(self, logInitial = True)
|
---|
| 459 | SingleValueMixin.__init__(self, "altimeter")
|
---|
| 460 | DelayedChangeMixin.__init__(self)
|
---|
[324] | 461 | self._getLogTimestamp = \
|
---|
| 462 | lambda state, forced: \
|
---|
| 463 | DelayedChangeMixin._getLogTimestamp(self, state, forced)
|
---|
[8] | 464 |
|
---|
[321] | 465 | def _getMessage(self, flight, state, forced):
|
---|
[8] | 466 | """Get the message to log on a change."""
|
---|
[22] | 467 | logState = self._lastChangeState if \
|
---|
| 468 | self._lastChangeState is not None else state
|
---|
[409] | 469 | message = "Altimeter: %.2f hPa at %.0f feet" % \
|
---|
[394] | 470 | (logState.altimeter, logState.altitude)
|
---|
| 471 | if not logState.altimeterReliable:
|
---|
| 472 | message += " (u/r)"
|
---|
| 473 | return message
|
---|
[8] | 474 |
|
---|
| 475 | #---------------------------------------------------------------------------------------
|
---|
| 476 |
|
---|
[321] | 477 | class NAVLogger(StateChangeLogger, DelayedChangeMixin, ForceableLoggerMixin):
|
---|
[320] | 478 | """Logger for NAV radios.
|
---|
| 479 |
|
---|
[355] | 480 | It also logs the OBS radial set."""
|
---|
[356] | 481 | excludedStages = [const.STAGE_BOARDING, const.STAGE_PUSHANDTAXI,
|
---|
| 482 | const.STAGE_RTO, const.STAGE_TAXIAFTERLAND,
|
---|
| 483 | const.STAGE_PARKING]
|
---|
| 484 |
|
---|
[321] | 485 | @staticmethod
|
---|
| 486 | def getMessage(logName, frequency, obs):
|
---|
| 487 | """Get the message for the given NAV radio setting."""
|
---|
[389] | 488 | message = u"%-5s %s" % (logName + ":", frequency)
|
---|
[363] | 489 | if obs is not None: message += u" (%03d\u00b0)" % (obs,)
|
---|
[321] | 490 | return message
|
---|
[332] | 491 |
|
---|
[320] | 492 | def __init__(self, attrName, logName):
|
---|
| 493 | """Construct the NAV logger."""
|
---|
[356] | 494 | StateChangeLogger.__init__(self, logInitial = False,
|
---|
| 495 | excludedStages = self.excludedStages)
|
---|
[320] | 496 | DelayedChangeMixin.__init__(self)
|
---|
[321] | 497 |
|
---|
| 498 | self._getLogTimestamp = \
|
---|
[324] | 499 | lambda state, forced: \
|
---|
| 500 | DelayedChangeMixin._getLogTimestamp(self, state, forced)
|
---|
[320] | 501 |
|
---|
| 502 | self._attrName = attrName
|
---|
| 503 | self._logName = logName
|
---|
[321] | 504 |
|
---|
[320] | 505 | def _getValue(self, state):
|
---|
| 506 | """Get the value.
|
---|
| 507 |
|
---|
| 508 | If both the frequency and the obs settings are available, a tuple
|
---|
| 509 | containing them is returned, otherwise None."""
|
---|
| 510 | frequency = getattr(state, self._attrName)
|
---|
| 511 | obs = getattr(state, self._attrName + "_obs")
|
---|
[321] | 512 | manual = getattr(state, self._attrName + "_manual")
|
---|
| 513 | return (frequency, obs, manual)
|
---|
[320] | 514 |
|
---|
[321] | 515 | def _getMessage(self, flight, state, forced):
|
---|
[320] | 516 | """Get the message."""
|
---|
[321] | 517 | (frequency, obs, manual) = self._getValue(state)
|
---|
| 518 | return None if frequency is None or obs is None or \
|
---|
| 519 | (not manual and not forced) else \
|
---|
| 520 | self.getMessage(self._logName, frequency, obs)
|
---|
| 521 |
|
---|
| 522 | def _isDifferent(self, oldValue, newValue):
|
---|
| 523 | """Determine if the valie has changed between the given states."""
|
---|
| 524 | (oldFrequency, oldOBS, _oldManual) = oldValue
|
---|
| 525 | (newFrequency, newOBS, _newManual) = newValue
|
---|
| 526 | return oldFrequency!=newFrequency or oldOBS!=newOBS
|
---|
[320] | 527 |
|
---|
| 528 | #---------------------------------------------------------------------------------------
|
---|
| 529 |
|
---|
[366] | 530 | class ILSLogger(NAVLogger):
|
---|
| 531 | """Logger for the ILS radio setting."""
|
---|
| 532 | def __init__(self):
|
---|
| 533 | """Construct the logger."""
|
---|
| 534 | super(ILSLogger, self).__init__("ils", "ILS")
|
---|
| 535 |
|
---|
| 536 | #---------------------------------------------------------------------------------------
|
---|
| 537 |
|
---|
[320] | 538 | class NAV1Logger(NAVLogger):
|
---|
[8] | 539 | """Logger for the NAV1 radio setting."""
|
---|
| 540 | def __init__(self):
|
---|
| 541 | """Construct the logger."""
|
---|
[320] | 542 | super(NAV1Logger, self).__init__("nav1", "NAV1")
|
---|
[8] | 543 |
|
---|
| 544 | #---------------------------------------------------------------------------------------
|
---|
| 545 |
|
---|
[320] | 546 | class NAV2Logger(NAVLogger):
|
---|
[8] | 547 | """Logger for the NAV2 radio setting."""
|
---|
| 548 | def __init__(self):
|
---|
| 549 | """Construct the logger."""
|
---|
[320] | 550 | super(NAV2Logger, self).__init__("nav2", "NAV2")
|
---|
[8] | 551 |
|
---|
| 552 | #---------------------------------------------------------------------------------------
|
---|
| 553 |
|
---|
[321] | 554 | class ADFLogger(GenericStateChangeLogger, ForceableLoggerMixin):
|
---|
| 555 | """Base class for the ADF loggers."""
|
---|
| 556 | def __init__(self, attr, logName):
|
---|
| 557 | """Construct the ADF logger."""
|
---|
| 558 | GenericStateChangeLogger.__init__(self, attr,
|
---|
[333] | 559 | "%s: %%s" % (logName,),
|
---|
[356] | 560 | logInitial = False,
|
---|
| 561 | excludedStages =
|
---|
| 562 | NAVLogger.excludedStages,
|
---|
[321] | 563 | minDelay = 3.0, maxDelay = 10.0)
|
---|
| 564 |
|
---|
| 565 | #---------------------------------------------------------------------------------------
|
---|
| 566 |
|
---|
| 567 | class ADF1Logger(ADFLogger):
|
---|
[317] | 568 | """Logger for the ADF1 radio setting."""
|
---|
| 569 | def __init__(self):
|
---|
| 570 | """Construct the logger."""
|
---|
[321] | 571 | super(ADF1Logger, self).__init__("adf1", "ADF1")
|
---|
[317] | 572 |
|
---|
| 573 | #---------------------------------------------------------------------------------------
|
---|
| 574 |
|
---|
[321] | 575 | class ADF2Logger(ADFLogger):
|
---|
[317] | 576 | """Logger for the ADF2 radio setting."""
|
---|
| 577 | def __init__(self):
|
---|
| 578 | """Construct the logger."""
|
---|
[321] | 579 | super(ADF2Logger, self).__init__("adf2", "ADF2")
|
---|
[317] | 580 |
|
---|
| 581 | #---------------------------------------------------------------------------------------
|
---|
| 582 |
|
---|
[8] | 583 | class SquawkLogger(GenericStateChangeLogger):
|
---|
| 584 | """Logger for the squawk setting."""
|
---|
| 585 | def __init__(self):
|
---|
| 586 | """Construct the logger."""
|
---|
| 587 | super(SquawkLogger, self).__init__("squawk", "Squawk code: %s",
|
---|
[22] | 588 | minDelay = 3.0, maxDelay = 10.0)
|
---|
[8] | 589 |
|
---|
| 590 | #---------------------------------------------------------------------------------------
|
---|
| 591 |
|
---|
| 592 | class LightsLogger(StateChangeLogger, SingleValueMixin, SimpleChangeMixin):
|
---|
| 593 | """Base class for the loggers of the various lights."""
|
---|
| 594 | def __init__(self, attrName, template):
|
---|
| 595 | """Construct the logger."""
|
---|
| 596 | StateChangeLogger.__init__(self)
|
---|
| 597 | SingleValueMixin.__init__(self, attrName)
|
---|
[332] | 598 |
|
---|
[8] | 599 | self._template = template
|
---|
| 600 |
|
---|
[321] | 601 | def _getMessage(self, flight, state, forced):
|
---|
[8] | 602 | """Get the message from the given state."""
|
---|
[416] | 603 | value = self._getValue(state)
|
---|
| 604 | if value is None:
|
---|
| 605 | return None
|
---|
| 606 | else:
|
---|
| 607 | return self._template % ("ON" if value else "OFF")
|
---|
[332] | 608 |
|
---|
[8] | 609 | #---------------------------------------------------------------------------------------
|
---|
| 610 |
|
---|
| 611 | class AnticollisionLightsLogger(LightsLogger):
|
---|
| 612 | """Logger for the anti-collision lights."""
|
---|
| 613 | def __init__(self):
|
---|
| 614 | LightsLogger.__init__(self, "antiCollisionLightsOn",
|
---|
| 615 | "Anti-collision lights: %s")
|
---|
| 616 |
|
---|
| 617 | #---------------------------------------------------------------------------------------
|
---|
| 618 |
|
---|
| 619 | class LandingLightsLogger(LightsLogger):
|
---|
| 620 | """Logger for the landing lights."""
|
---|
| 621 | def __init__(self):
|
---|
| 622 | LightsLogger.__init__(self, "landingLightsOn",
|
---|
| 623 | "Landing lights: %s")
|
---|
| 624 |
|
---|
| 625 | #---------------------------------------------------------------------------------------
|
---|
| 626 |
|
---|
| 627 | class StrobeLightsLogger(LightsLogger):
|
---|
| 628 | """Logger for the strobe lights."""
|
---|
| 629 | def __init__(self):
|
---|
| 630 | LightsLogger.__init__(self, "strobeLightsOn",
|
---|
| 631 | "Strobe lights: %s")
|
---|
| 632 |
|
---|
| 633 | #---------------------------------------------------------------------------------------
|
---|
| 634 |
|
---|
| 635 | class NavLightsLogger(LightsLogger):
|
---|
| 636 | """Logger for the navigational lights."""
|
---|
| 637 | def __init__(self):
|
---|
| 638 | LightsLogger.__init__(self, "navLightsOn",
|
---|
| 639 | "Navigational lights: %s")
|
---|
| 640 |
|
---|
| 641 | #---------------------------------------------------------------------------------------
|
---|
| 642 |
|
---|
| 643 | class FlapsLogger(StateChangeLogger, SingleValueMixin, SimpleChangeMixin):
|
---|
| 644 | """Logger for the flaps setting."""
|
---|
| 645 | def __init__(self):
|
---|
| 646 | """Construct the logger."""
|
---|
[364] | 647 | StateChangeLogger.__init__(self, logInitial = True,
|
---|
| 648 | excludedStages =
|
---|
| 649 | [const.STAGE_BOARDING,
|
---|
| 650 | const.STAGE_PUSHANDTAXI,
|
---|
| 651 | const.STAGE_RTO,
|
---|
| 652 | const.STAGE_TAKEOFF])
|
---|
[8] | 653 | SingleValueMixin.__init__(self, "flapsSet")
|
---|
| 654 |
|
---|
[321] | 655 | def _getMessage(self, flight, state, forced):
|
---|
[8] | 656 | """Get the message to log on a change."""
|
---|
| 657 | speed = state.groundSpeed if state.groundSpeed<80.0 else state.ias
|
---|
[333] | 658 | return "Flaps %.0f - %.0f %s" % \
|
---|
[241] | 659 | (state.flapsSet, flight.speedFromKnots(speed),
|
---|
| 660 | flight.getEnglishSpeedUnit())
|
---|
[8] | 661 |
|
---|
| 662 | #---------------------------------------------------------------------------------------
|
---|
| 663 |
|
---|
| 664 | class GearsLogger(StateChangeLogger, SingleValueMixin, SimpleChangeMixin):
|
---|
| 665 | """Logger for the gears state."""
|
---|
| 666 | def __init__(self):
|
---|
| 667 | """Construct the logger."""
|
---|
| 668 | StateChangeLogger.__init__(self, logInitial = True)
|
---|
[209] | 669 | SingleValueMixin.__init__(self, "gearControlDown")
|
---|
[8] | 670 |
|
---|
[321] | 671 | def _getMessage(self, flight, state, forced):
|
---|
[8] | 672 | """Get the message to log on a change."""
|
---|
[241] | 673 | return "Gears SET to %s at %.0f %s, %.0f feet" % \
|
---|
[209] | 674 | ("DOWN" if state.gearControlDown else "UP",
|
---|
[241] | 675 | flight.speedFromKnots(state.ias),
|
---|
| 676 | flight.getEnglishSpeedUnit(), state.altitude)
|
---|
[8] | 677 |
|
---|
| 678 | #---------------------------------------------------------------------------------------
|
---|
[11] | 679 |
|
---|
[338] | 680 | class APLogger(StateChangeLogger, DelayedChangeMixin):
|
---|
| 681 | """Log the state of the autopilot."""
|
---|
| 682 | @staticmethod
|
---|
| 683 | def _logBoolean(logger, timestamp, what, value):
|
---|
| 684 | """Log a boolean value.
|
---|
| 685 |
|
---|
| 686 | what is the name of the value that is being logged."""
|
---|
| 687 | message = what + " "
|
---|
| 688 | if value is None:
|
---|
| 689 | message += "cannot be detected, will not log"
|
---|
| 690 | else:
|
---|
| 691 | message += "is " + ("ON" if value else "OFF")
|
---|
| 692 | logger.message(timestamp, message)
|
---|
| 693 |
|
---|
| 694 | @staticmethod
|
---|
| 695 | def _logNumeric(logger, timestamp, what, format, value):
|
---|
| 696 | """Log a numerical value."""
|
---|
| 697 | message = what
|
---|
| 698 | if value is None:
|
---|
| 699 | message += u" cannot be detected, will not log"
|
---|
| 700 | else:
|
---|
| 701 | message += u": " + format % (value,)
|
---|
| 702 | logger.message(timestamp, message)
|
---|
| 703 |
|
---|
| 704 | @staticmethod
|
---|
| 705 | def _logAPMaster(logger, timestamp, state):
|
---|
| 706 | """Log the AP master state."""
|
---|
| 707 | APLogger._logBoolean(logger, timestamp, "AP master",
|
---|
| 708 | state.apMaster)
|
---|
| 709 |
|
---|
| 710 | @staticmethod
|
---|
| 711 | def _logAPHeadingHold(logger, timestamp, state):
|
---|
| 712 | """Log the AP heading hold state."""
|
---|
| 713 | APLogger._logBoolean(logger, timestamp, "AP heading hold",
|
---|
| 714 | state.apHeadingHold)
|
---|
| 715 |
|
---|
| 716 | @staticmethod
|
---|
| 717 | def _logAPHeading(logger, timestamp, state):
|
---|
| 718 | """Log the AP heading."""
|
---|
| 719 | APLogger._logNumeric(logger, timestamp, u"AP heading",
|
---|
| 720 | u"%03.0f\u00b0", state.apHeading)
|
---|
| 721 |
|
---|
| 722 | @staticmethod
|
---|
| 723 | def _logAPAltitudeHold(logger, timestamp, state):
|
---|
| 724 | """Log the AP altitude hold state."""
|
---|
| 725 | APLogger._logBoolean(logger, timestamp, "AP altitude hold",
|
---|
| 726 | state.apAltitudeHold)
|
---|
| 727 |
|
---|
| 728 | @staticmethod
|
---|
| 729 | def _logAPAltitude(logger, timestamp, state):
|
---|
| 730 | """Log the AP heading."""
|
---|
| 731 | APLogger._logNumeric(logger, timestamp, u"AP altitude",
|
---|
| 732 | u"%.0f ft", state.apAltitude)
|
---|
| 733 |
|
---|
| 734 | def __init__(self):
|
---|
| 735 | """Construct the state logger."""
|
---|
| 736 | StateChangeLogger.__init__(self)
|
---|
| 737 | DelayedChangeMixin.__init__(self)
|
---|
| 738 | self._lastLoggedState = None
|
---|
[355] | 739 | self.logState = lambda flight, logger, state:\
|
---|
| 740 | APLogger.logState(self, flight, logger, state)
|
---|
[338] | 741 |
|
---|
| 742 | def _getValue(self, state):
|
---|
| 743 | """Convert the relevant values from the given state into a tuple."""
|
---|
| 744 | return (state.apMaster,
|
---|
| 745 | state.apHeadingHold, state.apHeading,
|
---|
| 746 | state.apAltitudeHold, state.apAltitude)
|
---|
| 747 |
|
---|
| 748 | def _isDifferent(self, oldValue, newValue):
|
---|
| 749 | """Determine if the given old and new values are different (enough) to
|
---|
| 750 | be logged."""
|
---|
| 751 | (oldAPMaster, oldAPHeadingHold, oldAPHeading,
|
---|
| 752 | oldAPAltitudeHold, oldAPAltitude) = oldValue
|
---|
| 753 | (apMaster, apHeadingHold, apHeading,
|
---|
| 754 | apAltitudeHold, apAltitude) = newValue
|
---|
| 755 |
|
---|
| 756 | if apMaster is not None and apMaster!=oldAPMaster:
|
---|
| 757 | return True
|
---|
| 758 | if apMaster is False:
|
---|
| 759 | return False
|
---|
| 760 |
|
---|
| 761 | if apHeadingHold is not None and apHeadingHold!=oldAPHeadingHold:
|
---|
| 762 | return True
|
---|
| 763 | if apHeadingHold is not False and apHeading is not None and \
|
---|
| 764 | apHeading!=oldAPHeading:
|
---|
| 765 | return True
|
---|
| 766 |
|
---|
| 767 | if apAltitudeHold is not None and apAltitudeHold!=oldAPAltitudeHold:
|
---|
| 768 | return True
|
---|
| 769 | if apAltitudeHold is not False and apAltitude is not None and \
|
---|
| 770 | apAltitude!=oldAPAltitude:
|
---|
| 771 | return True
|
---|
| 772 |
|
---|
| 773 | return False
|
---|
| 774 |
|
---|
| 775 | def logState(self, flight, logger, state):
|
---|
| 776 | """Log the autopilot state."""
|
---|
| 777 | timestamp = DelayedChangeMixin._getLogTimestamp(self, state, False)
|
---|
| 778 | if self._lastLoggedState is None:
|
---|
| 779 | self._logAPMaster(logger, timestamp, state)
|
---|
| 780 | if state.apMaster is not False or state.apHeadingHold is None:
|
---|
| 781 | self._logAPHeadingHold(logger, timestamp, state)
|
---|
| 782 | if state.apMaster is not False and \
|
---|
| 783 | (state.apHeadingHold is not False or state.apHeading is None):
|
---|
| 784 | self._logAPHeading(logger, timestamp, state)
|
---|
| 785 | if state.apMaster is not False or state.apAltitudeHold is None:
|
---|
| 786 | self._logAPAltitudeHold(logger, timestamp, state)
|
---|
| 787 | if state.apMaster is not False and \
|
---|
| 788 | (state.apAltitudeHold is not False or state.apAltitude is None):
|
---|
| 789 | self._logAPAltitude(logger, timestamp, state)
|
---|
| 790 | self._firstCall = False
|
---|
| 791 | else:
|
---|
| 792 | oldState = self._lastLoggedState
|
---|
| 793 |
|
---|
| 794 | apMasterTurnedOn = False
|
---|
| 795 | if state.apMaster is not None and state.apMaster!=oldState.apMaster:
|
---|
| 796 | apMasterTurnedOn = state.apMaster
|
---|
| 797 | self._logAPMaster(logger, timestamp, state)
|
---|
| 798 |
|
---|
| 799 | if state.apMaster is not False:
|
---|
| 800 | apHeadingHoldTurnedOn = False
|
---|
| 801 | if state.apHeadingHold is not None and \
|
---|
| 802 | (state.apHeadingHold!=oldState.apHeadingHold or
|
---|
| 803 | apMasterTurnedOn):
|
---|
| 804 | apHeadingHoldTurnedOn = state.apHeadingHold
|
---|
| 805 | self._logAPHeadingHold(logger, timestamp, state)
|
---|
| 806 |
|
---|
| 807 | if state.apHeadingHold is not False and \
|
---|
| 808 | state.apHeading is not None and \
|
---|
| 809 | (state.apHeading!=oldState.apHeading or apMasterTurnedOn or
|
---|
| 810 | apHeadingHoldTurnedOn):
|
---|
| 811 | self._logAPHeading(logger, timestamp, state)
|
---|
| 812 |
|
---|
| 813 | apAltitudeHoldTurnedOn = False
|
---|
| 814 | if state.apAltitudeHold is not None and \
|
---|
| 815 | (state.apAltitudeHold!=oldState.apAltitudeHold or
|
---|
| 816 | apMasterTurnedOn):
|
---|
| 817 | apAltitudeHoldTurnedOn = state.apAltitudeHold
|
---|
| 818 | self._logAPAltitudeHold(logger, timestamp, state)
|
---|
| 819 |
|
---|
| 820 | if state.apAltitudeHold is not False and \
|
---|
| 821 | state.apAltitude is not None and \
|
---|
| 822 | (state.apAltitude!=oldState.apAltitude or apMasterTurnedOn or
|
---|
| 823 | apAltitudeHoldTurnedOn):
|
---|
| 824 | self._logAPAltitude(logger, timestamp, state)
|
---|
| 825 |
|
---|
| 826 | self._lastLoggedState = state
|
---|
| 827 |
|
---|
| 828 | #---------------------------------------------------------------------------------------
|
---|
| 829 |
|
---|
[11] | 830 | class FaultChecker(StateChecker):
|
---|
| 831 | """Base class for checkers that look for faults."""
|
---|
| 832 | @staticmethod
|
---|
| 833 | def _appendDuring(flight, message):
|
---|
| 834 | """Append a 'during XXX' test to the given message, depending on the
|
---|
| 835 | flight stage."""
|
---|
| 836 | stageStr = const.stage2string(flight.stage)
|
---|
| 837 | return message if stageStr is None \
|
---|
| 838 | else (message + " during " + stageStr.upper())
|
---|
| 839 |
|
---|
| 840 | @staticmethod
|
---|
| 841 | def _getLinearScore(minFaultValue, maxFaultValue, minScore, maxScore,
|
---|
| 842 | value):
|
---|
| 843 | """Get the score for a faulty value where the score is calculated
|
---|
| 844 | linearly within a certain range."""
|
---|
| 845 | if value<minFaultValue:
|
---|
| 846 | return 0
|
---|
| 847 | elif value>maxFaultValue:
|
---|
| 848 | return maxScore
|
---|
| 849 | else:
|
---|
| 850 | return minScore + (maxScore-minScore) * (value-minFaultValue) / \
|
---|
| 851 | (maxFaultValue - minFaultValue)
|
---|
| 852 |
|
---|
| 853 | #---------------------------------------------------------------------------------------
|
---|
| 854 |
|
---|
| 855 | class SimpleFaultChecker(FaultChecker):
|
---|
| 856 | """Base class for fault checkers that check for a single occurence of a
|
---|
| 857 | faulty condition.
|
---|
| 858 |
|
---|
| 859 | Child classes should implement the following functions:
|
---|
| 860 | - isCondition(self, flight, aircraft, oldState, state): should return whether the
|
---|
| 861 | condition holds
|
---|
| 862 | - logFault(self, flight, aircraft, logger, oldState, state): log the fault
|
---|
| 863 | via the logger."""
|
---|
| 864 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 865 | """Perform the check."""
|
---|
| 866 | if self.isCondition(flight, aircraft, oldState, state):
|
---|
| 867 | self.logFault(flight, aircraft, logger, oldState, state)
|
---|
| 868 |
|
---|
| 869 | #---------------------------------------------------------------------------------------
|
---|
| 870 |
|
---|
| 871 | class PatientFaultChecker(FaultChecker):
|
---|
| 872 | """A fault checker that does not decides on a fault when the condition
|
---|
| 873 | arises immediately, but can wait some time.
|
---|
| 874 |
|
---|
| 875 | Child classes should implement the following functions:
|
---|
| 876 | - isCondition(self, flight, aircraft, oldState, state): should return whether the
|
---|
| 877 | condition holds
|
---|
| 878 | - logFault(self, flight, aircraft, logger, oldState, state): log the fault
|
---|
| 879 | via the logger
|
---|
| 880 | """
|
---|
| 881 | def __init__(self, timeout = 2.0):
|
---|
| 882 | """Construct the fault checker with the given timeout."""
|
---|
| 883 | self._timeout = timeout
|
---|
| 884 | self._faultStarted = None
|
---|
| 885 |
|
---|
| 886 | def getTimeout(self, flight, aircraft, oldState, state):
|
---|
| 887 | """Get the timeout.
|
---|
| 888 |
|
---|
| 889 | This default implementation returns the timeout given in the
|
---|
| 890 | constructor, but child classes might want to enforce a different
|
---|
| 891 | policy."""
|
---|
| 892 | return self._timeout
|
---|
| 893 |
|
---|
| 894 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 895 | """Perform the check."""
|
---|
| 896 | if self.isCondition(flight, aircraft, oldState, state):
|
---|
| 897 | if self._faultStarted is None:
|
---|
| 898 | self._faultStarted = state.timestamp
|
---|
| 899 | timeout = self.getTimeout(flight, aircraft, oldState, state)
|
---|
| 900 | if state.timestamp>=(self._faultStarted + timeout):
|
---|
| 901 | self.logFault(flight, aircraft, logger, oldState, state)
|
---|
| 902 | self._faultStarted = state.timestamp
|
---|
| 903 | else:
|
---|
| 904 | self._faultStarted = None
|
---|
[332] | 905 |
|
---|
[11] | 906 | #---------------------------------------------------------------------------------------
|
---|
| 907 |
|
---|
| 908 | class AntiCollisionLightsChecker(PatientFaultChecker):
|
---|
| 909 | """Check for the anti-collision light being off at high N1 values."""
|
---|
| 910 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 911 | """Check if the fault condition holds."""
|
---|
| 912 | return (flight.stage!=const.STAGE_PARKING or \
|
---|
[183] | 913 | not flight.config.usingFS2Crew) and \
|
---|
[11] | 914 | not state.antiCollisionLightsOn and \
|
---|
[211] | 915 | self.isEngineCondition(state)
|
---|
[11] | 916 |
|
---|
| 917 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 918 | """Log the fault."""
|
---|
[30] | 919 | flight.handleFault(AntiCollisionLightsChecker, state.timestamp,
|
---|
| 920 | FaultChecker._appendDuring(flight,
|
---|
| 921 | "Anti-collision lights were off"),
|
---|
| 922 | 1)
|
---|
[11] | 923 |
|
---|
[211] | 924 | def isEngineCondition(self, state):
|
---|
| 925 | """Determine if the engines are in such a state that the lights should
|
---|
| 926 | be on."""
|
---|
[263] | 927 | if state.n1 is not None:
|
---|
| 928 | return max(state.n1)>5
|
---|
| 929 | elif state.rpm is not None:
|
---|
| 930 | return max(state.rpm)>0
|
---|
| 931 | else:
|
---|
| 932 | return False
|
---|
[211] | 933 |
|
---|
| 934 | #---------------------------------------------------------------------------------------
|
---|
| 935 |
|
---|
| 936 | class TupolevAntiCollisionLightsChecker(AntiCollisionLightsChecker):
|
---|
| 937 | """Check for the anti-collision light for Tuplev planes."""
|
---|
[307] | 938 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
[332] | 939 | """Check if the fault condition holds."""
|
---|
[307] | 940 | numEnginesRunning = 0
|
---|
| 941 | for n1 in state.n1:
|
---|
| 942 | if n1>5: numEnginesRunning += 1
|
---|
[332] | 943 |
|
---|
[452] | 944 | if flight.stage==const.STAGE_PARKING or \
|
---|
| 945 | (flight.stage==const.STAGE_TAXIAFTERLAND and state.parking):
|
---|
[307] | 946 | return numEnginesRunning<len(state.n1) \
|
---|
| 947 | and state.antiCollisionLightsOn
|
---|
| 948 | else:
|
---|
| 949 | return numEnginesRunning>1 and not state.antiCollisionLightsOn or \
|
---|
| 950 | numEnginesRunning<1 and state.antiCollisionLightsOn
|
---|
[211] | 951 |
|
---|
[11] | 952 | #---------------------------------------------------------------------------------------
|
---|
| 953 |
|
---|
| 954 | class BankChecker(SimpleFaultChecker):
|
---|
[263] | 955 | """Check for the bank is within limits."""
|
---|
[11] | 956 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 957 | """Check if the fault condition holds."""
|
---|
| 958 | if flight.stage==const.STAGE_CRUISE:
|
---|
| 959 | bankLimit = 30
|
---|
| 960 | elif flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
|
---|
| 961 | const.STAGE_DESCENT, const.STAGE_LANDING]:
|
---|
| 962 | bankLimit = 35
|
---|
| 963 | else:
|
---|
| 964 | return False
|
---|
| 965 |
|
---|
| 966 | return state.bank>bankLimit or state.bank<-bankLimit
|
---|
| 967 |
|
---|
| 968 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 969 | """Log the fault."""
|
---|
[30] | 970 | flight.handleFault(BankChecker, state.timestamp,
|
---|
| 971 | FaultChecker._appendDuring(flight, "Bank too steep"),
|
---|
| 972 | 2)
|
---|
[11] | 973 |
|
---|
| 974 | #---------------------------------------------------------------------------------------
|
---|
| 975 |
|
---|
| 976 | class FlapsRetractChecker(SimpleFaultChecker):
|
---|
| 977 | """Check if the flaps are not retracted too early."""
|
---|
[13] | 978 | def __init__(self):
|
---|
| 979 | """Construct the flaps checker."""
|
---|
| 980 | self._timeStart = None
|
---|
[332] | 981 |
|
---|
[11] | 982 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 983 | """Check if the fault condition holds.
|
---|
| 984 |
|
---|
| 985 | FIXME: check if this really is the intention (FlapsRetractedMistake.java)"""
|
---|
[357] | 986 | if (flight.stage==const.STAGE_TAKEOFF and not state.onTheGround and
|
---|
| 987 | aircraft.type!=const.AIRCRAFT_F70) or \
|
---|
[11] | 988 | (flight.stage==const.STAGE_LANDING and state.onTheGround):
|
---|
| 989 | if self._timeStart is None:
|
---|
| 990 | self._timeStart = state.timestamp
|
---|
| 991 |
|
---|
| 992 | if state.flapsSet==0 and state.timestamp<=(self._timeStart+2.0):
|
---|
| 993 | return True
|
---|
[13] | 994 | else:
|
---|
| 995 | self._timeStart = None
|
---|
[11] | 996 | return False
|
---|
| 997 |
|
---|
| 998 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 999 | """Log the fault."""
|
---|
[30] | 1000 | flight.handleFault(FlapsRetractChecker, state.timestamp,
|
---|
| 1001 | FaultChecker._appendDuring(flight, "Flaps retracted"),
|
---|
| 1002 | 20)
|
---|
[11] | 1003 |
|
---|
| 1004 | #---------------------------------------------------------------------------------------
|
---|
| 1005 |
|
---|
| 1006 | class FlapsSpeedLimitChecker(SimpleFaultChecker):
|
---|
| 1007 | """Check if the flaps are extended only at the right speeds."""
|
---|
| 1008 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1009 | """Check if the fault condition holds."""
|
---|
| 1010 | speedLimit = aircraft.getFlapsSpeedLimit(state.flapsSet)
|
---|
[197] | 1011 | return speedLimit is not None and state.smoothedIAS>speedLimit
|
---|
[11] | 1012 |
|
---|
| 1013 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1014 | """Log the fault."""
|
---|
[30] | 1015 | flight.handleFault(FlapsSpeedLimitChecker, state.timestamp,
|
---|
| 1016 | FaultChecker._appendDuring(flight, "Flap speed limit fault"),
|
---|
| 1017 | 5)
|
---|
[11] | 1018 |
|
---|
| 1019 | #---------------------------------------------------------------------------------------
|
---|
| 1020 |
|
---|
| 1021 | class GearsDownChecker(SimpleFaultChecker):
|
---|
| 1022 | """Check if the gears are down at low altitudes."""
|
---|
| 1023 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1024 | """Check if the fault condition holds."""
|
---|
| 1025 | return state.radioAltitude<10 and not state.gearsDown and \
|
---|
| 1026 | flight.stage!=const.STAGE_TAKEOFF
|
---|
| 1027 |
|
---|
| 1028 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1029 | """Log the fault."""
|
---|
[30] | 1030 | flight.handleNoGo(GearsDownChecker, state.timestamp,
|
---|
| 1031 | "Gears not down at %.0f feet radio altitude" % \
|
---|
| 1032 | (state.radioAltitude,),
|
---|
| 1033 | "GEAR DOWN NO GO")
|
---|
[11] | 1034 |
|
---|
| 1035 | #---------------------------------------------------------------------------------------
|
---|
| 1036 |
|
---|
| 1037 | class GearSpeedLimitChecker(PatientFaultChecker):
|
---|
| 1038 | """Check if the gears not down at too high a speed."""
|
---|
| 1039 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1040 | """Check if the fault condition holds."""
|
---|
[197] | 1041 | return state.gearsDown and state.smoothedIAS>aircraft.gearSpeedLimit
|
---|
[11] | 1042 |
|
---|
| 1043 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1044 | """Log the fault."""
|
---|
[30] | 1045 | flight.handleFault(GearSpeedLimitChecker, state.timestamp,
|
---|
| 1046 | FaultChecker._appendDuring(flight, "Gear speed limit fault"),
|
---|
| 1047 | 5)
|
---|
[11] | 1048 |
|
---|
| 1049 | #---------------------------------------------------------------------------------------
|
---|
| 1050 |
|
---|
| 1051 | class GLoadChecker(SimpleFaultChecker):
|
---|
| 1052 | """Check if the G-load does not exceed 2 except during flare."""
|
---|
| 1053 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1054 | """Check if the fault condition holds."""
|
---|
[448] | 1055 | return state.gLoad>2.0 and not state.onTheGround and \
|
---|
| 1056 | (flight.stage!=const.STAGE_LANDING or state.radioAltitude>=50)
|
---|
[332] | 1057 |
|
---|
[11] | 1058 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1059 | """Log the fault."""
|
---|
[30] | 1060 | flight.handleFault(GLoadChecker, state.timestamp,
|
---|
| 1061 | "G-load was %.2f" % (state.gLoad,),
|
---|
| 1062 | 10)
|
---|
[11] | 1063 |
|
---|
| 1064 | #---------------------------------------------------------------------------------------
|
---|
| 1065 |
|
---|
| 1066 | class LandingLightsChecker(PatientFaultChecker):
|
---|
| 1067 | """Check if the landing lights are used properly."""
|
---|
| 1068 | def getTimeout(self, flight, aircraft, oldState, state):
|
---|
| 1069 | """Get the timeout.
|
---|
| 1070 |
|
---|
| 1071 | It is the default timeout except for landing and takeoff."""
|
---|
| 1072 | return 0.0 if flight.stage in [const.STAGE_TAKEOFF,
|
---|
| 1073 | const.STAGE_LANDING] else self._timeout
|
---|
| 1074 |
|
---|
| 1075 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1076 | """Check if the fault condition holds."""
|
---|
[314] | 1077 | return state.landingLightsOn is not None and \
|
---|
| 1078 | ((flight.stage==const.STAGE_BOARDING and \
|
---|
| 1079 | state.landingLightsOn and state.onTheGround) or \
|
---|
| 1080 | (flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 1081 | not state.landingLightsOn and not state.onTheGround) or \
|
---|
| 1082 | (flight.stage in [const.STAGE_CLIMB, const.STAGE_CRUISE,
|
---|
| 1083 | const.STAGE_DESCENT] and \
|
---|
| 1084 | state.landingLightsOn and state.altitude>12500) or \
|
---|
| 1085 | (flight.stage==const.STAGE_LANDING and \
|
---|
[415] | 1086 | not state.landingLightsOn and state.onTheGround and
|
---|
| 1087 | state.groundSpeed>50.0) or \
|
---|
[314] | 1088 | (flight.stage==const.STAGE_PARKING and \
|
---|
| 1089 | state.landingLightsOn and state.onTheGround))
|
---|
[332] | 1090 |
|
---|
[11] | 1091 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1092 | """Log the fault."""
|
---|
[375] | 1093 | score = 0 if flight.stage in [const.STAGE_TAKEOFF,
|
---|
| 1094 | const.STAGE_LANDING] else 1
|
---|
[335] | 1095 | message = "Landing lights were %s" % \
|
---|
| 1096 | (("on" if state.landingLightsOn else "off"),)
|
---|
[30] | 1097 | flight.handleFault(LandingLightsChecker, state.timestamp,
|
---|
| 1098 | FaultChecker._appendDuring(flight, message),
|
---|
[332] | 1099 | score)
|
---|
[11] | 1100 |
|
---|
| 1101 | #---------------------------------------------------------------------------------------
|
---|
| 1102 |
|
---|
[335] | 1103 | class TransponderChecker(PatientFaultChecker):
|
---|
| 1104 | """Check if the transponder is used properly."""
|
---|
[361] | 1105 | def __init__(self):
|
---|
| 1106 | """Construct the transponder checker."""
|
---|
| 1107 | super(TransponderChecker, self).__init__()
|
---|
| 1108 | self._liftOffTime = None
|
---|
| 1109 |
|
---|
[335] | 1110 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1111 | """Check if the fault condition holds."""
|
---|
[361] | 1112 | if state.onTheGround:
|
---|
| 1113 | self._liftOffTime = None
|
---|
| 1114 | elif self._liftOffTime is None:
|
---|
| 1115 | self._liftOffTime = state.timestamp
|
---|
| 1116 |
|
---|
[335] | 1117 | return state.xpdrC is not None and \
|
---|
| 1118 | ((state.xpdrC and flight.stage in
|
---|
| 1119 | [const.STAGE_BOARDING, const.STAGE_PARKING]) or \
|
---|
[361] | 1120 | (not state.xpdrC and
|
---|
| 1121 | (flight.stage in
|
---|
| 1122 | [const.STAGE_CRUISE, const.STAGE_DESCENT,
|
---|
[446] | 1123 | const.STAGE_GOAROUND] or \
|
---|
| 1124 | (flight.stage==const.STAGE_LANDING and
|
---|
| 1125 | state.groundSpeed>50.0) or \
|
---|
[361] | 1126 | ((not state.autoXPDR or \
|
---|
| 1127 | (self._liftOffTime is not None and
|
---|
| 1128 | state.timestamp > (self._liftOffTime+8))) and \
|
---|
| 1129 | flight.stage in
|
---|
| 1130 | [const.STAGE_TAKEOFF, const.STAGE_RTO, const.STAGE_CLIMB])
|
---|
| 1131 | )
|
---|
| 1132 | )
|
---|
| 1133 | )
|
---|
[335] | 1134 |
|
---|
| 1135 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1136 | """Log the fault."""
|
---|
| 1137 | score = 0
|
---|
| 1138 | message = "Transponder was %s" % \
|
---|
| 1139 | (("mode C" if state.xpdrC else "standby"),)
|
---|
| 1140 | flight.handleFault(TransponderChecker, state.timestamp,
|
---|
| 1141 | FaultChecker._appendDuring(flight, message),
|
---|
| 1142 | score)
|
---|
| 1143 |
|
---|
| 1144 | #---------------------------------------------------------------------------------------
|
---|
| 1145 |
|
---|
[11] | 1146 | class WeightChecker(PatientFaultChecker):
|
---|
| 1147 | """Base class for checkers that check that some limit is not exceeded."""
|
---|
| 1148 | def __init__(self, name):
|
---|
| 1149 | """Construct the checker."""
|
---|
| 1150 | super(WeightChecker, self).__init__(timeout = 5.0)
|
---|
| 1151 | self._name = name
|
---|
| 1152 |
|
---|
| 1153 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1154 | """Check if the fault condition holds."""
|
---|
| 1155 | if flight.entranceExam:
|
---|
| 1156 | return False
|
---|
| 1157 |
|
---|
| 1158 | limit = self.getLimit(flight, aircraft, state)
|
---|
| 1159 | if limit is not None:
|
---|
[183] | 1160 | #if flight.options.compensation is not None:
|
---|
| 1161 | # limit += flight.options.compensation
|
---|
[13] | 1162 | return self.getWeight(state)>limit
|
---|
[11] | 1163 |
|
---|
| 1164 | return False
|
---|
| 1165 |
|
---|
| 1166 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1167 | """Log the fault."""
|
---|
[13] | 1168 | mname = "M" + self._name
|
---|
[30] | 1169 | flight.handleNoGo(self.__class__, state.timestamp,
|
---|
| 1170 | "%s exceeded: %s is %.0f kg" % \
|
---|
| 1171 | (mname, self._name, self.getWeight(state)),
|
---|
| 1172 | "%s NO GO" % (mname,))
|
---|
[13] | 1173 |
|
---|
| 1174 | def getWeight(self, state):
|
---|
| 1175 | """Get the weight that is interesting for us."""
|
---|
| 1176 | return state.grossWeight
|
---|
[11] | 1177 |
|
---|
| 1178 | #---------------------------------------------------------------------------------------
|
---|
| 1179 |
|
---|
| 1180 | class MLWChecker(WeightChecker):
|
---|
| 1181 | """Checks if the MLW is not exceeded on landing."""
|
---|
| 1182 | def __init__(self):
|
---|
| 1183 | """Construct the checker."""
|
---|
[13] | 1184 | super(MLWChecker, self).__init__("LW")
|
---|
[11] | 1185 |
|
---|
[13] | 1186 | def getLimit(self, flight, aircraft, state):
|
---|
[11] | 1187 | """Get the limit if we are in the right state."""
|
---|
| 1188 | return aircraft.mlw if flight.stage==const.STAGE_LANDING and \
|
---|
[184] | 1189 | state.onTheGround and \
|
---|
| 1190 | not flight.entranceExam else None
|
---|
[11] | 1191 |
|
---|
| 1192 | #---------------------------------------------------------------------------------------
|
---|
| 1193 |
|
---|
| 1194 | class MTOWChecker(WeightChecker):
|
---|
| 1195 | """Checks if the MTOW is not exceeded on landing."""
|
---|
| 1196 | def __init__(self):
|
---|
| 1197 | """Construct the checker."""
|
---|
[13] | 1198 | super(MTOWChecker, self).__init__("TOW")
|
---|
[11] | 1199 |
|
---|
[13] | 1200 | def getLimit(self, flight, aircraft, state):
|
---|
[11] | 1201 | """Get the limit if we are in the right state."""
|
---|
[184] | 1202 | return aircraft.mtow if flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 1203 | not flight.entranceExam else None
|
---|
[11] | 1204 |
|
---|
| 1205 | #---------------------------------------------------------------------------------------
|
---|
| 1206 |
|
---|
| 1207 | class MZFWChecker(WeightChecker):
|
---|
[60] | 1208 | """Checks if the MZFW is not exceeded on landing."""
|
---|
[11] | 1209 | def __init__(self):
|
---|
| 1210 | """Construct the checker."""
|
---|
[13] | 1211 | super(MZFWChecker, self).__init__("ZFW")
|
---|
[11] | 1212 |
|
---|
[13] | 1213 | def getLimit(self, flight, aircraft, state):
|
---|
[11] | 1214 | """Get the limit if we are in the right state."""
|
---|
[184] | 1215 | return aircraft.mzfw if not flight.entranceExam else None
|
---|
[11] | 1216 |
|
---|
[13] | 1217 | def getWeight(self, state):
|
---|
| 1218 | """Get the weight that is interesting for us."""
|
---|
| 1219 | return state.zfw
|
---|
| 1220 |
|
---|
[11] | 1221 | #---------------------------------------------------------------------------------------
|
---|
| 1222 |
|
---|
| 1223 | class NavLightsChecker(PatientFaultChecker):
|
---|
| 1224 | """Check if the navigational lights are used properly."""
|
---|
| 1225 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1226 | """Check if the fault condition holds."""
|
---|
| 1227 | return flight.stage!=const.STAGE_BOARDING and \
|
---|
| 1228 | flight.stage!=const.STAGE_PARKING and \
|
---|
[341] | 1229 | state.navLightsOn is False
|
---|
[332] | 1230 |
|
---|
[11] | 1231 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1232 | """Log the fault."""
|
---|
[30] | 1233 | flight.handleFault(NavLightsChecker, state.timestamp,
|
---|
| 1234 | FaultChecker._appendDuring(flight,
|
---|
| 1235 | "Navigation lights were off"),
|
---|
| 1236 | 1)
|
---|
[11] | 1237 |
|
---|
| 1238 | #---------------------------------------------------------------------------------------
|
---|
| 1239 |
|
---|
| 1240 | class OverspeedChecker(PatientFaultChecker):
|
---|
| 1241 | """Check if Vne has been exceeded."""
|
---|
[447] | 1242 | def __init__(self, timeout = 30.0):
|
---|
[11] | 1243 | """Construct the checker."""
|
---|
[197] | 1244 | super(OverspeedChecker, self).__init__(timeout = timeout)
|
---|
[11] | 1245 |
|
---|
| 1246 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1247 | """Check if the fault condition holds."""
|
---|
| 1248 | return state.overspeed
|
---|
[332] | 1249 |
|
---|
[11] | 1250 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1251 | """Log the fault."""
|
---|
[30] | 1252 | flight.handleFault(OverspeedChecker, state.timestamp,
|
---|
| 1253 | FaultChecker._appendDuring(flight, "Overspeed"),
|
---|
[332] | 1254 | 20)
|
---|
[11] | 1255 |
|
---|
| 1256 | #---------------------------------------------------------------------------------------
|
---|
| 1257 |
|
---|
| 1258 | class PayloadChecker(SimpleFaultChecker):
|
---|
| 1259 | """Check if the payload matches the specification."""
|
---|
| 1260 | TOLERANCE=550
|
---|
[60] | 1261 |
|
---|
| 1262 | @staticmethod
|
---|
| 1263 | def isZFWFaulty(aircraftZFW, flightZFW):
|
---|
| 1264 | """Check if the given aircraft's ZFW is outside of the limits."""
|
---|
| 1265 | return aircraftZFW < (flightZFW - PayloadChecker.TOLERANCE) or \
|
---|
[332] | 1266 | aircraftZFW > (flightZFW + PayloadChecker.TOLERANCE)
|
---|
| 1267 |
|
---|
[11] | 1268 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1269 | """Check if the fault condition holds."""
|
---|
[192] | 1270 | return not flight.entranceExam and \
|
---|
[184] | 1271 | flight.stage==const.STAGE_PUSHANDTAXI and \
|
---|
[60] | 1272 | PayloadChecker.isZFWFaulty(state.zfw, flight.zfw)
|
---|
[332] | 1273 |
|
---|
[11] | 1274 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1275 | """Log the fault."""
|
---|
[30] | 1276 | flight.handleNoGo(PayloadChecker, state.timestamp,
|
---|
| 1277 | "ZFW difference is more than %d kgs" % \
|
---|
| 1278 | (PayloadChecker.TOLERANCE,),
|
---|
| 1279 | "ZFW NO GO")
|
---|
[11] | 1280 |
|
---|
| 1281 | #---------------------------------------------------------------------------------------
|
---|
| 1282 |
|
---|
| 1283 | class PitotChecker(PatientFaultChecker):
|
---|
| 1284 | """Check if pitot heat is on."""
|
---|
| 1285 | def __init__(self):
|
---|
| 1286 | """Construct the checker."""
|
---|
| 1287 | super(PitotChecker, self).__init__(timeout = 3.0)
|
---|
| 1288 |
|
---|
| 1289 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1290 | """Check if the fault condition holds."""
|
---|
[13] | 1291 | return state.groundSpeed>80 and not state.pitotHeatOn
|
---|
[332] | 1292 |
|
---|
[11] | 1293 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1294 | """Log the fault."""
|
---|
| 1295 | score = 2 if flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
|
---|
| 1296 | const.STAGE_CRUISE, const.STAGE_DESCENT,
|
---|
| 1297 | const.STAGE_LANDING] else 0
|
---|
[30] | 1298 | flight.handleFault(PitotChecker, state.timestamp,
|
---|
| 1299 | FaultChecker._appendDuring(flight, "Pitot heat was off"),
|
---|
[332] | 1300 | score)
|
---|
[11] | 1301 |
|
---|
| 1302 | #---------------------------------------------------------------------------------------
|
---|
| 1303 |
|
---|
| 1304 | class ReverserChecker(SimpleFaultChecker):
|
---|
[360] | 1305 | """Check if the reverser is not used below the speed prescribed for the
|
---|
| 1306 | aircraft."""
|
---|
[11] | 1307 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1308 | """Check if the fault condition holds."""
|
---|
| 1309 | return flight.stage in [const.STAGE_DESCENT, const.STAGE_LANDING,
|
---|
| 1310 | const.STAGE_TAXIAFTERLAND] and \
|
---|
[443] | 1311 | state.reverser and \
|
---|
[360] | 1312 | state.groundSpeed<aircraft.reverseMinSpeed and max(state.reverser)
|
---|
[332] | 1313 |
|
---|
[11] | 1314 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1315 | """Log the fault."""
|
---|
[241] | 1316 | message = "Reverser used below %.0f %s" % \
|
---|
| 1317 | (flight.speedFromKnots(60), flight.getEnglishSpeedUnit())
|
---|
[30] | 1318 | flight.handleFault(ReverserChecker, state.timestamp,
|
---|
[241] | 1319 | FaultChecker._appendDuring(flight, message),
|
---|
| 1320 | 15)
|
---|
[11] | 1321 |
|
---|
| 1322 | #---------------------------------------------------------------------------------------
|
---|
| 1323 |
|
---|
| 1324 | class SpeedChecker(SimpleFaultChecker):
|
---|
| 1325 | """Check if the speed is in the prescribed limits."""
|
---|
[344] | 1326 | @staticmethod
|
---|
[349] | 1327 | def logSpeedFault(flight, state, stage = None, updateID = None):
|
---|
[344] | 1328 | """Log the speed fault."""
|
---|
| 1329 | message = "Taxi speed over %.0f %s" % \
|
---|
| 1330 | (flight.speedFromKnots(50), flight.getEnglishSpeedUnit())
|
---|
[349] | 1331 | if stage is None:
|
---|
| 1332 | stage = flight.stage
|
---|
| 1333 | score = FaultChecker._getLinearScore(50, 80, 10, 15, state.groundSpeed)
|
---|
| 1334 | return flight.handleFault((SpeedChecker, stage), state.timestamp,
|
---|
| 1335 | FaultChecker._appendDuring(flight, message),
|
---|
| 1336 | score, updatePrevious = updateID is None,
|
---|
| 1337 | updateID = updateID)
|
---|
[344] | 1338 |
|
---|
[11] | 1339 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1340 | """Check if the fault condition holds."""
|
---|
| 1341 | return flight.stage in [const.STAGE_PUSHANDTAXI,
|
---|
[354] | 1342 | const.STAGE_RTO,
|
---|
[11] | 1343 | const.STAGE_TAXIAFTERLAND] and \
|
---|
| 1344 | state.groundSpeed>50
|
---|
[332] | 1345 |
|
---|
[11] | 1346 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1347 | """Log the fault."""
|
---|
[344] | 1348 | self.logSpeedFault(flight, state)
|
---|
| 1349 |
|
---|
| 1350 | #---------------------------------------------------------------------------------------
|
---|
| 1351 |
|
---|
| 1352 | class NoStrobeSpeedChecker(StateChecker):
|
---|
| 1353 | """Checker for the ground speed of aircraft that have no strobe lights by
|
---|
| 1354 | which to detect the takeoff stage.
|
---|
| 1355 |
|
---|
| 1356 | If, during the PUSHANDTAXI stage the speed exceeds 50 knots, the state as
|
---|
| 1357 | saved as a provisional takeoff state. If the speed then decreases below 50
|
---|
[453] | 1358 | knots, or the plane remains on the ground for more than 40 seconds, a taxi
|
---|
[349] | 1359 | speed error is logged with the highest ground speed detected. This state is
|
---|
| 1360 | also stored in the flight object as a possible
|
---|
[344] | 1361 |
|
---|
[453] | 1362 | If the plane becomes airborne within 40 seconds, the stage becomes TAKEOFF,
|
---|
[344] | 1363 | and the previously saved takeoff state is logged.
|
---|
| 1364 |
|
---|
| 1365 | During the TAXIAFTERLAND stage, speed is checked as in case of
|
---|
| 1366 | SpeedChecker."""
|
---|
| 1367 | def __init__(self):
|
---|
| 1368 | """Initialize the speed checker."""
|
---|
| 1369 | self._takeoffState = None
|
---|
| 1370 | self._highestSpeedState = None
|
---|
| 1371 |
|
---|
| 1372 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 1373 | """Check the state as described above."""
|
---|
[354] | 1374 | if flight.stage==const.STAGE_PUSHANDTAXI or \
|
---|
| 1375 | flight.stage==const.STAGE_RTO:
|
---|
[344] | 1376 | self._checkPushAndTaxi(flight, aircraft, state)
|
---|
| 1377 | elif flight.stage==const.STAGE_TAXIAFTERLAND:
|
---|
| 1378 | if state.groundSpeed>50:
|
---|
| 1379 | SpeedChecker.logSpeedFault(flight, state)
|
---|
[480] | 1380 | else:
|
---|
| 1381 | self._takeoffState = None
|
---|
[344] | 1382 |
|
---|
| 1383 | def _checkPushAndTaxi(self, flight, aircraft, state):
|
---|
| 1384 | """Check the speed during the push and taxi stage."""
|
---|
| 1385 | if state.groundSpeed>50:
|
---|
| 1386 | if self._takeoffState is None:
|
---|
| 1387 | self._takeoffState = state
|
---|
| 1388 | self._highestSpeedState = state
|
---|
| 1389 | else:
|
---|
| 1390 | if state.groundSpeed>self._highestSpeedState.groundSpeed:
|
---|
| 1391 | self._highestSpeedState = state
|
---|
| 1392 |
|
---|
[414] | 1393 | if not state.onTheGround:
|
---|
[344] | 1394 | aircraft.setStage(self._takeoffState, const.STAGE_TAKEOFF)
|
---|
| 1395 | self._takeoffState = None
|
---|
[453] | 1396 | elif state.timestamp > (self._takeoffState.timestamp + 40):
|
---|
[414] | 1397 | flight.setRTOState(self._highestSpeedState)
|
---|
[344] | 1398 | elif self._takeoffState is not None:
|
---|
[349] | 1399 | flight.setRTOState(self._highestSpeedState)
|
---|
[344] | 1400 | self._takeoffState = None
|
---|
[11] | 1401 |
|
---|
| 1402 | #---------------------------------------------------------------------------------------
|
---|
| 1403 |
|
---|
| 1404 | class StallChecker(PatientFaultChecker):
|
---|
| 1405 | """Check if stall occured."""
|
---|
| 1406 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1407 | """Check if the fault condition holds."""
|
---|
| 1408 | return flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
|
---|
| 1409 | const.STAGE_CRUISE, const.STAGE_DESCENT,
|
---|
| 1410 | const.STAGE_LANDING] and state.stalled
|
---|
[332] | 1411 |
|
---|
[11] | 1412 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1413 | """Log the fault."""
|
---|
| 1414 | score = 40 if flight.stage in [const.STAGE_TAKEOFF,
|
---|
| 1415 | const.STAGE_LANDING] else 30
|
---|
[30] | 1416 | flight.handleFault(StallChecker, state.timestamp,
|
---|
| 1417 | FaultChecker._appendDuring(flight, "Stalled"),
|
---|
[332] | 1418 | score)
|
---|
[11] | 1419 |
|
---|
| 1420 | #---------------------------------------------------------------------------------------
|
---|
| 1421 |
|
---|
| 1422 | class StrobeLightsChecker(PatientFaultChecker):
|
---|
| 1423 | """Check if the strobe lights are used properly."""
|
---|
| 1424 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1425 | """Check if the fault condition holds."""
|
---|
[480] | 1426 | return state.strobeLightsOn is not None and \
|
---|
| 1427 | ((flight.stage==const.STAGE_BOARDING and \
|
---|
[211] | 1428 | state.strobeLightsOn and state.onTheGround) or \
|
---|
| 1429 | (flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 1430 | not state.strobeLightsOn and not state.gearsDown) or \
|
---|
| 1431 | (flight.stage in [const.STAGE_CLIMB, const.STAGE_CRUISE,
|
---|
| 1432 | const.STAGE_DESCENT] and \
|
---|
| 1433 | not state.strobeLightsOn and not state.onTheGround) or \
|
---|
| 1434 | (flight.stage==const.STAGE_PARKING and \
|
---|
[480] | 1435 | state.strobeLightsOn and state.onTheGround))
|
---|
[332] | 1436 |
|
---|
[11] | 1437 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1438 | """Log the fault."""
|
---|
| 1439 | message = "Strobe lights were %s" % (("on" if state.strobeLightsOn else "off"),)
|
---|
[30] | 1440 | flight.handleFault(StrobeLightsChecker, state.timestamp,
|
---|
| 1441 | FaultChecker._appendDuring(flight, message),
|
---|
| 1442 | 1)
|
---|
[11] | 1443 |
|
---|
| 1444 | #---------------------------------------------------------------------------------------
|
---|
| 1445 |
|
---|
| 1446 | class ThrustChecker(SimpleFaultChecker):
|
---|
| 1447 | """Check if the thrust setting is not too high during takeoff.
|
---|
| 1448 |
|
---|
| 1449 | FIXME: is this really so general, for all aircraft?"""
|
---|
| 1450 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1451 | """Check if the fault condition holds."""
|
---|
[263] | 1452 | return flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 1453 | state.n1 is not None and max(state.n1)>97
|
---|
[332] | 1454 |
|
---|
[11] | 1455 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1456 | """Log the fault."""
|
---|
[30] | 1457 | flight.handleFault(ThrustChecker, state.timestamp,
|
---|
| 1458 | FaultChecker._appendDuring(flight,
|
---|
| 1459 | "Thrust setting was too high (>97%)"),
|
---|
[405] | 1460 | FaultChecker._getLinearScore(97, 110, 0, 10,
|
---|
| 1461 | max(state.n1)),
|
---|
| 1462 | updatePrevious = True)
|
---|
[11] | 1463 |
|
---|
| 1464 | #---------------------------------------------------------------------------------------
|
---|
| 1465 |
|
---|
| 1466 | class VSChecker(SimpleFaultChecker):
|
---|
| 1467 | """Check if the vertical speed is not too low at certain altitudes"""
|
---|
| 1468 | BELOW10000 = -5000
|
---|
| 1469 | BELOW5000 = -2500
|
---|
| 1470 | BELOW2500 = -1500
|
---|
| 1471 | BELOW500 = -1000
|
---|
| 1472 | TOLERANCE = 1.2
|
---|
| 1473 |
|
---|
| 1474 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1475 | """Check if the fault condition holds."""
|
---|
[197] | 1476 | vs = state.smoothedVS
|
---|
[11] | 1477 | altitude = state.altitude
|
---|
| 1478 | return vs < -8000 or vs > 8000 or \
|
---|
| 1479 | (altitude<500 and vs < (VSChecker.BELOW500 *
|
---|
[13] | 1480 | VSChecker.TOLERANCE)) or \
|
---|
[11] | 1481 | (altitude<2500 and vs < (VSChecker.BELOW2500 *
|
---|
[13] | 1482 | VSChecker.TOLERANCE)) or \
|
---|
[11] | 1483 | (altitude<5000 and vs < (VSChecker.BELOW5000 *
|
---|
[13] | 1484 | VSChecker.TOLERANCE)) or \
|
---|
[11] | 1485 | (altitude<10000 and vs < (VSChecker.BELOW10000 *
|
---|
[13] | 1486 | VSChecker.TOLERANCE))
|
---|
[332] | 1487 |
|
---|
[11] | 1488 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1489 | """Log the fault."""
|
---|
[197] | 1490 | vs = state.smoothedVS
|
---|
[11] | 1491 |
|
---|
| 1492 | message = "Vertical speed was %.0f feet/min" % (vs,)
|
---|
| 1493 | if vs>-8000 and vs<8000:
|
---|
| 1494 | message += " at %.0f feet (exceeds company limit)" % (state.altitude,)
|
---|
| 1495 |
|
---|
| 1496 | score = 10 if vs<-8000 or vs>8000 else 0
|
---|
| 1497 |
|
---|
[30] | 1498 | flight.handleFault(VSChecker, state.timestamp,
|
---|
| 1499 | FaultChecker._appendDuring(flight, message),
|
---|
| 1500 | score)
|
---|
[11] | 1501 |
|
---|
| 1502 | #---------------------------------------------------------------------------------------
|
---|