Changeset 89:ef4711a984fe for src/mlx/flight.py
- Timestamp:
- 04/17/12 18:00:09 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/flight.py
r86 r89 4 4 5 5 import const 6 import util 6 7 7 8 import threading … … 39 40 self.aircraft = None 40 41 self.simulator = None 42 43 self.blockTimeStart = None 44 self.flightTimeStart = None 45 self.flightTimeEnd = None 46 self.blockTimeEnd = None 47 48 self._lastDistanceTime = None 49 self._previousLatitude = None 50 self._previousLongitude = None 51 self.flownDistance = 0.0 52 53 self.startFuel = None 54 self.endFuel = None 41 55 42 56 self._endCondition = threading.Condition() … … 80 94 return self._gui.vref 81 95 96 def handleState(self, oldState, currentState): 97 """Handle a new state information.""" 98 self._updateFlownDistance(currentState) 99 100 self.endFuel = sum(currentState.fuel) 101 if self.startFuel is None: 102 self.startFuel = self.endFuel 103 82 104 def setStage(self, timestamp, stage): 83 105 """Set the flight stage. … … 88 110 self._gui.setStage(stage) 89 111 self.logger.stage(timestamp, stage) 90 if stage==const.STAGE_END: 112 if stage==const.STAGE_PUSHANDTAXI: 113 self.blockTimeStart = timestamp 114 elif stage==const.STAGE_TAKEOFF: 115 self.flightTimeStart = timestamp 116 elif stage==const.STAGE_TAXIAFTERLAND: 117 self.flightTimeEnd = timestamp 118 elif stage==const.STAGE_PARKING: 119 self.blockTimeEnd = timestamp 120 elif stage==const.STAGE_END: 91 121 with self._endCondition: 92 122 self._endCondition.notify() … … 133 163 self._endCondition.wait(1) 134 164 165 def _updateFlownDistance(self, currentState): 166 """Update the flown distance.""" 167 if not currentState.onTheGround: 168 updateData = False 169 if self._lastDistanceTime is None or \ 170 self._previousLatitude is None or \ 171 self._previousLongitude is None: 172 updateData = True 173 elif currentState.timestamp >= (self._lastDistanceTime + 30.0): 174 updateData = True 175 self.flownDistance += self._getDistance(currentState) 176 177 if updateData: 178 self._previousLatitude = currentState.latitude 179 self._previousLongitude = currentState.longitude 180 self._lastDistanceTime = currentState.timestamp 181 else: 182 if self._lastDistanceTime is not None and \ 183 self._previousLatitude is not None and \ 184 self._previousLongitude is not None: 185 self.flownDistance += self._getDistance(currentState) 186 187 self._lastDistanceTime = None 188 189 def _getDistance(self, currentState): 190 """Get the distance between the previous and the current state.""" 191 return util.getDistCourse(self._previousLatitude, self._previousLongitude, 192 currentState.latitude, currentState.longitude)[0] 193 135 194 #---------------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.