[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
|
---|
[409] | 467 | message = "Altimeter: %.2f hPa at %.0f feet" % \
|
---|
[394] | 468 | (logState.altimeter, logState.altitude)
|
---|
| 469 | if not logState.altimeterReliable:
|
---|
| 470 | message += " (u/r)"
|
---|
| 471 | return message
|
---|
[8] | 472 |
|
---|
| 473 | #---------------------------------------------------------------------------------------
|
---|
| 474 |
|
---|
[321] | 475 | class NAVLogger(StateChangeLogger, DelayedChangeMixin, ForceableLoggerMixin):
|
---|
[320] | 476 | """Logger for NAV radios.
|
---|
| 477 |
|
---|
[355] | 478 | It also logs the OBS radial set."""
|
---|
[356] | 479 | excludedStages = [const.STAGE_BOARDING, const.STAGE_PUSHANDTAXI,
|
---|
| 480 | const.STAGE_RTO, const.STAGE_TAXIAFTERLAND,
|
---|
| 481 | const.STAGE_PARKING]
|
---|
| 482 |
|
---|
[321] | 483 | @staticmethod
|
---|
| 484 | def getMessage(logName, frequency, obs):
|
---|
| 485 | """Get the message for the given NAV radio setting."""
|
---|
[389] | 486 | message = u"%-5s %s" % (logName + ":", frequency)
|
---|
[363] | 487 | if obs is not None: message += u" (%03d\u00b0)" % (obs,)
|
---|
[321] | 488 | return message
|
---|
[332] | 489 |
|
---|
[320] | 490 | def __init__(self, attrName, logName):
|
---|
| 491 | """Construct the NAV logger."""
|
---|
[356] | 492 | StateChangeLogger.__init__(self, logInitial = False,
|
---|
| 493 | excludedStages = self.excludedStages)
|
---|
[320] | 494 | DelayedChangeMixin.__init__(self)
|
---|
[321] | 495 |
|
---|
| 496 | self._getLogTimestamp = \
|
---|
[324] | 497 | lambda state, forced: \
|
---|
| 498 | DelayedChangeMixin._getLogTimestamp(self, state, forced)
|
---|
[320] | 499 |
|
---|
| 500 | self._attrName = attrName
|
---|
| 501 | self._logName = logName
|
---|
[321] | 502 |
|
---|
[320] | 503 | def _getValue(self, state):
|
---|
| 504 | """Get the value.
|
---|
| 505 |
|
---|
| 506 | If both the frequency and the obs settings are available, a tuple
|
---|
| 507 | containing them is returned, otherwise None."""
|
---|
| 508 | frequency = getattr(state, self._attrName)
|
---|
| 509 | obs = getattr(state, self._attrName + "_obs")
|
---|
[321] | 510 | manual = getattr(state, self._attrName + "_manual")
|
---|
| 511 | return (frequency, obs, manual)
|
---|
[320] | 512 |
|
---|
[321] | 513 | def _getMessage(self, flight, state, forced):
|
---|
[320] | 514 | """Get the message."""
|
---|
[321] | 515 | (frequency, obs, manual) = self._getValue(state)
|
---|
| 516 | return None if frequency is None or obs is None or \
|
---|
| 517 | (not manual and not forced) else \
|
---|
| 518 | self.getMessage(self._logName, frequency, obs)
|
---|
| 519 |
|
---|
| 520 | def _isDifferent(self, oldValue, newValue):
|
---|
| 521 | """Determine if the valie has changed between the given states."""
|
---|
| 522 | (oldFrequency, oldOBS, _oldManual) = oldValue
|
---|
| 523 | (newFrequency, newOBS, _newManual) = newValue
|
---|
| 524 | return oldFrequency!=newFrequency or oldOBS!=newOBS
|
---|
[320] | 525 |
|
---|
| 526 | #---------------------------------------------------------------------------------------
|
---|
| 527 |
|
---|
[366] | 528 | class ILSLogger(NAVLogger):
|
---|
| 529 | """Logger for the ILS radio setting."""
|
---|
| 530 | def __init__(self):
|
---|
| 531 | """Construct the logger."""
|
---|
| 532 | super(ILSLogger, self).__init__("ils", "ILS")
|
---|
| 533 |
|
---|
| 534 | #---------------------------------------------------------------------------------------
|
---|
| 535 |
|
---|
[320] | 536 | class NAV1Logger(NAVLogger):
|
---|
[8] | 537 | """Logger for the NAV1 radio setting."""
|
---|
| 538 | def __init__(self):
|
---|
| 539 | """Construct the logger."""
|
---|
[320] | 540 | super(NAV1Logger, self).__init__("nav1", "NAV1")
|
---|
[8] | 541 |
|
---|
| 542 | #---------------------------------------------------------------------------------------
|
---|
| 543 |
|
---|
[320] | 544 | class NAV2Logger(NAVLogger):
|
---|
[8] | 545 | """Logger for the NAV2 radio setting."""
|
---|
| 546 | def __init__(self):
|
---|
| 547 | """Construct the logger."""
|
---|
[320] | 548 | super(NAV2Logger, self).__init__("nav2", "NAV2")
|
---|
[8] | 549 |
|
---|
| 550 | #---------------------------------------------------------------------------------------
|
---|
| 551 |
|
---|
[321] | 552 | class ADFLogger(GenericStateChangeLogger, ForceableLoggerMixin):
|
---|
| 553 | """Base class for the ADF loggers."""
|
---|
| 554 | def __init__(self, attr, logName):
|
---|
| 555 | """Construct the ADF logger."""
|
---|
| 556 | GenericStateChangeLogger.__init__(self, attr,
|
---|
[333] | 557 | "%s: %%s" % (logName,),
|
---|
[356] | 558 | logInitial = False,
|
---|
| 559 | excludedStages =
|
---|
| 560 | NAVLogger.excludedStages,
|
---|
[321] | 561 | minDelay = 3.0, maxDelay = 10.0)
|
---|
| 562 |
|
---|
| 563 | #---------------------------------------------------------------------------------------
|
---|
| 564 |
|
---|
| 565 | class ADF1Logger(ADFLogger):
|
---|
[317] | 566 | """Logger for the ADF1 radio setting."""
|
---|
| 567 | def __init__(self):
|
---|
| 568 | """Construct the logger."""
|
---|
[321] | 569 | super(ADF1Logger, self).__init__("adf1", "ADF1")
|
---|
[317] | 570 |
|
---|
| 571 | #---------------------------------------------------------------------------------------
|
---|
| 572 |
|
---|
[321] | 573 | class ADF2Logger(ADFLogger):
|
---|
[317] | 574 | """Logger for the ADF2 radio setting."""
|
---|
| 575 | def __init__(self):
|
---|
| 576 | """Construct the logger."""
|
---|
[321] | 577 | super(ADF2Logger, self).__init__("adf2", "ADF2")
|
---|
[317] | 578 |
|
---|
| 579 | #---------------------------------------------------------------------------------------
|
---|
| 580 |
|
---|
[8] | 581 | class SquawkLogger(GenericStateChangeLogger):
|
---|
| 582 | """Logger for the squawk setting."""
|
---|
| 583 | def __init__(self):
|
---|
| 584 | """Construct the logger."""
|
---|
| 585 | super(SquawkLogger, self).__init__("squawk", "Squawk code: %s",
|
---|
[22] | 586 | minDelay = 3.0, maxDelay = 10.0)
|
---|
[8] | 587 |
|
---|
| 588 | #---------------------------------------------------------------------------------------
|
---|
| 589 |
|
---|
| 590 | class LightsLogger(StateChangeLogger, SingleValueMixin, SimpleChangeMixin):
|
---|
| 591 | """Base class for the loggers of the various lights."""
|
---|
| 592 | def __init__(self, attrName, template):
|
---|
| 593 | """Construct the logger."""
|
---|
| 594 | StateChangeLogger.__init__(self)
|
---|
| 595 | SingleValueMixin.__init__(self, attrName)
|
---|
[332] | 596 |
|
---|
[8] | 597 | self._template = template
|
---|
| 598 |
|
---|
[321] | 599 | def _getMessage(self, flight, state, forced):
|
---|
[8] | 600 | """Get the message from the given state."""
|
---|
[416] | 601 | value = self._getValue(state)
|
---|
| 602 | if value is None:
|
---|
| 603 | return None
|
---|
| 604 | else:
|
---|
| 605 | return self._template % ("ON" if value else "OFF")
|
---|
[332] | 606 |
|
---|
[8] | 607 | #---------------------------------------------------------------------------------------
|
---|
| 608 |
|
---|
| 609 | class AnticollisionLightsLogger(LightsLogger):
|
---|
| 610 | """Logger for the anti-collision lights."""
|
---|
| 611 | def __init__(self):
|
---|
| 612 | LightsLogger.__init__(self, "antiCollisionLightsOn",
|
---|
| 613 | "Anti-collision lights: %s")
|
---|
| 614 |
|
---|
| 615 | #---------------------------------------------------------------------------------------
|
---|
| 616 |
|
---|
| 617 | class LandingLightsLogger(LightsLogger):
|
---|
| 618 | """Logger for the landing lights."""
|
---|
| 619 | def __init__(self):
|
---|
| 620 | LightsLogger.__init__(self, "landingLightsOn",
|
---|
| 621 | "Landing lights: %s")
|
---|
| 622 |
|
---|
| 623 | #---------------------------------------------------------------------------------------
|
---|
| 624 |
|
---|
| 625 | class StrobeLightsLogger(LightsLogger):
|
---|
| 626 | """Logger for the strobe lights."""
|
---|
| 627 | def __init__(self):
|
---|
| 628 | LightsLogger.__init__(self, "strobeLightsOn",
|
---|
| 629 | "Strobe lights: %s")
|
---|
| 630 |
|
---|
| 631 | #---------------------------------------------------------------------------------------
|
---|
| 632 |
|
---|
| 633 | class NavLightsLogger(LightsLogger):
|
---|
| 634 | """Logger for the navigational lights."""
|
---|
| 635 | def __init__(self):
|
---|
| 636 | LightsLogger.__init__(self, "navLightsOn",
|
---|
| 637 | "Navigational lights: %s")
|
---|
| 638 |
|
---|
| 639 | #---------------------------------------------------------------------------------------
|
---|
| 640 |
|
---|
| 641 | class FlapsLogger(StateChangeLogger, SingleValueMixin, SimpleChangeMixin):
|
---|
| 642 | """Logger for the flaps setting."""
|
---|
| 643 | def __init__(self):
|
---|
| 644 | """Construct the logger."""
|
---|
[364] | 645 | StateChangeLogger.__init__(self, logInitial = True,
|
---|
| 646 | excludedStages =
|
---|
| 647 | [const.STAGE_BOARDING,
|
---|
| 648 | const.STAGE_PUSHANDTAXI,
|
---|
| 649 | const.STAGE_RTO,
|
---|
| 650 | const.STAGE_TAKEOFF])
|
---|
[8] | 651 | SingleValueMixin.__init__(self, "flapsSet")
|
---|
| 652 |
|
---|
[321] | 653 | def _getMessage(self, flight, state, forced):
|
---|
[8] | 654 | """Get the message to log on a change."""
|
---|
| 655 | speed = state.groundSpeed if state.groundSpeed<80.0 else state.ias
|
---|
[333] | 656 | return "Flaps %.0f - %.0f %s" % \
|
---|
[241] | 657 | (state.flapsSet, flight.speedFromKnots(speed),
|
---|
| 658 | flight.getEnglishSpeedUnit())
|
---|
[8] | 659 |
|
---|
| 660 | #---------------------------------------------------------------------------------------
|
---|
| 661 |
|
---|
| 662 | class GearsLogger(StateChangeLogger, SingleValueMixin, SimpleChangeMixin):
|
---|
| 663 | """Logger for the gears state."""
|
---|
| 664 | def __init__(self):
|
---|
| 665 | """Construct the logger."""
|
---|
| 666 | StateChangeLogger.__init__(self, logInitial = True)
|
---|
[209] | 667 | SingleValueMixin.__init__(self, "gearControlDown")
|
---|
[8] | 668 |
|
---|
[321] | 669 | def _getMessage(self, flight, state, forced):
|
---|
[8] | 670 | """Get the message to log on a change."""
|
---|
[241] | 671 | return "Gears SET to %s at %.0f %s, %.0f feet" % \
|
---|
[209] | 672 | ("DOWN" if state.gearControlDown else "UP",
|
---|
[241] | 673 | flight.speedFromKnots(state.ias),
|
---|
| 674 | flight.getEnglishSpeedUnit(), state.altitude)
|
---|
[8] | 675 |
|
---|
| 676 | #---------------------------------------------------------------------------------------
|
---|
[11] | 677 |
|
---|
[338] | 678 | class APLogger(StateChangeLogger, DelayedChangeMixin):
|
---|
| 679 | """Log the state of the autopilot."""
|
---|
| 680 | @staticmethod
|
---|
| 681 | def _logBoolean(logger, timestamp, what, value):
|
---|
| 682 | """Log a boolean value.
|
---|
| 683 |
|
---|
| 684 | what is the name of the value that is being logged."""
|
---|
| 685 | message = what + " "
|
---|
| 686 | if value is None:
|
---|
| 687 | message += "cannot be detected, will not log"
|
---|
| 688 | else:
|
---|
| 689 | message += "is " + ("ON" if value else "OFF")
|
---|
| 690 | logger.message(timestamp, message)
|
---|
| 691 |
|
---|
| 692 | @staticmethod
|
---|
| 693 | def _logNumeric(logger, timestamp, what, format, value):
|
---|
| 694 | """Log a numerical value."""
|
---|
| 695 | message = what
|
---|
| 696 | if value is None:
|
---|
| 697 | message += u" cannot be detected, will not log"
|
---|
| 698 | else:
|
---|
| 699 | message += u": " + format % (value,)
|
---|
| 700 | logger.message(timestamp, message)
|
---|
| 701 |
|
---|
| 702 | @staticmethod
|
---|
| 703 | def _logAPMaster(logger, timestamp, state):
|
---|
| 704 | """Log the AP master state."""
|
---|
| 705 | APLogger._logBoolean(logger, timestamp, "AP master",
|
---|
| 706 | state.apMaster)
|
---|
| 707 |
|
---|
| 708 | @staticmethod
|
---|
| 709 | def _logAPHeadingHold(logger, timestamp, state):
|
---|
| 710 | """Log the AP heading hold state."""
|
---|
| 711 | APLogger._logBoolean(logger, timestamp, "AP heading hold",
|
---|
| 712 | state.apHeadingHold)
|
---|
| 713 |
|
---|
| 714 | @staticmethod
|
---|
| 715 | def _logAPHeading(logger, timestamp, state):
|
---|
| 716 | """Log the AP heading."""
|
---|
| 717 | APLogger._logNumeric(logger, timestamp, u"AP heading",
|
---|
| 718 | u"%03.0f\u00b0", state.apHeading)
|
---|
| 719 |
|
---|
| 720 | @staticmethod
|
---|
| 721 | def _logAPAltitudeHold(logger, timestamp, state):
|
---|
| 722 | """Log the AP altitude hold state."""
|
---|
| 723 | APLogger._logBoolean(logger, timestamp, "AP altitude hold",
|
---|
| 724 | state.apAltitudeHold)
|
---|
| 725 |
|
---|
| 726 | @staticmethod
|
---|
| 727 | def _logAPAltitude(logger, timestamp, state):
|
---|
| 728 | """Log the AP heading."""
|
---|
| 729 | APLogger._logNumeric(logger, timestamp, u"AP altitude",
|
---|
| 730 | u"%.0f ft", state.apAltitude)
|
---|
| 731 |
|
---|
| 732 | def __init__(self):
|
---|
| 733 | """Construct the state logger."""
|
---|
| 734 | StateChangeLogger.__init__(self)
|
---|
| 735 | DelayedChangeMixin.__init__(self)
|
---|
| 736 | self._lastLoggedState = None
|
---|
[355] | 737 | self.logState = lambda flight, logger, state:\
|
---|
| 738 | APLogger.logState(self, flight, logger, state)
|
---|
[338] | 739 |
|
---|
| 740 | def _getValue(self, state):
|
---|
| 741 | """Convert the relevant values from the given state into a tuple."""
|
---|
| 742 | return (state.apMaster,
|
---|
| 743 | state.apHeadingHold, state.apHeading,
|
---|
| 744 | state.apAltitudeHold, state.apAltitude)
|
---|
| 745 |
|
---|
| 746 | def _isDifferent(self, oldValue, newValue):
|
---|
| 747 | """Determine if the given old and new values are different (enough) to
|
---|
| 748 | be logged."""
|
---|
| 749 | (oldAPMaster, oldAPHeadingHold, oldAPHeading,
|
---|
| 750 | oldAPAltitudeHold, oldAPAltitude) = oldValue
|
---|
| 751 | (apMaster, apHeadingHold, apHeading,
|
---|
| 752 | apAltitudeHold, apAltitude) = newValue
|
---|
| 753 |
|
---|
| 754 | if apMaster is not None and apMaster!=oldAPMaster:
|
---|
| 755 | return True
|
---|
| 756 | if apMaster is False:
|
---|
| 757 | return False
|
---|
| 758 |
|
---|
| 759 | if apHeadingHold is not None and apHeadingHold!=oldAPHeadingHold:
|
---|
| 760 | return True
|
---|
| 761 | if apHeadingHold is not False and apHeading is not None and \
|
---|
| 762 | apHeading!=oldAPHeading:
|
---|
| 763 | return True
|
---|
| 764 |
|
---|
| 765 | if apAltitudeHold is not None and apAltitudeHold!=oldAPAltitudeHold:
|
---|
| 766 | return True
|
---|
| 767 | if apAltitudeHold is not False and apAltitude is not None and \
|
---|
| 768 | apAltitude!=oldAPAltitude:
|
---|
| 769 | return True
|
---|
| 770 |
|
---|
| 771 | return False
|
---|
| 772 |
|
---|
| 773 | def logState(self, flight, logger, state):
|
---|
| 774 | """Log the autopilot state."""
|
---|
| 775 | timestamp = DelayedChangeMixin._getLogTimestamp(self, state, False)
|
---|
| 776 | if self._lastLoggedState is None:
|
---|
| 777 | self._logAPMaster(logger, timestamp, state)
|
---|
| 778 | if state.apMaster is not False or state.apHeadingHold is None:
|
---|
| 779 | self._logAPHeadingHold(logger, timestamp, state)
|
---|
| 780 | if state.apMaster is not False and \
|
---|
| 781 | (state.apHeadingHold is not False or state.apHeading is None):
|
---|
| 782 | self._logAPHeading(logger, timestamp, state)
|
---|
| 783 | if state.apMaster is not False or state.apAltitudeHold is None:
|
---|
| 784 | self._logAPAltitudeHold(logger, timestamp, state)
|
---|
| 785 | if state.apMaster is not False and \
|
---|
| 786 | (state.apAltitudeHold is not False or state.apAltitude is None):
|
---|
| 787 | self._logAPAltitude(logger, timestamp, state)
|
---|
| 788 | self._firstCall = False
|
---|
| 789 | else:
|
---|
| 790 | oldState = self._lastLoggedState
|
---|
| 791 |
|
---|
| 792 | apMasterTurnedOn = False
|
---|
| 793 | if state.apMaster is not None and state.apMaster!=oldState.apMaster:
|
---|
| 794 | apMasterTurnedOn = state.apMaster
|
---|
| 795 | self._logAPMaster(logger, timestamp, state)
|
---|
| 796 |
|
---|
| 797 | if state.apMaster is not False:
|
---|
| 798 | apHeadingHoldTurnedOn = False
|
---|
| 799 | if state.apHeadingHold is not None and \
|
---|
| 800 | (state.apHeadingHold!=oldState.apHeadingHold or
|
---|
| 801 | apMasterTurnedOn):
|
---|
| 802 | apHeadingHoldTurnedOn = state.apHeadingHold
|
---|
| 803 | self._logAPHeadingHold(logger, timestamp, state)
|
---|
| 804 |
|
---|
| 805 | if state.apHeadingHold is not False and \
|
---|
| 806 | state.apHeading is not None and \
|
---|
| 807 | (state.apHeading!=oldState.apHeading or apMasterTurnedOn or
|
---|
| 808 | apHeadingHoldTurnedOn):
|
---|
| 809 | self._logAPHeading(logger, timestamp, state)
|
---|
| 810 |
|
---|
| 811 | apAltitudeHoldTurnedOn = False
|
---|
| 812 | if state.apAltitudeHold is not None and \
|
---|
| 813 | (state.apAltitudeHold!=oldState.apAltitudeHold or
|
---|
| 814 | apMasterTurnedOn):
|
---|
| 815 | apAltitudeHoldTurnedOn = state.apAltitudeHold
|
---|
| 816 | self._logAPAltitudeHold(logger, timestamp, state)
|
---|
| 817 |
|
---|
| 818 | if state.apAltitudeHold is not False and \
|
---|
| 819 | state.apAltitude is not None and \
|
---|
| 820 | (state.apAltitude!=oldState.apAltitude or apMasterTurnedOn or
|
---|
| 821 | apAltitudeHoldTurnedOn):
|
---|
| 822 | self._logAPAltitude(logger, timestamp, state)
|
---|
| 823 |
|
---|
| 824 | self._lastLoggedState = state
|
---|
| 825 |
|
---|
| 826 | #---------------------------------------------------------------------------------------
|
---|
| 827 |
|
---|
[11] | 828 | class FaultChecker(StateChecker):
|
---|
| 829 | """Base class for checkers that look for faults."""
|
---|
| 830 | @staticmethod
|
---|
| 831 | def _appendDuring(flight, message):
|
---|
| 832 | """Append a 'during XXX' test to the given message, depending on the
|
---|
| 833 | flight stage."""
|
---|
| 834 | stageStr = const.stage2string(flight.stage)
|
---|
| 835 | return message if stageStr is None \
|
---|
| 836 | else (message + " during " + stageStr.upper())
|
---|
| 837 |
|
---|
| 838 | @staticmethod
|
---|
| 839 | def _getLinearScore(minFaultValue, maxFaultValue, minScore, maxScore,
|
---|
| 840 | value):
|
---|
| 841 | """Get the score for a faulty value where the score is calculated
|
---|
| 842 | linearly within a certain range."""
|
---|
| 843 | if value<minFaultValue:
|
---|
| 844 | return 0
|
---|
| 845 | elif value>maxFaultValue:
|
---|
| 846 | return maxScore
|
---|
| 847 | else:
|
---|
| 848 | return minScore + (maxScore-minScore) * (value-minFaultValue) / \
|
---|
| 849 | (maxFaultValue - minFaultValue)
|
---|
| 850 |
|
---|
| 851 | #---------------------------------------------------------------------------------------
|
---|
| 852 |
|
---|
| 853 | class SimpleFaultChecker(FaultChecker):
|
---|
| 854 | """Base class for fault checkers that check for a single occurence of a
|
---|
| 855 | faulty condition.
|
---|
| 856 |
|
---|
| 857 | Child classes should implement the following functions:
|
---|
| 858 | - isCondition(self, flight, aircraft, oldState, state): should return whether the
|
---|
| 859 | condition holds
|
---|
| 860 | - logFault(self, flight, aircraft, logger, oldState, state): log the fault
|
---|
| 861 | via the logger."""
|
---|
| 862 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 863 | """Perform the check."""
|
---|
| 864 | if self.isCondition(flight, aircraft, oldState, state):
|
---|
| 865 | self.logFault(flight, aircraft, logger, oldState, state)
|
---|
| 866 |
|
---|
| 867 | #---------------------------------------------------------------------------------------
|
---|
| 868 |
|
---|
| 869 | class PatientFaultChecker(FaultChecker):
|
---|
| 870 | """A fault checker that does not decides on a fault when the condition
|
---|
| 871 | arises immediately, but can wait some time.
|
---|
| 872 |
|
---|
| 873 | Child classes should implement the following functions:
|
---|
| 874 | - isCondition(self, flight, aircraft, oldState, state): should return whether the
|
---|
| 875 | condition holds
|
---|
| 876 | - logFault(self, flight, aircraft, logger, oldState, state): log the fault
|
---|
| 877 | via the logger
|
---|
| 878 | """
|
---|
| 879 | def __init__(self, timeout = 2.0):
|
---|
| 880 | """Construct the fault checker with the given timeout."""
|
---|
| 881 | self._timeout = timeout
|
---|
| 882 | self._faultStarted = None
|
---|
| 883 |
|
---|
| 884 | def getTimeout(self, flight, aircraft, oldState, state):
|
---|
| 885 | """Get the timeout.
|
---|
| 886 |
|
---|
| 887 | This default implementation returns the timeout given in the
|
---|
| 888 | constructor, but child classes might want to enforce a different
|
---|
| 889 | policy."""
|
---|
| 890 | return self._timeout
|
---|
| 891 |
|
---|
| 892 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 893 | """Perform the check."""
|
---|
| 894 | if self.isCondition(flight, aircraft, oldState, state):
|
---|
| 895 | if self._faultStarted is None:
|
---|
| 896 | self._faultStarted = state.timestamp
|
---|
| 897 | timeout = self.getTimeout(flight, aircraft, oldState, state)
|
---|
| 898 | if state.timestamp>=(self._faultStarted + timeout):
|
---|
| 899 | self.logFault(flight, aircraft, logger, oldState, state)
|
---|
| 900 | self._faultStarted = state.timestamp
|
---|
| 901 | else:
|
---|
| 902 | self._faultStarted = None
|
---|
[332] | 903 |
|
---|
[11] | 904 | #---------------------------------------------------------------------------------------
|
---|
| 905 |
|
---|
| 906 | class AntiCollisionLightsChecker(PatientFaultChecker):
|
---|
| 907 | """Check for the anti-collision light being off at high N1 values."""
|
---|
| 908 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 909 | """Check if the fault condition holds."""
|
---|
| 910 | return (flight.stage!=const.STAGE_PARKING or \
|
---|
[183] | 911 | not flight.config.usingFS2Crew) and \
|
---|
[11] | 912 | not state.antiCollisionLightsOn and \
|
---|
[211] | 913 | self.isEngineCondition(state)
|
---|
[11] | 914 |
|
---|
| 915 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 916 | """Log the fault."""
|
---|
[30] | 917 | flight.handleFault(AntiCollisionLightsChecker, state.timestamp,
|
---|
| 918 | FaultChecker._appendDuring(flight,
|
---|
| 919 | "Anti-collision lights were off"),
|
---|
| 920 | 1)
|
---|
[11] | 921 |
|
---|
[211] | 922 | def isEngineCondition(self, state):
|
---|
| 923 | """Determine if the engines are in such a state that the lights should
|
---|
| 924 | be on."""
|
---|
[263] | 925 | if state.n1 is not None:
|
---|
| 926 | return max(state.n1)>5
|
---|
| 927 | elif state.rpm is not None:
|
---|
| 928 | return max(state.rpm)>0
|
---|
| 929 | else:
|
---|
| 930 | return False
|
---|
[211] | 931 |
|
---|
| 932 | #---------------------------------------------------------------------------------------
|
---|
| 933 |
|
---|
| 934 | class TupolevAntiCollisionLightsChecker(AntiCollisionLightsChecker):
|
---|
| 935 | """Check for the anti-collision light for Tuplev planes."""
|
---|
[307] | 936 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
[332] | 937 | """Check if the fault condition holds."""
|
---|
[307] | 938 | numEnginesRunning = 0
|
---|
| 939 | for n1 in state.n1:
|
---|
| 940 | if n1>5: numEnginesRunning += 1
|
---|
[332] | 941 |
|
---|
[307] | 942 | if flight.stage==const.STAGE_PARKING:
|
---|
| 943 | return numEnginesRunning<len(state.n1) \
|
---|
| 944 | and state.antiCollisionLightsOn
|
---|
| 945 | else:
|
---|
| 946 | return numEnginesRunning>1 and not state.antiCollisionLightsOn or \
|
---|
| 947 | numEnginesRunning<1 and state.antiCollisionLightsOn
|
---|
[211] | 948 |
|
---|
[11] | 949 | #---------------------------------------------------------------------------------------
|
---|
| 950 |
|
---|
| 951 | class BankChecker(SimpleFaultChecker):
|
---|
[263] | 952 | """Check for the bank is within limits."""
|
---|
[11] | 953 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 954 | """Check if the fault condition holds."""
|
---|
| 955 | if flight.stage==const.STAGE_CRUISE:
|
---|
| 956 | bankLimit = 30
|
---|
| 957 | elif flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
|
---|
| 958 | const.STAGE_DESCENT, const.STAGE_LANDING]:
|
---|
| 959 | bankLimit = 35
|
---|
| 960 | else:
|
---|
| 961 | return False
|
---|
| 962 |
|
---|
| 963 | return state.bank>bankLimit or state.bank<-bankLimit
|
---|
| 964 |
|
---|
| 965 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 966 | """Log the fault."""
|
---|
[30] | 967 | flight.handleFault(BankChecker, state.timestamp,
|
---|
| 968 | FaultChecker._appendDuring(flight, "Bank too steep"),
|
---|
| 969 | 2)
|
---|
[11] | 970 |
|
---|
| 971 | #---------------------------------------------------------------------------------------
|
---|
| 972 |
|
---|
| 973 | class FlapsRetractChecker(SimpleFaultChecker):
|
---|
| 974 | """Check if the flaps are not retracted too early."""
|
---|
[13] | 975 | def __init__(self):
|
---|
| 976 | """Construct the flaps checker."""
|
---|
| 977 | self._timeStart = None
|
---|
[332] | 978 |
|
---|
[11] | 979 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 980 | """Check if the fault condition holds.
|
---|
| 981 |
|
---|
| 982 | FIXME: check if this really is the intention (FlapsRetractedMistake.java)"""
|
---|
[357] | 983 | if (flight.stage==const.STAGE_TAKEOFF and not state.onTheGround and
|
---|
| 984 | aircraft.type!=const.AIRCRAFT_F70) or \
|
---|
[11] | 985 | (flight.stage==const.STAGE_LANDING and state.onTheGround):
|
---|
| 986 | if self._timeStart is None:
|
---|
| 987 | self._timeStart = state.timestamp
|
---|
| 988 |
|
---|
| 989 | if state.flapsSet==0 and state.timestamp<=(self._timeStart+2.0):
|
---|
| 990 | return True
|
---|
[13] | 991 | else:
|
---|
| 992 | self._timeStart = None
|
---|
[11] | 993 | return False
|
---|
| 994 |
|
---|
| 995 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 996 | """Log the fault."""
|
---|
[30] | 997 | flight.handleFault(FlapsRetractChecker, state.timestamp,
|
---|
| 998 | FaultChecker._appendDuring(flight, "Flaps retracted"),
|
---|
| 999 | 20)
|
---|
[11] | 1000 |
|
---|
| 1001 | #---------------------------------------------------------------------------------------
|
---|
| 1002 |
|
---|
| 1003 | class FlapsSpeedLimitChecker(SimpleFaultChecker):
|
---|
| 1004 | """Check if the flaps are extended only at the right speeds."""
|
---|
| 1005 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1006 | """Check if the fault condition holds."""
|
---|
| 1007 | speedLimit = aircraft.getFlapsSpeedLimit(state.flapsSet)
|
---|
[197] | 1008 | return speedLimit is not None and state.smoothedIAS>speedLimit
|
---|
[11] | 1009 |
|
---|
| 1010 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1011 | """Log the fault."""
|
---|
[30] | 1012 | flight.handleFault(FlapsSpeedLimitChecker, state.timestamp,
|
---|
| 1013 | FaultChecker._appendDuring(flight, "Flap speed limit fault"),
|
---|
| 1014 | 5)
|
---|
[11] | 1015 |
|
---|
| 1016 | #---------------------------------------------------------------------------------------
|
---|
| 1017 |
|
---|
| 1018 | class GearsDownChecker(SimpleFaultChecker):
|
---|
| 1019 | """Check if the gears are down at low altitudes."""
|
---|
| 1020 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1021 | """Check if the fault condition holds."""
|
---|
| 1022 | return state.radioAltitude<10 and not state.gearsDown and \
|
---|
| 1023 | flight.stage!=const.STAGE_TAKEOFF
|
---|
| 1024 |
|
---|
| 1025 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1026 | """Log the fault."""
|
---|
[30] | 1027 | flight.handleNoGo(GearsDownChecker, state.timestamp,
|
---|
| 1028 | "Gears not down at %.0f feet radio altitude" % \
|
---|
| 1029 | (state.radioAltitude,),
|
---|
| 1030 | "GEAR DOWN NO GO")
|
---|
[11] | 1031 |
|
---|
| 1032 | #---------------------------------------------------------------------------------------
|
---|
| 1033 |
|
---|
| 1034 | class GearSpeedLimitChecker(PatientFaultChecker):
|
---|
| 1035 | """Check if the gears not down at too high a speed."""
|
---|
| 1036 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1037 | """Check if the fault condition holds."""
|
---|
[197] | 1038 | return state.gearsDown and state.smoothedIAS>aircraft.gearSpeedLimit
|
---|
[11] | 1039 |
|
---|
| 1040 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1041 | """Log the fault."""
|
---|
[30] | 1042 | flight.handleFault(GearSpeedLimitChecker, state.timestamp,
|
---|
| 1043 | FaultChecker._appendDuring(flight, "Gear speed limit fault"),
|
---|
| 1044 | 5)
|
---|
[11] | 1045 |
|
---|
| 1046 | #---------------------------------------------------------------------------------------
|
---|
| 1047 |
|
---|
| 1048 | class GLoadChecker(SimpleFaultChecker):
|
---|
| 1049 | """Check if the G-load does not exceed 2 except during flare."""
|
---|
| 1050 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1051 | """Check if the fault condition holds."""
|
---|
| 1052 | return state.gLoad>2.0 and (flight.stage!=const.STAGE_LANDING or \
|
---|
| 1053 | state.radioAltitude>=50)
|
---|
[332] | 1054 |
|
---|
[11] | 1055 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1056 | """Log the fault."""
|
---|
[30] | 1057 | flight.handleFault(GLoadChecker, state.timestamp,
|
---|
| 1058 | "G-load was %.2f" % (state.gLoad,),
|
---|
| 1059 | 10)
|
---|
[11] | 1060 |
|
---|
| 1061 | #---------------------------------------------------------------------------------------
|
---|
| 1062 |
|
---|
| 1063 | class LandingLightsChecker(PatientFaultChecker):
|
---|
| 1064 | """Check if the landing lights are used properly."""
|
---|
| 1065 | def getTimeout(self, flight, aircraft, oldState, state):
|
---|
| 1066 | """Get the timeout.
|
---|
| 1067 |
|
---|
| 1068 | It is the default timeout except for landing and takeoff."""
|
---|
| 1069 | return 0.0 if flight.stage in [const.STAGE_TAKEOFF,
|
---|
| 1070 | const.STAGE_LANDING] else self._timeout
|
---|
| 1071 |
|
---|
| 1072 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1073 | """Check if the fault condition holds."""
|
---|
[314] | 1074 | return state.landingLightsOn is not None and \
|
---|
| 1075 | ((flight.stage==const.STAGE_BOARDING and \
|
---|
| 1076 | state.landingLightsOn and state.onTheGround) or \
|
---|
| 1077 | (flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 1078 | not state.landingLightsOn and not state.onTheGround) or \
|
---|
| 1079 | (flight.stage in [const.STAGE_CLIMB, const.STAGE_CRUISE,
|
---|
| 1080 | const.STAGE_DESCENT] and \
|
---|
| 1081 | state.landingLightsOn and state.altitude>12500) or \
|
---|
| 1082 | (flight.stage==const.STAGE_LANDING and \
|
---|
[415] | 1083 | not state.landingLightsOn and state.onTheGround and
|
---|
| 1084 | state.groundSpeed>50.0) or \
|
---|
[314] | 1085 | (flight.stage==const.STAGE_PARKING and \
|
---|
| 1086 | state.landingLightsOn and state.onTheGround))
|
---|
[332] | 1087 |
|
---|
[11] | 1088 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1089 | """Log the fault."""
|
---|
[375] | 1090 | score = 0 if flight.stage in [const.STAGE_TAKEOFF,
|
---|
| 1091 | const.STAGE_LANDING] else 1
|
---|
[335] | 1092 | message = "Landing lights were %s" % \
|
---|
| 1093 | (("on" if state.landingLightsOn else "off"),)
|
---|
[30] | 1094 | flight.handleFault(LandingLightsChecker, state.timestamp,
|
---|
| 1095 | FaultChecker._appendDuring(flight, message),
|
---|
[332] | 1096 | score)
|
---|
[11] | 1097 |
|
---|
| 1098 | #---------------------------------------------------------------------------------------
|
---|
| 1099 |
|
---|
[335] | 1100 | class TransponderChecker(PatientFaultChecker):
|
---|
| 1101 | """Check if the transponder is used properly."""
|
---|
[361] | 1102 | def __init__(self):
|
---|
| 1103 | """Construct the transponder checker."""
|
---|
| 1104 | super(TransponderChecker, self).__init__()
|
---|
| 1105 | self._liftOffTime = None
|
---|
| 1106 |
|
---|
[335] | 1107 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1108 | """Check if the fault condition holds."""
|
---|
[361] | 1109 | if state.onTheGround:
|
---|
| 1110 | self._liftOffTime = None
|
---|
| 1111 | elif self._liftOffTime is None:
|
---|
| 1112 | self._liftOffTime = state.timestamp
|
---|
| 1113 |
|
---|
[335] | 1114 | return state.xpdrC is not None and \
|
---|
| 1115 | ((state.xpdrC and flight.stage in
|
---|
| 1116 | [const.STAGE_BOARDING, const.STAGE_PARKING]) or \
|
---|
[361] | 1117 | (not state.xpdrC and
|
---|
| 1118 | (flight.stage in
|
---|
| 1119 | [const.STAGE_CRUISE, const.STAGE_DESCENT,
|
---|
| 1120 | const.STAGE_LANDING, const.STAGE_GOAROUND] or \
|
---|
| 1121 | ((not state.autoXPDR or \
|
---|
| 1122 | (self._liftOffTime is not None and
|
---|
| 1123 | state.timestamp > (self._liftOffTime+8))) and \
|
---|
| 1124 | flight.stage in
|
---|
| 1125 | [const.STAGE_TAKEOFF, const.STAGE_RTO, const.STAGE_CLIMB])
|
---|
| 1126 | )
|
---|
| 1127 | )
|
---|
| 1128 | )
|
---|
[335] | 1129 |
|
---|
| 1130 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1131 | """Log the fault."""
|
---|
| 1132 | score = 0
|
---|
| 1133 | message = "Transponder was %s" % \
|
---|
| 1134 | (("mode C" if state.xpdrC else "standby"),)
|
---|
| 1135 | flight.handleFault(TransponderChecker, state.timestamp,
|
---|
| 1136 | FaultChecker._appendDuring(flight, message),
|
---|
| 1137 | score)
|
---|
| 1138 |
|
---|
| 1139 | #---------------------------------------------------------------------------------------
|
---|
| 1140 |
|
---|
[11] | 1141 | class WeightChecker(PatientFaultChecker):
|
---|
| 1142 | """Base class for checkers that check that some limit is not exceeded."""
|
---|
| 1143 | def __init__(self, name):
|
---|
| 1144 | """Construct the checker."""
|
---|
| 1145 | super(WeightChecker, self).__init__(timeout = 5.0)
|
---|
| 1146 | self._name = name
|
---|
| 1147 |
|
---|
| 1148 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1149 | """Check if the fault condition holds."""
|
---|
| 1150 | if flight.entranceExam:
|
---|
| 1151 | return False
|
---|
| 1152 |
|
---|
| 1153 | limit = self.getLimit(flight, aircraft, state)
|
---|
| 1154 | if limit is not None:
|
---|
[183] | 1155 | #if flight.options.compensation is not None:
|
---|
| 1156 | # limit += flight.options.compensation
|
---|
[13] | 1157 | return self.getWeight(state)>limit
|
---|
[11] | 1158 |
|
---|
| 1159 | return False
|
---|
| 1160 |
|
---|
| 1161 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1162 | """Log the fault."""
|
---|
[13] | 1163 | mname = "M" + self._name
|
---|
[30] | 1164 | flight.handleNoGo(self.__class__, state.timestamp,
|
---|
| 1165 | "%s exceeded: %s is %.0f kg" % \
|
---|
| 1166 | (mname, self._name, self.getWeight(state)),
|
---|
| 1167 | "%s NO GO" % (mname,))
|
---|
[13] | 1168 |
|
---|
| 1169 | def getWeight(self, state):
|
---|
| 1170 | """Get the weight that is interesting for us."""
|
---|
| 1171 | return state.grossWeight
|
---|
[11] | 1172 |
|
---|
| 1173 | #---------------------------------------------------------------------------------------
|
---|
| 1174 |
|
---|
| 1175 | class MLWChecker(WeightChecker):
|
---|
| 1176 | """Checks if the MLW is not exceeded on landing."""
|
---|
| 1177 | def __init__(self):
|
---|
| 1178 | """Construct the checker."""
|
---|
[13] | 1179 | super(MLWChecker, self).__init__("LW")
|
---|
[11] | 1180 |
|
---|
[13] | 1181 | def getLimit(self, flight, aircraft, state):
|
---|
[11] | 1182 | """Get the limit if we are in the right state."""
|
---|
| 1183 | return aircraft.mlw if flight.stage==const.STAGE_LANDING and \
|
---|
[184] | 1184 | state.onTheGround and \
|
---|
| 1185 | not flight.entranceExam else None
|
---|
[11] | 1186 |
|
---|
| 1187 | #---------------------------------------------------------------------------------------
|
---|
| 1188 |
|
---|
| 1189 | class MTOWChecker(WeightChecker):
|
---|
| 1190 | """Checks if the MTOW is not exceeded on landing."""
|
---|
| 1191 | def __init__(self):
|
---|
| 1192 | """Construct the checker."""
|
---|
[13] | 1193 | super(MTOWChecker, self).__init__("TOW")
|
---|
[11] | 1194 |
|
---|
[13] | 1195 | def getLimit(self, flight, aircraft, state):
|
---|
[11] | 1196 | """Get the limit if we are in the right state."""
|
---|
[184] | 1197 | return aircraft.mtow if flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 1198 | not flight.entranceExam else None
|
---|
[11] | 1199 |
|
---|
| 1200 | #---------------------------------------------------------------------------------------
|
---|
| 1201 |
|
---|
| 1202 | class MZFWChecker(WeightChecker):
|
---|
[60] | 1203 | """Checks if the MZFW is not exceeded on landing."""
|
---|
[11] | 1204 | def __init__(self):
|
---|
| 1205 | """Construct the checker."""
|
---|
[13] | 1206 | super(MZFWChecker, self).__init__("ZFW")
|
---|
[11] | 1207 |
|
---|
[13] | 1208 | def getLimit(self, flight, aircraft, state):
|
---|
[11] | 1209 | """Get the limit if we are in the right state."""
|
---|
[184] | 1210 | return aircraft.mzfw if not flight.entranceExam else None
|
---|
[11] | 1211 |
|
---|
[13] | 1212 | def getWeight(self, state):
|
---|
| 1213 | """Get the weight that is interesting for us."""
|
---|
| 1214 | return state.zfw
|
---|
| 1215 |
|
---|
[11] | 1216 | #---------------------------------------------------------------------------------------
|
---|
| 1217 |
|
---|
| 1218 | class NavLightsChecker(PatientFaultChecker):
|
---|
| 1219 | """Check if the navigational lights are used properly."""
|
---|
| 1220 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1221 | """Check if the fault condition holds."""
|
---|
| 1222 | return flight.stage!=const.STAGE_BOARDING and \
|
---|
| 1223 | flight.stage!=const.STAGE_PARKING and \
|
---|
[341] | 1224 | state.navLightsOn is False
|
---|
[332] | 1225 |
|
---|
[11] | 1226 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1227 | """Log the fault."""
|
---|
[30] | 1228 | flight.handleFault(NavLightsChecker, state.timestamp,
|
---|
| 1229 | FaultChecker._appendDuring(flight,
|
---|
| 1230 | "Navigation lights were off"),
|
---|
| 1231 | 1)
|
---|
[11] | 1232 |
|
---|
| 1233 | #---------------------------------------------------------------------------------------
|
---|
| 1234 |
|
---|
| 1235 | class OverspeedChecker(PatientFaultChecker):
|
---|
| 1236 | """Check if Vne has been exceeded."""
|
---|
[197] | 1237 | def __init__(self, timeout = 5.0):
|
---|
[11] | 1238 | """Construct the checker."""
|
---|
[197] | 1239 | super(OverspeedChecker, self).__init__(timeout = timeout)
|
---|
[11] | 1240 |
|
---|
| 1241 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1242 | """Check if the fault condition holds."""
|
---|
| 1243 | return state.overspeed
|
---|
[332] | 1244 |
|
---|
[11] | 1245 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1246 | """Log the fault."""
|
---|
[30] | 1247 | flight.handleFault(OverspeedChecker, state.timestamp,
|
---|
| 1248 | FaultChecker._appendDuring(flight, "Overspeed"),
|
---|
[332] | 1249 | 20)
|
---|
[11] | 1250 |
|
---|
| 1251 | #---------------------------------------------------------------------------------------
|
---|
| 1252 |
|
---|
| 1253 | class PayloadChecker(SimpleFaultChecker):
|
---|
| 1254 | """Check if the payload matches the specification."""
|
---|
| 1255 | TOLERANCE=550
|
---|
[60] | 1256 |
|
---|
| 1257 | @staticmethod
|
---|
| 1258 | def isZFWFaulty(aircraftZFW, flightZFW):
|
---|
| 1259 | """Check if the given aircraft's ZFW is outside of the limits."""
|
---|
| 1260 | return aircraftZFW < (flightZFW - PayloadChecker.TOLERANCE) or \
|
---|
[332] | 1261 | aircraftZFW > (flightZFW + PayloadChecker.TOLERANCE)
|
---|
| 1262 |
|
---|
[11] | 1263 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1264 | """Check if the fault condition holds."""
|
---|
[192] | 1265 | return not flight.entranceExam and \
|
---|
[184] | 1266 | flight.stage==const.STAGE_PUSHANDTAXI and \
|
---|
[60] | 1267 | PayloadChecker.isZFWFaulty(state.zfw, flight.zfw)
|
---|
[332] | 1268 |
|
---|
[11] | 1269 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1270 | """Log the fault."""
|
---|
[30] | 1271 | flight.handleNoGo(PayloadChecker, state.timestamp,
|
---|
| 1272 | "ZFW difference is more than %d kgs" % \
|
---|
| 1273 | (PayloadChecker.TOLERANCE,),
|
---|
| 1274 | "ZFW NO GO")
|
---|
[11] | 1275 |
|
---|
| 1276 | #---------------------------------------------------------------------------------------
|
---|
| 1277 |
|
---|
| 1278 | class PitotChecker(PatientFaultChecker):
|
---|
| 1279 | """Check if pitot heat is on."""
|
---|
| 1280 | def __init__(self):
|
---|
| 1281 | """Construct the checker."""
|
---|
| 1282 | super(PitotChecker, self).__init__(timeout = 3.0)
|
---|
| 1283 |
|
---|
| 1284 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1285 | """Check if the fault condition holds."""
|
---|
[13] | 1286 | return state.groundSpeed>80 and not state.pitotHeatOn
|
---|
[332] | 1287 |
|
---|
[11] | 1288 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1289 | """Log the fault."""
|
---|
| 1290 | score = 2 if flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
|
---|
| 1291 | const.STAGE_CRUISE, const.STAGE_DESCENT,
|
---|
| 1292 | const.STAGE_LANDING] else 0
|
---|
[30] | 1293 | flight.handleFault(PitotChecker, state.timestamp,
|
---|
| 1294 | FaultChecker._appendDuring(flight, "Pitot heat was off"),
|
---|
[332] | 1295 | score)
|
---|
[11] | 1296 |
|
---|
| 1297 | #---------------------------------------------------------------------------------------
|
---|
| 1298 |
|
---|
| 1299 | class ReverserChecker(SimpleFaultChecker):
|
---|
[360] | 1300 | """Check if the reverser is not used below the speed prescribed for the
|
---|
| 1301 | aircraft."""
|
---|
[11] | 1302 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1303 | """Check if the fault condition holds."""
|
---|
| 1304 | return flight.stage in [const.STAGE_DESCENT, const.STAGE_LANDING,
|
---|
| 1305 | const.STAGE_TAXIAFTERLAND] and \
|
---|
[360] | 1306 | state.groundSpeed<aircraft.reverseMinSpeed and max(state.reverser)
|
---|
[332] | 1307 |
|
---|
[11] | 1308 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1309 | """Log the fault."""
|
---|
[241] | 1310 | message = "Reverser used below %.0f %s" % \
|
---|
| 1311 | (flight.speedFromKnots(60), flight.getEnglishSpeedUnit())
|
---|
[30] | 1312 | flight.handleFault(ReverserChecker, state.timestamp,
|
---|
[241] | 1313 | FaultChecker._appendDuring(flight, message),
|
---|
| 1314 | 15)
|
---|
[11] | 1315 |
|
---|
| 1316 | #---------------------------------------------------------------------------------------
|
---|
| 1317 |
|
---|
| 1318 | class SpeedChecker(SimpleFaultChecker):
|
---|
| 1319 | """Check if the speed is in the prescribed limits."""
|
---|
[344] | 1320 | @staticmethod
|
---|
[349] | 1321 | def logSpeedFault(flight, state, stage = None, updateID = None):
|
---|
[344] | 1322 | """Log the speed fault."""
|
---|
| 1323 | message = "Taxi speed over %.0f %s" % \
|
---|
| 1324 | (flight.speedFromKnots(50), flight.getEnglishSpeedUnit())
|
---|
[349] | 1325 | if stage is None:
|
---|
| 1326 | stage = flight.stage
|
---|
| 1327 | score = FaultChecker._getLinearScore(50, 80, 10, 15, state.groundSpeed)
|
---|
| 1328 | return flight.handleFault((SpeedChecker, stage), state.timestamp,
|
---|
| 1329 | FaultChecker._appendDuring(flight, message),
|
---|
| 1330 | score, updatePrevious = updateID is None,
|
---|
| 1331 | updateID = updateID)
|
---|
[344] | 1332 |
|
---|
[11] | 1333 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1334 | """Check if the fault condition holds."""
|
---|
| 1335 | return flight.stage in [const.STAGE_PUSHANDTAXI,
|
---|
[354] | 1336 | const.STAGE_RTO,
|
---|
[11] | 1337 | const.STAGE_TAXIAFTERLAND] and \
|
---|
| 1338 | state.groundSpeed>50
|
---|
[332] | 1339 |
|
---|
[11] | 1340 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1341 | """Log the fault."""
|
---|
[344] | 1342 | self.logSpeedFault(flight, state)
|
---|
| 1343 |
|
---|
| 1344 | #---------------------------------------------------------------------------------------
|
---|
| 1345 |
|
---|
| 1346 | class NoStrobeSpeedChecker(StateChecker):
|
---|
| 1347 | """Checker for the ground speed of aircraft that have no strobe lights by
|
---|
| 1348 | which to detect the takeoff stage.
|
---|
| 1349 |
|
---|
| 1350 | If, during the PUSHANDTAXI stage the speed exceeds 50 knots, the state as
|
---|
| 1351 | saved as a provisional takeoff state. If the speed then decreases below 50
|
---|
| 1352 | knots, or the plane remains on the ground for more than 20 seconds, a taxi
|
---|
[349] | 1353 | speed error is logged with the highest ground speed detected. This state is
|
---|
| 1354 | also stored in the flight object as a possible
|
---|
[344] | 1355 |
|
---|
| 1356 | If the plane becomes airborne within 20 seconds, the stage becomes TAKEOFF,
|
---|
| 1357 | and the previously saved takeoff state is logged.
|
---|
| 1358 |
|
---|
| 1359 | During the TAXIAFTERLAND stage, speed is checked as in case of
|
---|
| 1360 | SpeedChecker."""
|
---|
| 1361 | def __init__(self):
|
---|
| 1362 | """Initialize the speed checker."""
|
---|
| 1363 | self._takeoffState = None
|
---|
| 1364 | self._highestSpeedState = None
|
---|
| 1365 |
|
---|
| 1366 | def check(self, flight, aircraft, logger, oldState, state):
|
---|
| 1367 | """Check the state as described above."""
|
---|
[354] | 1368 | if flight.stage==const.STAGE_PUSHANDTAXI or \
|
---|
| 1369 | flight.stage==const.STAGE_RTO:
|
---|
[344] | 1370 | self._checkPushAndTaxi(flight, aircraft, state)
|
---|
| 1371 | elif flight.stage==const.STAGE_TAXIAFTERLAND:
|
---|
| 1372 | if state.groundSpeed>50:
|
---|
| 1373 | SpeedChecker.logSpeedFault(flight, state)
|
---|
| 1374 |
|
---|
| 1375 | def _checkPushAndTaxi(self, flight, aircraft, state):
|
---|
| 1376 | """Check the speed during the push and taxi stage."""
|
---|
| 1377 | if state.groundSpeed>50:
|
---|
| 1378 | if self._takeoffState is None:
|
---|
| 1379 | self._takeoffState = state
|
---|
| 1380 | self._highestSpeedState = state
|
---|
| 1381 | else:
|
---|
| 1382 | if state.groundSpeed>self._highestSpeedState.groundSpeed:
|
---|
| 1383 | self._highestSpeedState = state
|
---|
| 1384 |
|
---|
[414] | 1385 | if not state.onTheGround:
|
---|
[344] | 1386 | aircraft.setStage(self._takeoffState, const.STAGE_TAKEOFF)
|
---|
| 1387 | self._takeoffState = None
|
---|
[414] | 1388 | elif state.timestamp > (self._takeoffState.timestamp + 30):
|
---|
| 1389 | flight.setRTOState(self._highestSpeedState)
|
---|
[344] | 1390 | elif self._takeoffState is not None:
|
---|
[349] | 1391 | flight.setRTOState(self._highestSpeedState)
|
---|
[344] | 1392 | self._takeoffState = None
|
---|
[11] | 1393 |
|
---|
| 1394 | #---------------------------------------------------------------------------------------
|
---|
| 1395 |
|
---|
| 1396 | class StallChecker(PatientFaultChecker):
|
---|
| 1397 | """Check if stall occured."""
|
---|
| 1398 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1399 | """Check if the fault condition holds."""
|
---|
| 1400 | return flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
|
---|
| 1401 | const.STAGE_CRUISE, const.STAGE_DESCENT,
|
---|
| 1402 | const.STAGE_LANDING] and state.stalled
|
---|
[332] | 1403 |
|
---|
[11] | 1404 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1405 | """Log the fault."""
|
---|
| 1406 | score = 40 if flight.stage in [const.STAGE_TAKEOFF,
|
---|
| 1407 | const.STAGE_LANDING] else 30
|
---|
[30] | 1408 | flight.handleFault(StallChecker, state.timestamp,
|
---|
| 1409 | FaultChecker._appendDuring(flight, "Stalled"),
|
---|
[332] | 1410 | score)
|
---|
[11] | 1411 |
|
---|
| 1412 | #---------------------------------------------------------------------------------------
|
---|
| 1413 |
|
---|
| 1414 | class StrobeLightsChecker(PatientFaultChecker):
|
---|
| 1415 | """Check if the strobe lights are used properly."""
|
---|
| 1416 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1417 | """Check if the fault condition holds."""
|
---|
[211] | 1418 | return (flight.stage==const.STAGE_BOARDING and \
|
---|
| 1419 | state.strobeLightsOn and state.onTheGround) or \
|
---|
| 1420 | (flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 1421 | not state.strobeLightsOn and not state.gearsDown) or \
|
---|
| 1422 | (flight.stage in [const.STAGE_CLIMB, const.STAGE_CRUISE,
|
---|
| 1423 | const.STAGE_DESCENT] and \
|
---|
| 1424 | not state.strobeLightsOn and not state.onTheGround) or \
|
---|
| 1425 | (flight.stage==const.STAGE_PARKING and \
|
---|
| 1426 | state.strobeLightsOn and state.onTheGround)
|
---|
[332] | 1427 |
|
---|
[11] | 1428 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1429 | """Log the fault."""
|
---|
| 1430 | message = "Strobe lights were %s" % (("on" if state.strobeLightsOn else "off"),)
|
---|
[30] | 1431 | flight.handleFault(StrobeLightsChecker, state.timestamp,
|
---|
| 1432 | FaultChecker._appendDuring(flight, message),
|
---|
| 1433 | 1)
|
---|
[11] | 1434 |
|
---|
| 1435 | #---------------------------------------------------------------------------------------
|
---|
| 1436 |
|
---|
| 1437 | class ThrustChecker(SimpleFaultChecker):
|
---|
| 1438 | """Check if the thrust setting is not too high during takeoff.
|
---|
| 1439 |
|
---|
| 1440 | FIXME: is this really so general, for all aircraft?"""
|
---|
| 1441 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1442 | """Check if the fault condition holds."""
|
---|
[263] | 1443 | return flight.stage==const.STAGE_TAKEOFF and \
|
---|
| 1444 | state.n1 is not None and max(state.n1)>97
|
---|
[332] | 1445 |
|
---|
[11] | 1446 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1447 | """Log the fault."""
|
---|
[30] | 1448 | flight.handleFault(ThrustChecker, state.timestamp,
|
---|
| 1449 | FaultChecker._appendDuring(flight,
|
---|
| 1450 | "Thrust setting was too high (>97%)"),
|
---|
[405] | 1451 | FaultChecker._getLinearScore(97, 110, 0, 10,
|
---|
| 1452 | max(state.n1)),
|
---|
| 1453 | updatePrevious = True)
|
---|
[11] | 1454 |
|
---|
| 1455 | #---------------------------------------------------------------------------------------
|
---|
| 1456 |
|
---|
| 1457 | class VSChecker(SimpleFaultChecker):
|
---|
| 1458 | """Check if the vertical speed is not too low at certain altitudes"""
|
---|
| 1459 | BELOW10000 = -5000
|
---|
| 1460 | BELOW5000 = -2500
|
---|
| 1461 | BELOW2500 = -1500
|
---|
| 1462 | BELOW500 = -1000
|
---|
| 1463 | TOLERANCE = 1.2
|
---|
| 1464 |
|
---|
| 1465 | def isCondition(self, flight, aircraft, oldState, state):
|
---|
| 1466 | """Check if the fault condition holds."""
|
---|
[197] | 1467 | vs = state.smoothedVS
|
---|
[11] | 1468 | altitude = state.altitude
|
---|
| 1469 | return vs < -8000 or vs > 8000 or \
|
---|
| 1470 | (altitude<500 and vs < (VSChecker.BELOW500 *
|
---|
[13] | 1471 | VSChecker.TOLERANCE)) or \
|
---|
[11] | 1472 | (altitude<2500 and vs < (VSChecker.BELOW2500 *
|
---|
[13] | 1473 | VSChecker.TOLERANCE)) or \
|
---|
[11] | 1474 | (altitude<5000 and vs < (VSChecker.BELOW5000 *
|
---|
[13] | 1475 | VSChecker.TOLERANCE)) or \
|
---|
[11] | 1476 | (altitude<10000 and vs < (VSChecker.BELOW10000 *
|
---|
[13] | 1477 | VSChecker.TOLERANCE))
|
---|
[332] | 1478 |
|
---|
[11] | 1479 | def logFault(self, flight, aircraft, logger, oldState, state):
|
---|
| 1480 | """Log the fault."""
|
---|
[197] | 1481 | vs = state.smoothedVS
|
---|
[11] | 1482 |
|
---|
| 1483 | message = "Vertical speed was %.0f feet/min" % (vs,)
|
---|
| 1484 | if vs>-8000 and vs<8000:
|
---|
| 1485 | message += " at %.0f feet (exceeds company limit)" % (state.altitude,)
|
---|
| 1486 |
|
---|
| 1487 | score = 10 if vs<-8000 or vs>8000 else 0
|
---|
| 1488 |
|
---|
[30] | 1489 | flight.handleFault(VSChecker, state.timestamp,
|
---|
| 1490 | FaultChecker._appendDuring(flight, message),
|
---|
| 1491 | score)
|
---|
[11] | 1492 |
|
---|
| 1493 | #---------------------------------------------------------------------------------------
|
---|