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