[8] | 1 | # Module related to the high-level tracking of the flight
|
---|
| 2 |
|
---|
| 3 | #---------------------------------------------------------------------------------------
|
---|
| 4 |
|
---|
[170] | 5 | from soundsched import SoundScheduler
|
---|
| 6 |
|
---|
[8] | 7 | import const
|
---|
[89] | 8 | import util
|
---|
[8] | 9 |
|
---|
| 10 | import threading
|
---|
| 11 |
|
---|
| 12 | #---------------------------------------------------------------------------------------
|
---|
| 13 |
|
---|
[11] | 14 | class Options(object):
|
---|
| 15 | """Various configuration options."""
|
---|
| 16 | def __init__(self):
|
---|
| 17 | """Construct the object with default values."""
|
---|
| 18 | self.fs2Crew = False
|
---|
| 19 | self.compensation = None
|
---|
| 20 |
|
---|
| 21 | #---------------------------------------------------------------------------------------
|
---|
| 22 |
|
---|
[8] | 23 | class Flight(object):
|
---|
| 24 | """The object with the global flight state.
|
---|
| 25 |
|
---|
| 26 | It is also the hub for the other main objects participating in the handling of
|
---|
| 27 | the flight."""
|
---|
[29] | 28 | def __init__(self, logger, gui):
|
---|
[8] | 29 | """Construct the flight."""
|
---|
| 30 | self._stage = None
|
---|
| 31 | self.logger = logger
|
---|
[29] | 32 | self._gui = gui
|
---|
[11] | 33 |
|
---|
[31] | 34 | gui.resetFlightStatus()
|
---|
| 35 |
|
---|
[170] | 36 | self._soundScheduler = SoundScheduler(self)
|
---|
| 37 | self._pilotHotkeyPressed = False
|
---|
| 38 | self._checklistHotkeyPressed = False
|
---|
| 39 |
|
---|
[9] | 40 | self.flareTimeFromFS = False
|
---|
[11] | 41 | self.entranceExam = False
|
---|
| 42 |
|
---|
| 43 | self.options = Options()
|
---|
| 44 |
|
---|
[8] | 45 | self.aircraftType = None
|
---|
| 46 | self.aircraft = None
|
---|
| 47 | self.simulator = None
|
---|
| 48 |
|
---|
[89] | 49 | self.blockTimeStart = None
|
---|
| 50 | self.flightTimeStart = None
|
---|
| 51 | self.flightTimeEnd = None
|
---|
| 52 | self.blockTimeEnd = None
|
---|
| 53 |
|
---|
| 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 |
|
---|
[8] | 69 | @property
|
---|
[134] | 70 | def config(self):
|
---|
| 71 | """Get the configuration."""
|
---|
| 72 | return self._gui.config
|
---|
| 73 |
|
---|
| 74 | @property
|
---|
[8] | 75 | def stage(self):
|
---|
| 76 | """Get the flight stage."""
|
---|
| 77 | return self._stage
|
---|
| 78 |
|
---|
[84] | 79 | @property
|
---|
[134] | 80 | def bookedFlight(self):
|
---|
| 81 | """Get the booked flight."""
|
---|
| 82 | return self._gui.bookedFlight
|
---|
| 83 |
|
---|
| 84 | @property
|
---|
[84] | 85 | def zfw(self):
|
---|
| 86 | """Get the Zero-Fuel Weight of the flight."""
|
---|
| 87 | return self._gui.zfw
|
---|
| 88 |
|
---|
| 89 | @property
|
---|
| 90 | def cruiseAltitude(self):
|
---|
| 91 | """Get the cruise altitude of the flight."""
|
---|
| 92 | return self._gui.cruiseAltitude
|
---|
| 93 |
|
---|
| 94 | @property
|
---|
| 95 | def v1(self):
|
---|
| 96 | """Get the V1 speed of the flight."""
|
---|
| 97 | return self._gui.v1
|
---|
| 98 |
|
---|
| 99 | @property
|
---|
| 100 | def vr(self):
|
---|
| 101 | """Get the Vr speed of the flight."""
|
---|
| 102 | return self._gui.vr
|
---|
| 103 |
|
---|
| 104 | @property
|
---|
| 105 | def v2(self):
|
---|
| 106 | """Get the V2 speed of the flight."""
|
---|
| 107 | return self._gui.v2
|
---|
| 108 |
|
---|
[86] | 109 | @property
|
---|
| 110 | def vref(self):
|
---|
| 111 | """Get the VRef speed of the flight."""
|
---|
| 112 | return self._gui.vref
|
---|
| 113 |
|
---|
[170] | 114 | @property
|
---|
| 115 | def tdRate(self):
|
---|
| 116 | """Get the touchdown rate if known, None otherwise."""
|
---|
| 117 | return self._tdRate
|
---|
| 118 |
|
---|
[89] | 119 | def handleState(self, oldState, currentState):
|
---|
| 120 | """Handle a new state information."""
|
---|
| 121 | self._updateFlownDistance(currentState)
|
---|
| 122 |
|
---|
| 123 | self.endFuel = sum(currentState.fuel)
|
---|
| 124 | if self.startFuel is None:
|
---|
| 125 | self.startFuel = self.endFuel
|
---|
[170] | 126 |
|
---|
| 127 | self._soundScheduler.schedule(currentState,
|
---|
| 128 | self._pilotHotkeyPressed)
|
---|
| 129 | self._pilotHotkeyPressed = False
|
---|
[89] | 130 |
|
---|
[8] | 131 | def setStage(self, timestamp, stage):
|
---|
[9] | 132 | """Set the flight stage.
|
---|
| 133 |
|
---|
| 134 | Returns if the stage has really changed."""
|
---|
[8] | 135 | if stage!=self._stage:
|
---|
| 136 | self._stage = stage
|
---|
[84] | 137 | self._gui.setStage(stage)
|
---|
[8] | 138 | self.logger.stage(timestamp, stage)
|
---|
[89] | 139 | if stage==const.STAGE_PUSHANDTAXI:
|
---|
| 140 | self.blockTimeStart = timestamp
|
---|
| 141 | elif stage==const.STAGE_TAKEOFF:
|
---|
| 142 | self.flightTimeStart = timestamp
|
---|
| 143 | elif stage==const.STAGE_TAXIAFTERLAND:
|
---|
| 144 | self.flightTimeEnd = timestamp
|
---|
| 145 | elif stage==const.STAGE_PARKING:
|
---|
| 146 | self.blockTimeEnd = timestamp
|
---|
| 147 | elif stage==const.STAGE_END:
|
---|
[8] | 148 | with self._endCondition:
|
---|
| 149 | self._endCondition.notify()
|
---|
[9] | 150 | return True
|
---|
| 151 | else:
|
---|
| 152 | return False
|
---|
| 153 |
|
---|
[30] | 154 | def handleFault(self, faultID, timestamp, what, score):
|
---|
| 155 | """Handle the given fault.
|
---|
| 156 |
|
---|
| 157 | faultID as a unique ID for the given kind of fault. If another fault of
|
---|
| 158 | this ID has been reported earlier, it will be reported again only if
|
---|
| 159 | the score is greater than last time. This ID can be, e.g. the checker
|
---|
| 160 | the report comes from."""
|
---|
| 161 | self.logger.fault(faultID, timestamp, what, score)
|
---|
[31] | 162 | self._gui.setRating(self.logger.getRating())
|
---|
[30] | 163 |
|
---|
| 164 | def handleNoGo(self, faultID, timestamp, what, shortReason):
|
---|
| 165 | """Handle a No-Go fault."""
|
---|
| 166 | self.logger.noGo(faultID, timestamp, what)
|
---|
[31] | 167 | self._gui.setNoGo(shortReason)
|
---|
[30] | 168 |
|
---|
[9] | 169 | def flareStarted(self, flareStart, flareStartFS):
|
---|
| 170 | """Called when the flare time has started."""
|
---|
| 171 | self._flareStart = flareStart
|
---|
| 172 | self._flareStartFS = flareStartFS
|
---|
| 173 |
|
---|
[170] | 174 | def flareFinished(self, flareEnd, flareEndFS, tdRate):
|
---|
[9] | 175 | """Called when the flare time has ended.
|
---|
| 176 |
|
---|
| 177 | Return a tuple of the following items:
|
---|
| 178 | - a boolean indicating if FS time is used
|
---|
| 179 | - the flare time
|
---|
| 180 | """
|
---|
[170] | 181 | self._tdRate = tdRate
|
---|
[9] | 182 | if self.flareTimeFromFS:
|
---|
| 183 | return (True, flareEndFS - self._flareStartFS)
|
---|
| 184 | else:
|
---|
| 185 | return (False, flareEnd - self._flareStart)
|
---|
[8] | 186 |
|
---|
| 187 | def wait(self):
|
---|
| 188 | """Wait for the flight to end."""
|
---|
| 189 | with self._endCondition:
|
---|
| 190 | while self._stage!=const.STAGE_END:
|
---|
[14] | 191 | self._endCondition.wait(1)
|
---|
[8] | 192 |
|
---|
[134] | 193 | def getFleet(self, callback, force = False):
|
---|
| 194 | """Get the fleet and call the given callback."""
|
---|
| 195 | self._gui.getFleetAsync(callback = callback, force = force)
|
---|
| 196 |
|
---|
[170] | 197 | def pilotHotkeyPressed(self):
|
---|
| 198 | """Called when the pilot hotkey is pressed."""
|
---|
| 199 | self._pilotHotkeyPressed = True
|
---|
| 200 |
|
---|
| 201 | def checklistHotkeyPressed(self):
|
---|
| 202 | """Called when the checklist hotkey is pressed."""
|
---|
| 203 | self._checklistHotkeyPressed = True
|
---|
| 204 |
|
---|
[89] | 205 | def _updateFlownDistance(self, currentState):
|
---|
| 206 | """Update the flown distance."""
|
---|
| 207 | if not currentState.onTheGround:
|
---|
| 208 | updateData = False
|
---|
| 209 | if self._lastDistanceTime is None or \
|
---|
| 210 | self._previousLatitude is None or \
|
---|
| 211 | self._previousLongitude is None:
|
---|
| 212 | updateData = True
|
---|
| 213 | elif currentState.timestamp >= (self._lastDistanceTime + 30.0):
|
---|
| 214 | updateData = True
|
---|
| 215 | self.flownDistance += self._getDistance(currentState)
|
---|
| 216 |
|
---|
| 217 | if updateData:
|
---|
| 218 | self._previousLatitude = currentState.latitude
|
---|
| 219 | self._previousLongitude = currentState.longitude
|
---|
| 220 | self._lastDistanceTime = currentState.timestamp
|
---|
| 221 | else:
|
---|
| 222 | if self._lastDistanceTime is not None and \
|
---|
| 223 | self._previousLatitude is not None and \
|
---|
| 224 | self._previousLongitude is not None:
|
---|
| 225 | self.flownDistance += self._getDistance(currentState)
|
---|
| 226 |
|
---|
| 227 | self._lastDistanceTime = None
|
---|
| 228 |
|
---|
| 229 | def _getDistance(self, currentState):
|
---|
| 230 | """Get the distance between the previous and the current state."""
|
---|
| 231 | return util.getDistCourse(self._previousLatitude, self._previousLongitude,
|
---|
| 232 | currentState.latitude, currentState.longitude)[0]
|
---|
| 233 |
|
---|
[8] | 234 | #---------------------------------------------------------------------------------------
|
---|