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