1 | # Module related to the high-level tracking of the flight
|
---|
2 |
|
---|
3 | #---------------------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | import const
|
---|
6 | import util
|
---|
7 |
|
---|
8 | import threading
|
---|
9 |
|
---|
10 | #---------------------------------------------------------------------------------------
|
---|
11 |
|
---|
12 | class Options(object):
|
---|
13 | """Various configuration options."""
|
---|
14 | def __init__(self):
|
---|
15 | """Construct the object with default values."""
|
---|
16 | self.fs2Crew = False
|
---|
17 | self.compensation = None
|
---|
18 |
|
---|
19 | #---------------------------------------------------------------------------------------
|
---|
20 |
|
---|
21 | class Flight(object):
|
---|
22 | """The object with the global flight state.
|
---|
23 |
|
---|
24 | It is also the hub for the other main objects participating in the handling of
|
---|
25 | the flight."""
|
---|
26 | def __init__(self, logger, gui):
|
---|
27 | """Construct the flight."""
|
---|
28 | self._stage = None
|
---|
29 | self.logger = logger
|
---|
30 | self._gui = gui
|
---|
31 |
|
---|
32 | gui.resetFlightStatus()
|
---|
33 |
|
---|
34 | self.flareTimeFromFS = False
|
---|
35 | self.entranceExam = False
|
---|
36 |
|
---|
37 | self.options = Options()
|
---|
38 |
|
---|
39 | self.aircraftType = None
|
---|
40 | self.aircraft = None
|
---|
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
|
---|
55 |
|
---|
56 | self._endCondition = threading.Condition()
|
---|
57 |
|
---|
58 | self._flareStart = None
|
---|
59 | self._flareStartFS = None
|
---|
60 |
|
---|
61 | @property
|
---|
62 | def stage(self):
|
---|
63 | """Get the flight stage."""
|
---|
64 | return self._stage
|
---|
65 |
|
---|
66 | @property
|
---|
67 | def zfw(self):
|
---|
68 | """Get the Zero-Fuel Weight of the flight."""
|
---|
69 | return self._gui.zfw
|
---|
70 |
|
---|
71 | @property
|
---|
72 | def cruiseAltitude(self):
|
---|
73 | """Get the cruise altitude of the flight."""
|
---|
74 | return self._gui.cruiseAltitude
|
---|
75 |
|
---|
76 | @property
|
---|
77 | def v1(self):
|
---|
78 | """Get the V1 speed of the flight."""
|
---|
79 | return self._gui.v1
|
---|
80 |
|
---|
81 | @property
|
---|
82 | def vr(self):
|
---|
83 | """Get the Vr speed of the flight."""
|
---|
84 | return self._gui.vr
|
---|
85 |
|
---|
86 | @property
|
---|
87 | def v2(self):
|
---|
88 | """Get the V2 speed of the flight."""
|
---|
89 | return self._gui.v2
|
---|
90 |
|
---|
91 | @property
|
---|
92 | def vref(self):
|
---|
93 | """Get the VRef speed of the flight."""
|
---|
94 | return self._gui.vref
|
---|
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 |
|
---|
104 | def setStage(self, timestamp, stage):
|
---|
105 | """Set the flight stage.
|
---|
106 |
|
---|
107 | Returns if the stage has really changed."""
|
---|
108 | if stage!=self._stage:
|
---|
109 | self._stage = stage
|
---|
110 | self._gui.setStage(stage)
|
---|
111 | self.logger.stage(timestamp, stage)
|
---|
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:
|
---|
121 | with self._endCondition:
|
---|
122 | self._endCondition.notify()
|
---|
123 | return True
|
---|
124 | else:
|
---|
125 | return False
|
---|
126 |
|
---|
127 | def handleFault(self, faultID, timestamp, what, score):
|
---|
128 | """Handle the given fault.
|
---|
129 |
|
---|
130 | faultID as a unique ID for the given kind of fault. If another fault of
|
---|
131 | this ID has been reported earlier, it will be reported again only if
|
---|
132 | the score is greater than last time. This ID can be, e.g. the checker
|
---|
133 | the report comes from."""
|
---|
134 | self.logger.fault(faultID, timestamp, what, score)
|
---|
135 | self._gui.setRating(self.logger.getRating())
|
---|
136 |
|
---|
137 | def handleNoGo(self, faultID, timestamp, what, shortReason):
|
---|
138 | """Handle a No-Go fault."""
|
---|
139 | self.logger.noGo(faultID, timestamp, what)
|
---|
140 | self._gui.setNoGo(shortReason)
|
---|
141 |
|
---|
142 | def flareStarted(self, flareStart, flareStartFS):
|
---|
143 | """Called when the flare time has started."""
|
---|
144 | self._flareStart = flareStart
|
---|
145 | self._flareStartFS = flareStartFS
|
---|
146 |
|
---|
147 | def flareFinished(self, flareEnd, flareEndFS):
|
---|
148 | """Called when the flare time has ended.
|
---|
149 |
|
---|
150 | Return a tuple of the following items:
|
---|
151 | - a boolean indicating if FS time is used
|
---|
152 | - the flare time
|
---|
153 | """
|
---|
154 | if self.flareTimeFromFS:
|
---|
155 | return (True, flareEndFS - self._flareStartFS)
|
---|
156 | else:
|
---|
157 | return (False, flareEnd - self._flareStart)
|
---|
158 |
|
---|
159 | def wait(self):
|
---|
160 | """Wait for the flight to end."""
|
---|
161 | with self._endCondition:
|
---|
162 | while self._stage!=const.STAGE_END:
|
---|
163 | self._endCondition.wait(1)
|
---|
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 |
|
---|
194 | #---------------------------------------------------------------------------------------
|
---|