[8] | 1 |
|
---|
[176] | 2 | from soundsched import SoundScheduler, ChecklistScheduler
|
---|
[349] | 3 | from checks import SpeedChecker
|
---|
[170] | 4 |
|
---|
[8] | 5 | import const
|
---|
[89] | 6 | import util
|
---|
[8] | 7 |
|
---|
| 8 | import threading
|
---|
| 9 |
|
---|
| 10 | #---------------------------------------------------------------------------------------
|
---|
| 11 |
|
---|
[298] | 12 | ## @package mlx.flight
|
---|
| 13 | #
|
---|
| 14 | # The global flight state.
|
---|
| 15 | #
|
---|
| 16 | # This module defines a single class, \ref Flight, which represents the flight
|
---|
| 17 | # in progress.
|
---|
| 18 |
|
---|
| 19 | #---------------------------------------------------------------------------------------
|
---|
| 20 |
|
---|
[8] | 21 | class Flight(object):
|
---|
| 22 | """The object with the global flight state.
|
---|
[348] | 23 |
|
---|
[8] | 24 | It is also the hub for the other main objects participating in the handling of
|
---|
| 25 | the flight."""
|
---|
[29] | 26 | def __init__(self, logger, gui):
|
---|
[8] | 27 | """Construct the flight."""
|
---|
| 28 | self._stage = None
|
---|
| 29 | self.logger = logger
|
---|
[29] | 30 | self._gui = gui
|
---|
[11] | 31 |
|
---|
[31] | 32 | gui.resetFlightStatus()
|
---|
| 33 |
|
---|
[170] | 34 | self._pilotHotkeyPressed = False
|
---|
| 35 | self._checklistHotkeyPressed = False
|
---|
| 36 |
|
---|
[9] | 37 | self.flareTimeFromFS = False
|
---|
[11] | 38 |
|
---|
[8] | 39 | self.aircraftType = None
|
---|
| 40 | self.aircraft = None
|
---|
| 41 | self.simulator = None
|
---|
| 42 |
|
---|
[89] | 43 | self.blockTimeStart = None
|
---|
| 44 | self.flightTimeStart = None
|
---|
[365] | 45 | self.climbTimeStart = None
|
---|
| 46 | self.cruiseTimeStart = None
|
---|
| 47 | self.descentTimeStart = None
|
---|
[89] | 48 | self.flightTimeEnd = None
|
---|
| 49 | self.blockTimeEnd = None
|
---|
| 50 |
|
---|
[349] | 51 | self._rtoState = None
|
---|
| 52 | self._rtoLogEntryID = None
|
---|
| 53 |
|
---|
[89] | 54 | self._lastDistanceTime = None
|
---|
| 55 | self._previousLatitude = None
|
---|
| 56 | self._previousLongitude = None
|
---|
| 57 | self.flownDistance = 0.0
|
---|
| 58 |
|
---|
| 59 | self.startFuel = None
|
---|
| 60 | self.endFuel = None
|
---|
| 61 |
|
---|
[8] | 62 | self._endCondition = threading.Condition()
|
---|
| 63 |
|
---|
[9] | 64 | self._flareStart = None
|
---|
| 65 | self._flareStartFS = None
|
---|
| 66 |
|
---|
[170] | 67 | self._tdRate = None
|
---|
| 68 |
|
---|
[176] | 69 | self._soundScheduler = SoundScheduler(self)
|
---|
| 70 | self._checklistScheduler = ChecklistScheduler(self)
|
---|
| 71 |
|
---|
[8] | 72 | @property
|
---|
[134] | 73 | def config(self):
|
---|
| 74 | """Get the configuration."""
|
---|
| 75 | return self._gui.config
|
---|
| 76 |
|
---|
| 77 | @property
|
---|
[8] | 78 | def stage(self):
|
---|
| 79 | """Get the flight stage."""
|
---|
| 80 | return self._stage
|
---|
| 81 |
|
---|
[84] | 82 | @property
|
---|
[215] | 83 | def loggedIn(self):
|
---|
| 84 | """Indicate if the user has logged in properly."""
|
---|
| 85 | return self._gui.loggedIn
|
---|
| 86 |
|
---|
| 87 | @property
|
---|
[184] | 88 | def entranceExam(self):
|
---|
| 89 | """Get whether an entrance exam is being performed."""
|
---|
| 90 | return self._gui.entranceExam
|
---|
| 91 |
|
---|
| 92 | @property
|
---|
[134] | 93 | def bookedFlight(self):
|
---|
| 94 | """Get the booked flight."""
|
---|
| 95 | return self._gui.bookedFlight
|
---|
| 96 |
|
---|
| 97 | @property
|
---|
[303] | 98 | def numCrew(self):
|
---|
| 99 | """Get the number of crew members on the flight."""
|
---|
| 100 | return self._gui.numCrew
|
---|
| 101 |
|
---|
| 102 | @property
|
---|
| 103 | def numPassengers(self):
|
---|
| 104 | """Get the number of passengers on the flight."""
|
---|
| 105 | return self._gui.numPassengers
|
---|
| 106 |
|
---|
| 107 | @property
|
---|
| 108 | def bagWeight(self):
|
---|
| 109 | """Get the baggage weight for the flight."""
|
---|
| 110 | return self._gui.bagWeight
|
---|
| 111 |
|
---|
| 112 | @property
|
---|
[262] | 113 | def cargoWeight(self):
|
---|
| 114 | """Get the cargo weight for the flight."""
|
---|
| 115 | return self._gui.cargoWeight
|
---|
| 116 |
|
---|
| 117 | @property
|
---|
[303] | 118 | def mailWeight(self):
|
---|
| 119 | """Get the mail weight for the flight."""
|
---|
| 120 | return self._gui.mailWeight
|
---|
| 121 |
|
---|
| 122 | @property
|
---|
[84] | 123 | def zfw(self):
|
---|
| 124 | """Get the Zero-Fuel Weight of the flight."""
|
---|
| 125 | return self._gui.zfw
|
---|
| 126 |
|
---|
| 127 | @property
|
---|
[262] | 128 | def filedCruiseAltitude(self):
|
---|
| 129 | """Get the filed cruise altitude."""
|
---|
| 130 | return self._gui.filedCruiseAltitude
|
---|
| 131 |
|
---|
| 132 | @property
|
---|
[84] | 133 | def cruiseAltitude(self):
|
---|
| 134 | """Get the cruise altitude of the flight."""
|
---|
| 135 | return self._gui.cruiseAltitude
|
---|
| 136 |
|
---|
| 137 | @property
|
---|
[262] | 138 | def route(self):
|
---|
| 139 | """Get the route of the flight."""
|
---|
| 140 | return self._gui.route
|
---|
| 141 |
|
---|
| 142 | @property
|
---|
| 143 | def departureMETAR(self):
|
---|
| 144 | """Get the departure METAR of the flight."""
|
---|
| 145 | return self._gui.departureMETAR
|
---|
| 146 |
|
---|
| 147 | @property
|
---|
| 148 | def arrivalMETAR(self):
|
---|
| 149 | """Get the arrival METAR of the flight."""
|
---|
| 150 | return self._gui.arrivalMETAR
|
---|
| 151 |
|
---|
| 152 | @property
|
---|
| 153 | def departureRunway(self):
|
---|
| 154 | """Get the departure runway."""
|
---|
| 155 | return self._gui.departureRunway
|
---|
| 156 |
|
---|
| 157 | @property
|
---|
| 158 | def sid(self):
|
---|
| 159 | """Get the SID followed."""
|
---|
| 160 | return self._gui.sid
|
---|
| 161 |
|
---|
| 162 | @property
|
---|
[84] | 163 | def v1(self):
|
---|
| 164 | """Get the V1 speed of the flight."""
|
---|
| 165 | return self._gui.v1
|
---|
| 166 |
|
---|
| 167 | @property
|
---|
| 168 | def vr(self):
|
---|
| 169 | """Get the Vr speed of the flight."""
|
---|
| 170 | return self._gui.vr
|
---|
| 171 |
|
---|
| 172 | @property
|
---|
| 173 | def v2(self):
|
---|
| 174 | """Get the V2 speed of the flight."""
|
---|
| 175 | return self._gui.v2
|
---|
| 176 |
|
---|
[86] | 177 | @property
|
---|
[262] | 178 | def star(self):
|
---|
| 179 | """Get the STAR planned."""
|
---|
| 180 | return self._gui.star
|
---|
| 181 |
|
---|
| 182 | @property
|
---|
| 183 | def transition(self):
|
---|
| 184 | """Get the transition planned."""
|
---|
| 185 | return self._gui.transition
|
---|
| 186 |
|
---|
| 187 | @property
|
---|
| 188 | def approachType(self):
|
---|
| 189 | """Get the approach type."""
|
---|
| 190 | return self._gui.approachType
|
---|
| 191 |
|
---|
| 192 | @property
|
---|
| 193 | def arrivalRunway(self):
|
---|
| 194 | """Get the arrival runway."""
|
---|
| 195 | return self._gui.arrivalRunway
|
---|
| 196 |
|
---|
| 197 | @property
|
---|
[86] | 198 | def vref(self):
|
---|
| 199 | """Get the VRef speed of the flight."""
|
---|
| 200 | return self._gui.vref
|
---|
| 201 |
|
---|
[170] | 202 | @property
|
---|
| 203 | def tdRate(self):
|
---|
| 204 | """Get the touchdown rate if known, None otherwise."""
|
---|
| 205 | return self._tdRate
|
---|
| 206 |
|
---|
[241] | 207 | @property
|
---|
[262] | 208 | def flightType(self):
|
---|
| 209 | """Get the type of the flight."""
|
---|
| 210 | return self._gui.flightType
|
---|
| 211 |
|
---|
| 212 | @property
|
---|
| 213 | def online(self):
|
---|
| 214 | """Get whether the flight was an online flight."""
|
---|
| 215 | return self._gui.online
|
---|
| 216 |
|
---|
| 217 | @property
|
---|
| 218 | def comments(self):
|
---|
| 219 | """Get the comments made by the pilot."""
|
---|
| 220 | return self._gui.comments
|
---|
| 221 |
|
---|
| 222 | @property
|
---|
| 223 | def flightDefects(self):
|
---|
| 224 | """Get the flight defects reported by the pilot."""
|
---|
| 225 | return self._gui.flightDefects
|
---|
| 226 |
|
---|
| 227 | @property
|
---|
| 228 | def delayCodes(self):
|
---|
| 229 | """Get the delay codes."""
|
---|
| 230 | return self._gui.delayCodes
|
---|
| 231 |
|
---|
| 232 | @property
|
---|
[241] | 233 | def speedInKnots(self):
|
---|
| 234 | """Determine if the speeds for the flight are to be expressed in
|
---|
| 235 | knots."""
|
---|
| 236 | return self.aircraft.speedInKnots if self.aircraft is not None \
|
---|
| 237 | else True
|
---|
| 238 |
|
---|
[349] | 239 | @property
|
---|
| 240 | def hasRTO(self):
|
---|
| 241 | """Determine if we have an RTO state."""
|
---|
| 242 | return self._rtoState is not None
|
---|
| 243 |
|
---|
| 244 | @property
|
---|
| 245 | def rtoState(self):
|
---|
| 246 | """Get the RTO state."""
|
---|
| 247 | return self._rtoState
|
---|
| 248 |
|
---|
[89] | 249 | def handleState(self, oldState, currentState):
|
---|
| 250 | """Handle a new state information."""
|
---|
| 251 | self._updateFlownDistance(currentState)
|
---|
[348] | 252 |
|
---|
[274] | 253 | self.endFuel = currentState.totalFuel
|
---|
[89] | 254 | if self.startFuel is None:
|
---|
| 255 | self.startFuel = self.endFuel
|
---|
[348] | 256 |
|
---|
[170] | 257 | self._soundScheduler.schedule(currentState,
|
---|
| 258 | self._pilotHotkeyPressed)
|
---|
| 259 | self._pilotHotkeyPressed = False
|
---|
[89] | 260 |
|
---|
[176] | 261 | if self._checklistHotkeyPressed:
|
---|
| 262 | self._checklistScheduler.hotkeyPressed()
|
---|
| 263 | self._checklistHotkeyPressed = False
|
---|
| 264 |
|
---|
[8] | 265 | def setStage(self, timestamp, stage):
|
---|
[9] | 266 | """Set the flight stage.
|
---|
| 267 |
|
---|
| 268 | Returns if the stage has really changed."""
|
---|
[8] | 269 | if stage!=self._stage:
|
---|
[365] | 270 | self._logStageDuration(timestamp, stage)
|
---|
[8] | 271 | self._stage = stage
|
---|
[84] | 272 | self._gui.setStage(stage)
|
---|
[8] | 273 | self.logger.stage(timestamp, stage)
|
---|
[89] | 274 | if stage==const.STAGE_PUSHANDTAXI:
|
---|
| 275 | self.blockTimeStart = timestamp
|
---|
| 276 | elif stage==const.STAGE_TAKEOFF:
|
---|
| 277 | self.flightTimeStart = timestamp
|
---|
[365] | 278 | elif stage==const.STAGE_CLIMB:
|
---|
| 279 | self.climbTimeStart = timestamp
|
---|
| 280 | elif stage==const.STAGE_CRUISE:
|
---|
| 281 | self.cruiseTimeStart = timestamp
|
---|
| 282 | elif stage==const.STAGE_DESCENT:
|
---|
| 283 | self.descentTimeStart = timestamp
|
---|
[89] | 284 | elif stage==const.STAGE_TAXIAFTERLAND:
|
---|
| 285 | self.flightTimeEnd = timestamp
|
---|
[359] | 286 | # elif stage==const.STAGE_PARKING:
|
---|
| 287 | # self.blockTimeEnd = timestamp
|
---|
| 288 | elif stage==const.STAGE_END:
|
---|
[89] | 289 | self.blockTimeEnd = timestamp
|
---|
[8] | 290 | with self._endCondition:
|
---|
| 291 | self._endCondition.notify()
|
---|
[9] | 292 | return True
|
---|
| 293 | else:
|
---|
| 294 | return False
|
---|
| 295 |
|
---|
[346] | 296 | def handleFault(self, faultID, timestamp, what, score,
|
---|
[349] | 297 | updatePrevious = False, updateID = None):
|
---|
[30] | 298 | """Handle the given fault.
|
---|
| 299 |
|
---|
| 300 | faultID as a unique ID for the given kind of fault. If another fault of
|
---|
| 301 | this ID has been reported earlier, it will be reported again only if
|
---|
| 302 | the score is greater than last time. This ID can be, e.g. the checker
|
---|
| 303 | the report comes from."""
|
---|
[349] | 304 | id = self.logger.fault(faultID, timestamp, what, score,
|
---|
| 305 | updatePrevious = updatePrevious,
|
---|
| 306 | updateID = updateID)
|
---|
[31] | 307 | self._gui.setRating(self.logger.getRating())
|
---|
[349] | 308 | return id
|
---|
[30] | 309 |
|
---|
| 310 | def handleNoGo(self, faultID, timestamp, what, shortReason):
|
---|
| 311 | """Handle a No-Go fault."""
|
---|
| 312 | self.logger.noGo(faultID, timestamp, what)
|
---|
[31] | 313 | self._gui.setNoGo(shortReason)
|
---|
[30] | 314 |
|
---|
[349] | 315 | def setRTOState(self, state):
|
---|
| 316 | """Set the state that might be used as the RTO state.
|
---|
| 317 |
|
---|
| 318 | If there has been no RTO state, the GUI is notified that from now on
|
---|
| 319 | the user may select to report an RTO."""
|
---|
| 320 | hadNoRTOState = self._rtoState is None
|
---|
| 321 |
|
---|
| 322 | self._rtoState = state
|
---|
| 323 | self._rtoLogEntryID = \
|
---|
| 324 | SpeedChecker.logSpeedFault(self, state,
|
---|
| 325 | stage = const.STAGE_PUSHANDTAXI)
|
---|
| 326 |
|
---|
| 327 | if hadNoRTOState:
|
---|
| 328 | self._gui.updateRTO()
|
---|
| 329 |
|
---|
| 330 | def rtoToggled(self, indicated):
|
---|
| 331 | """Called when the user has toggled the RTO indication."""
|
---|
| 332 | if self._rtoState is not None:
|
---|
| 333 | if indicated:
|
---|
| 334 | self.logger.clearFault(self._rtoLogEntryID,
|
---|
| 335 | "RTO at %d knots" %
|
---|
| 336 | (self._rtoState.groundSpeed,))
|
---|
| 337 | self._gui.setRating(self.logger.getRating())
|
---|
[354] | 338 | if self._stage == const.STAGE_PUSHANDTAXI:
|
---|
| 339 | self.setStage(self.aircraft.state.timestamp,
|
---|
| 340 | const.STAGE_RTO)
|
---|
[349] | 341 | else:
|
---|
| 342 | SpeedChecker.logSpeedFault(self, self._rtoState,
|
---|
| 343 | stage = const.STAGE_PUSHANDTAXI,
|
---|
| 344 | updateID = self._rtoLogEntryID)
|
---|
[354] | 345 | if self._stage == const.STAGE_RTO:
|
---|
| 346 | self.setStage(self.aircraft.state.timestamp,
|
---|
| 347 | const.STAGE_PUSHANDTAXI)
|
---|
[349] | 348 |
|
---|
[9] | 349 | def flareStarted(self, flareStart, flareStartFS):
|
---|
| 350 | """Called when the flare time has started."""
|
---|
| 351 | self._flareStart = flareStart
|
---|
| 352 | self._flareStartFS = flareStartFS
|
---|
| 353 |
|
---|
[170] | 354 | def flareFinished(self, flareEnd, flareEndFS, tdRate):
|
---|
[9] | 355 | """Called when the flare time has ended.
|
---|
[348] | 356 |
|
---|
[9] | 357 | Return a tuple of the following items:
|
---|
| 358 | - a boolean indicating if FS time is used
|
---|
| 359 | - the flare time
|
---|
| 360 | """
|
---|
[170] | 361 | self._tdRate = tdRate
|
---|
[9] | 362 | if self.flareTimeFromFS:
|
---|
| 363 | return (True, flareEndFS - self._flareStartFS)
|
---|
| 364 | else:
|
---|
| 365 | return (False, flareEnd - self._flareStart)
|
---|
[8] | 366 |
|
---|
| 367 | def wait(self):
|
---|
| 368 | """Wait for the flight to end."""
|
---|
| 369 | with self._endCondition:
|
---|
| 370 | while self._stage!=const.STAGE_END:
|
---|
[14] | 371 | self._endCondition.wait(1)
|
---|
[8] | 372 |
|
---|
[134] | 373 | def getFleet(self, callback, force = False):
|
---|
| 374 | """Get the fleet and call the given callback."""
|
---|
| 375 | self._gui.getFleetAsync(callback = callback, force = force)
|
---|
| 376 |
|
---|
[170] | 377 | def pilotHotkeyPressed(self):
|
---|
| 378 | """Called when the pilot hotkey is pressed."""
|
---|
| 379 | self._pilotHotkeyPressed = True
|
---|
| 380 |
|
---|
| 381 | def checklistHotkeyPressed(self):
|
---|
| 382 | """Called when the checklist hotkey is pressed."""
|
---|
| 383 | self._checklistHotkeyPressed = True
|
---|
| 384 |
|
---|
[241] | 385 | def speedFromKnots(self, knots):
|
---|
| 386 | """Convert the given speed value expressed in knots into the flight's
|
---|
| 387 | speed unit."""
|
---|
| 388 | return knots if self.speedInKnots else knots * const.KNOTSTOKMPH
|
---|
| 389 |
|
---|
| 390 | def speedToKnots(self, speed):
|
---|
| 391 | """Convert the given speed expressed in the flight's speed unit into
|
---|
[348] | 392 | knots."""
|
---|
[241] | 393 | return speed if self.speedInKnots else speed * const.KMPHTOKNOTS
|
---|
| 394 |
|
---|
| 395 | def getEnglishSpeedUnit(self):
|
---|
| 396 | """Get the English name of the speed unit used by the flight."""
|
---|
| 397 | return "knots" if self.speedInKnots else "km/h"
|
---|
| 398 |
|
---|
| 399 | def getI18NSpeedUnit(self):
|
---|
| 400 | """Get the speed unit suffix for i18n message identifiers."""
|
---|
| 401 | return "_knots" if self.speedInKnots else "_kmph"
|
---|
| 402 |
|
---|
[274] | 403 | def logFuel(self, aircraftState):
|
---|
| 404 | """Log the amount of fuel"""
|
---|
| 405 | fuelStr = ""
|
---|
| 406 | for (tank, amount) in aircraftState.fuel:
|
---|
| 407 | if fuelStr: fuelStr += " - "
|
---|
| 408 | fuelStr += "%s=%.0f kg" % (const.fuelTank2logString(tank), amount)
|
---|
[348] | 409 |
|
---|
[274] | 410 | self.logger.message(aircraftState.timestamp, "Fuel: " + fuelStr)
|
---|
| 411 | self.logger.message(aircraftState.timestamp,
|
---|
[348] | 412 | "Total fuel: %.0f kg" % (aircraftState.totalFuel,))
|
---|
[274] | 413 |
|
---|
[304] | 414 | def cruiseLevelChanged(self):
|
---|
| 415 | """Called when the cruise level hass changed."""
|
---|
| 416 | if self._stage in [const.STAGE_CRUISE, const.STAGE_DESCENT,
|
---|
| 417 | const.STAGE_LANDING]:
|
---|
| 418 | message = "Cruise altitude modified to %d feet" % \
|
---|
| 419 | (self.cruiseAltitude,)
|
---|
| 420 | self.logger.message(self.aircraft.timestamp, message)
|
---|
| 421 |
|
---|
[89] | 422 | def _updateFlownDistance(self, currentState):
|
---|
| 423 | """Update the flown distance."""
|
---|
| 424 | if not currentState.onTheGround:
|
---|
| 425 | updateData = False
|
---|
| 426 | if self._lastDistanceTime is None or \
|
---|
| 427 | self._previousLatitude is None or \
|
---|
| 428 | self._previousLongitude is None:
|
---|
| 429 | updateData = True
|
---|
| 430 | elif currentState.timestamp >= (self._lastDistanceTime + 30.0):
|
---|
| 431 | updateData = True
|
---|
| 432 | self.flownDistance += self._getDistance(currentState)
|
---|
| 433 |
|
---|
| 434 | if updateData:
|
---|
| 435 | self._previousLatitude = currentState.latitude
|
---|
| 436 | self._previousLongitude = currentState.longitude
|
---|
| 437 | self._lastDistanceTime = currentState.timestamp
|
---|
| 438 | else:
|
---|
| 439 | if self._lastDistanceTime is not None and \
|
---|
| 440 | self._previousLatitude is not None and \
|
---|
| 441 | self._previousLongitude is not None:
|
---|
| 442 | self.flownDistance += self._getDistance(currentState)
|
---|
[348] | 443 |
|
---|
[89] | 444 | self._lastDistanceTime = None
|
---|
| 445 |
|
---|
| 446 | def _getDistance(self, currentState):
|
---|
| 447 | """Get the distance between the previous and the current state."""
|
---|
| 448 | return util.getDistCourse(self._previousLatitude, self._previousLongitude,
|
---|
| 449 | currentState.latitude, currentState.longitude)[0]
|
---|
| 450 |
|
---|
[365] | 451 | def _logStageDuration(self, timestamp, stage):
|
---|
| 452 | """Log the duration of the stage preceding the given one."""
|
---|
| 453 | what = None
|
---|
| 454 | startTime = None
|
---|
| 455 |
|
---|
| 456 | if stage==const.STAGE_TAKEOFF:
|
---|
| 457 | what = "Pushback and taxi"
|
---|
| 458 | startTime = self.blockTimeStart
|
---|
| 459 | elif stage==const.STAGE_CRUISE:
|
---|
| 460 | what = "Climb"
|
---|
| 461 | startTime = self.climbTimeStart
|
---|
| 462 | elif stage==const.STAGE_DESCENT:
|
---|
| 463 | what = "Cruise"
|
---|
| 464 | startTime = self.cruiseTimeStart
|
---|
| 465 | elif stage==const.STAGE_LANDING:
|
---|
| 466 | what = "Descent"
|
---|
| 467 | startTime = self.descentTimeStart
|
---|
| 468 | elif stage==const.STAGE_END:
|
---|
| 469 | what = "Taxi after landing"
|
---|
| 470 | startTime = self.flightTimeEnd
|
---|
| 471 |
|
---|
| 472 | if what is not None and startTime is not None:
|
---|
| 473 | duration = timestamp - startTime
|
---|
| 474 | self.logger.message(timestamp,
|
---|
| 475 | "%s time: %s" % \
|
---|
| 476 | (what, util.getTimeIntervalString(duration)))
|
---|
| 477 |
|
---|
[8] | 478 | #---------------------------------------------------------------------------------------
|
---|