1 | # Module for the simulator-independent aircraft classes
|
---|
2 |
|
---|
3 | #---------------------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | import const
|
---|
6 | import checks
|
---|
7 | import fs
|
---|
8 | import util
|
---|
9 |
|
---|
10 | import sys
|
---|
11 | import time
|
---|
12 | import traceback
|
---|
13 |
|
---|
14 | from collections import deque
|
---|
15 |
|
---|
16 | #---------------------------------------------------------------------------------------
|
---|
17 |
|
---|
18 | class SmoothedValue(object):
|
---|
19 | """A smoothed value."""
|
---|
20 | def __init__(self):
|
---|
21 | """Construct the value."""
|
---|
22 | self._deque = deque()
|
---|
23 | self._sum = 0
|
---|
24 |
|
---|
25 | def add(self, length, value):
|
---|
26 | """Add the given value and smooth with the given length."""
|
---|
27 | dequeLength = len(self._deque)
|
---|
28 | while dequeLength>=length:
|
---|
29 | self._sum -= self._deque.popleft()
|
---|
30 | dequeLength -= 1
|
---|
31 |
|
---|
32 | self._sum += value
|
---|
33 | self._deque.append(value)
|
---|
34 |
|
---|
35 | def get(self):
|
---|
36 | """Get the average."""
|
---|
37 | return self._sum / len(self._deque)
|
---|
38 |
|
---|
39 | #---------------------------------------------------------------------------------------
|
---|
40 |
|
---|
41 | class Aircraft(object):
|
---|
42 | """Base class for aircraft."""
|
---|
43 | @staticmethod
|
---|
44 | def create(flight):
|
---|
45 | """Create an aircraft instance for the type in the given flight."""
|
---|
46 | return _classes[flight.aircraftType](flight)
|
---|
47 |
|
---|
48 | def __init__(self, flight):
|
---|
49 | """Construct the aircraft for the given type."""
|
---|
50 | self._flight = flight
|
---|
51 | self._aircraftState = None
|
---|
52 |
|
---|
53 | self._maxVS = -10000.0
|
---|
54 | self._minVS = 10000.0
|
---|
55 |
|
---|
56 | self._v1r2LineIndex = None
|
---|
57 | self._vrefLineIndex = None
|
---|
58 |
|
---|
59 | self.humanWeight = 82.0
|
---|
60 |
|
---|
61 | self._checkers = []
|
---|
62 |
|
---|
63 | config = flight.config
|
---|
64 | # Loggers
|
---|
65 |
|
---|
66 | self._checkers.append(checks.StageChecker())
|
---|
67 | self._checkers.append(checks.TakeOffLogger())
|
---|
68 |
|
---|
69 | self._checkers.append(checks.AltimeterLogger())
|
---|
70 |
|
---|
71 | self._checkers.append(checks.NAV1Logger())
|
---|
72 | self._checkers.append(checks.NAV2Logger())
|
---|
73 | self._checkers.append(checks.SquawkLogger())
|
---|
74 |
|
---|
75 | self._checkers.append(checks.AnticollisionLightsLogger())
|
---|
76 | self._checkers.append(checks.LandingLightsLogger())
|
---|
77 | self._checkers.append(checks.StrobeLightsLogger())
|
---|
78 | self._checkers.append(checks.NavLightsLogger())
|
---|
79 |
|
---|
80 | self._checkers.append(checks.FlapsLogger())
|
---|
81 |
|
---|
82 | self._checkers.append(checks.GearsLogger())
|
---|
83 | self._checkers.append(checks.CruiseSpeedLogger())
|
---|
84 | self._checkers.append(checks.SpoilerLogger())
|
---|
85 |
|
---|
86 | if config.isMessageTypeFS(const.MESSAGETYPE_VISIBILITY):
|
---|
87 | self._checkers.append(checks.VisibilityChecker())
|
---|
88 |
|
---|
89 | # FIXME: we should have a central data model object, and not collect
|
---|
90 | # the data from the GUI. However, some pieces of data (e.g. V-speeds,
|
---|
91 | # etc. that is entered into the GUI) *should* be a part of the GUI and
|
---|
92 | # queried from it, so the model should have a reference to the GUI as
|
---|
93 | # well and access such data via the GUI!
|
---|
94 | if config.onlineACARS and not flight.entranceExam:
|
---|
95 | self._checkers.append(checks.ACARSSender(flight._gui))
|
---|
96 |
|
---|
97 | # Fault checkers
|
---|
98 |
|
---|
99 | self._checkers.append(checks.AntiCollisionLightsChecker())
|
---|
100 | self._checkers.append(checks.LandingLightsChecker())
|
---|
101 | self._checkers.append(checks.NavLightsChecker())
|
---|
102 | self._checkers.append(checks.StrobeLightsChecker())
|
---|
103 |
|
---|
104 | self._checkers.append(checks.BankChecker())
|
---|
105 |
|
---|
106 | self._checkers.append(checks.FlapsRetractChecker())
|
---|
107 | self._checkers.append(checks.FlapsSpeedLimitChecker())
|
---|
108 |
|
---|
109 | self._checkers.append(checks.GearsDownChecker())
|
---|
110 | self._checkers.append(checks.GearSpeedLimitChecker())
|
---|
111 |
|
---|
112 | self._checkers.append(checks.GLoadChecker())
|
---|
113 |
|
---|
114 | self._checkers.append(checks.MLWChecker())
|
---|
115 | self._checkers.append(checks.MTOWChecker())
|
---|
116 | self._checkers.append(checks.MZFWChecker())
|
---|
117 | self._checkers.append(checks.PayloadChecker())
|
---|
118 |
|
---|
119 | self._checkers.append(checks.SpeedChecker())
|
---|
120 | self._checkers.append(checks.VSChecker())
|
---|
121 |
|
---|
122 | timeout = 5.0 + config.realIASSmoothingLength - 1
|
---|
123 | self._checkers.append(checks.OverspeedChecker(timeout = timeout))
|
---|
124 |
|
---|
125 | self._checkers.append(checks.StallChecker())
|
---|
126 |
|
---|
127 | self._checkers.append(checks.PitotChecker())
|
---|
128 |
|
---|
129 | self._checkers.append(checks.ReverserChecker())
|
---|
130 |
|
---|
131 | self._smoothedIAS = SmoothedValue()
|
---|
132 | self._smoothedVS = SmoothedValue()
|
---|
133 |
|
---|
134 | @property
|
---|
135 | def type(self):
|
---|
136 | """Get the type of the aircraft."""
|
---|
137 | return self._flight.aircraftType
|
---|
138 |
|
---|
139 | @property
|
---|
140 | def flight(self):
|
---|
141 | """Get the flight the aircraft belongs to."""
|
---|
142 | return self._flight
|
---|
143 |
|
---|
144 | @property
|
---|
145 | def logger(self):
|
---|
146 | """Get the logger to use for the aircraft."""
|
---|
147 | return self._flight.logger
|
---|
148 |
|
---|
149 | @property
|
---|
150 | def state(self):
|
---|
151 | """Get the current aircraft state."""
|
---|
152 | return self._aircraftState
|
---|
153 |
|
---|
154 | def getFlapsSpeedLimit(self, flaps):
|
---|
155 | """Get the speed limit for the given flaps setting."""
|
---|
156 | return self.flapSpeedLimits[flaps] if flaps in self.flapSpeedLimits \
|
---|
157 | else None
|
---|
158 |
|
---|
159 | def modelChanged(self, timestamp, aircraftName, modelName):
|
---|
160 | """Called when the simulator's aircraft changes."""
|
---|
161 | self._flight.logger.message(timestamp,
|
---|
162 | "Aircraft: name='%s', model='%s'" % \
|
---|
163 | (aircraftName, modelName))
|
---|
164 |
|
---|
165 | def handleState(self, aircraftState):
|
---|
166 | """Called when the state of the aircraft changes.
|
---|
167 |
|
---|
168 | This is the function that the simulator calls directly with the new
|
---|
169 | state."""
|
---|
170 | config = self._flight.config
|
---|
171 |
|
---|
172 | self._smoothedIAS.add(config.realIASSmoothingLength, aircraftState.ias)
|
---|
173 | aircraftState.smoothedIAS = self._smoothedIAS.get()
|
---|
174 |
|
---|
175 | self._smoothedVS.add(config.realVSSmoothingLength, aircraftState.vs)
|
---|
176 | aircraftState.smoothedVS = self._smoothedVS.get()
|
---|
177 |
|
---|
178 | for checker in self._checkers:
|
---|
179 | try:
|
---|
180 | checker.check(self._flight, self, self._flight.logger,
|
---|
181 | self._aircraftState, aircraftState)
|
---|
182 | except:
|
---|
183 | print >> sys.stderr, "Checker", checker, "failed"
|
---|
184 | traceback.print_exc()
|
---|
185 |
|
---|
186 | self._flight.handleState(self._aircraftState, aircraftState)
|
---|
187 |
|
---|
188 | self._maxVS = max(self._maxVS, aircraftState.vs)
|
---|
189 | self._minVS = min(self._minVS, aircraftState.vs)
|
---|
190 |
|
---|
191 | self._aircraftState = aircraftState
|
---|
192 |
|
---|
193 | def setStage(self, aircraftState, newStage):
|
---|
194 | """Set the given stage as the new one and do whatever should be
|
---|
195 | done."""
|
---|
196 | if self._flight.setStage(aircraftState.timestamp, newStage):
|
---|
197 | if newStage==const.STAGE_PUSHANDTAXI:
|
---|
198 | self.logger.message(aircraftState.timestamp, "Block time start")
|
---|
199 | self.logFuel(aircraftState)
|
---|
200 | self.logger.message(aircraftState.timestamp,
|
---|
201 | "Zero-fuel weight: %.0f kg" % (aircraftState.zfw))
|
---|
202 | flight = self._flight
|
---|
203 | if flight.v1 is None or flight.vr is None or flight.v2 is None:
|
---|
204 | fs.sendMessage(const.MESSAGETYPE_HELP,
|
---|
205 | "Don't forget to set the takeoff V-speeds!",
|
---|
206 | 5)
|
---|
207 | elif newStage==const.STAGE_TAKEOFF:
|
---|
208 | self.logger.message(aircraftState.timestamp, "Flight time start")
|
---|
209 | self.logger.message(aircraftState.timestamp,
|
---|
210 | "Takeoff weight: %.0f kg, MTOW: %.0f kg" % \
|
---|
211 | (aircraftState.grossWeight, self.mtow))
|
---|
212 | self.logger.message(aircraftState.timestamp,
|
---|
213 | "Wind %03.0f degrees at %.0f knots" % \
|
---|
214 | (aircraftState.windDirection,
|
---|
215 | aircraftState.windSpeed))
|
---|
216 | self._logV1R2()
|
---|
217 | elif newStage==const.STAGE_TAXIAFTERLAND:
|
---|
218 | flight = self._flight
|
---|
219 | bookedFlight = flight.bookedFlight
|
---|
220 | config = flight.config
|
---|
221 | if config.onlineGateSystem and \
|
---|
222 | not flight.entranceExam and \
|
---|
223 | bookedFlight.arrivalICAO=="LHBP" and \
|
---|
224 | config.isMessageTypeFS(const.MESSAGETYPE_GATE_SYSTEM):
|
---|
225 | self._flight.getFleet(callback = self._fleetRetrieved,
|
---|
226 | force = True)
|
---|
227 | self.logger.message(aircraftState.timestamp, "Flight time end")
|
---|
228 | self.logFuel(aircraftState)
|
---|
229 | self.logger.message(aircraftState.timestamp,
|
---|
230 | "Landing weight: %.0f kg, MLW: %.0f" % \
|
---|
231 | (aircraftState.grossWeight, self.mlw))
|
---|
232 | self.logger.message(aircraftState.timestamp,
|
---|
233 | "Vertical speed range: %.0f..%.0f feet/min" % \
|
---|
234 | (self._minVS, self._maxVS))
|
---|
235 | elif newStage==const.STAGE_PARKING:
|
---|
236 | self.logger.message(aircraftState.timestamp, "Block time end")
|
---|
237 | elif newStage==const.STAGE_END:
|
---|
238 | flightLength = self._flight.flightTimeEnd - self._flight.flightTimeStart
|
---|
239 | self.logger.message(aircraftState.timestamp,
|
---|
240 | "Flight time: " +
|
---|
241 | util.getTimeIntervalString(flightLength))
|
---|
242 | self.logger.message(aircraftState.timestamp,
|
---|
243 | "Flown distance: %.2f NM" % \
|
---|
244 | (self._flight.flownDistance,))
|
---|
245 | blockLength = self._flight.blockTimeEnd - self._flight.blockTimeStart
|
---|
246 | self.logger.message(aircraftState.timestamp,
|
---|
247 | "Block time: " +
|
---|
248 | util.getTimeIntervalString(blockLength))
|
---|
249 |
|
---|
250 | def prepareFlare(self):
|
---|
251 | """Called when it is detected that we will soon flare.
|
---|
252 |
|
---|
253 | On the first call, it should start monitoring some parameters more
|
---|
254 | closely to determine flare time."""
|
---|
255 | self.flight.simulator.startFlare()
|
---|
256 |
|
---|
257 | def flareStarted(self, windSpeed, windDirection, visibility,
|
---|
258 | flareStart, flareStartFS):
|
---|
259 | """Called when the flare has started."""
|
---|
260 | self.logger.message(self._aircraftState.timestamp, "The flare has begun")
|
---|
261 | self.logger.message(self._aircraftState.timestamp,
|
---|
262 | "Wind %03.0f degrees at %.0f knots" % \
|
---|
263 | (windDirection, windSpeed))
|
---|
264 | self.logger.message(self._aircraftState.timestamp,
|
---|
265 | "Visibility: %.0f metres" % (visibility,))
|
---|
266 | self.logger.message(self._aircraftState.timestamp,
|
---|
267 | "Altimeter setting: %.0f hPa" % \
|
---|
268 | (self._aircraftState.altimeter,))
|
---|
269 | self._logVRef()
|
---|
270 | self.flight.flareStarted(flareStart, flareStartFS)
|
---|
271 | fs.sendMessage(const.MESSAGETYPE_INFORMATION, "Flare-time", 3)
|
---|
272 |
|
---|
273 | def flareFinished(self, flareEnd, flareEndFS, tdRate, tdRateCalculatedByFS,
|
---|
274 | ias, pitch, bank, heading):
|
---|
275 | """Called when the flare has finished."""
|
---|
276 | (flareTimeFromFS, flareTime) = self.flight.flareFinished(flareEnd,
|
---|
277 | flareEndFS,
|
---|
278 | tdRate)
|
---|
279 | self.logger.message(self._aircraftState.timestamp,
|
---|
280 | "Flaretime: %.3f (from %s)" % \
|
---|
281 | (flareTime,
|
---|
282 | "the simulator" if flareTimeFromFS else "real time",))
|
---|
283 | self.logger.message(self._aircraftState.timestamp,
|
---|
284 | "Touchdown rate: %.0f feet/min" % (tdRate,))
|
---|
285 | self.logger.message(self._aircraftState.timestamp,
|
---|
286 | "Touchdown rate was calculated by the %s" % \
|
---|
287 | ("simulator" if tdRateCalculatedByFS else "logger",))
|
---|
288 | self.logger.message(self._aircraftState.timestamp,
|
---|
289 | "Touchdown speed: %.0f knots" % (ias,))
|
---|
290 | self.logger.message(self._aircraftState.timestamp,
|
---|
291 | "Touchdown pitch: %.1f degrees" % (pitch,))
|
---|
292 | self.logger.message(self._aircraftState.timestamp,
|
---|
293 | "Touchdown bank: %.1f degrees" % (bank,))
|
---|
294 | self.logger.message(self._aircraftState.timestamp,
|
---|
295 | "Touchdown heading: %03.0f degrees" % (heading,))
|
---|
296 |
|
---|
297 | def cancelFlare(self):
|
---|
298 | """Cancel flare, if it has started."""
|
---|
299 | self.flight.simulator.cancelFlare()
|
---|
300 |
|
---|
301 | def checkFlightEnd(self, aircraftState):
|
---|
302 | """Check if the end of the flight has arrived.
|
---|
303 |
|
---|
304 | This default implementation checks the N1 values, but for
|
---|
305 | piston-powered aircraft you need to check the RPMs."""
|
---|
306 | for n1 in aircraftState.n1:
|
---|
307 | if n1>=0.5: return False
|
---|
308 | return True
|
---|
309 |
|
---|
310 | def updateV1R2(self):
|
---|
311 | """Update the V1, Vr and V2 values from the flight, if the these values
|
---|
312 | have already been logged."""
|
---|
313 | if self._v1r2LineIndex is not None:
|
---|
314 | self._logV1R2()
|
---|
315 |
|
---|
316 | def _logV1R2(self):
|
---|
317 | """Log the V1, Vr and V2 value either newly, or by updating the
|
---|
318 | corresponding line."""
|
---|
319 | message = "Speeds calculated by the pilot: V1: %s, VR: %s, V2: %s" % \
|
---|
320 | ("-" if self._flight.v1 is None
|
---|
321 | else str(self._flight.v1),
|
---|
322 | "-" if self._flight.vr is None
|
---|
323 | else str(self._flight.vr),
|
---|
324 | "-" if self._flight.v2 is None
|
---|
325 | else str(self._flight.v2))
|
---|
326 |
|
---|
327 | if self._v1r2LineIndex is None:
|
---|
328 | self._v1r2LineIndex = \
|
---|
329 | self.logger.message(self._aircraftState.timestamp, message)
|
---|
330 | else:
|
---|
331 | self.logger.updateLine(self._v1r2LineIndex, message)
|
---|
332 |
|
---|
333 | def updateVRef(self):
|
---|
334 | """Update the Vref value from the flight, if the Vref value has already
|
---|
335 | been logged."""
|
---|
336 | if self._vrefLineIndex is not None:
|
---|
337 | self._logVRef()
|
---|
338 |
|
---|
339 | def _logVRef(self):
|
---|
340 | """Log the Vref value either newly, or by updating the corresponding
|
---|
341 | line."""
|
---|
342 | message = "VRef speed calculated by the pilot: %s" % \
|
---|
343 | ("-" if self._flight.vref is None else str(self._flight.vref))
|
---|
344 | if self._vrefLineIndex is None:
|
---|
345 | self._vrefLineIndex = \
|
---|
346 | self.logger.message(self._aircraftState.timestamp, message)
|
---|
347 | else:
|
---|
348 | self.logger.updateLine(self._vrefLineIndex, message)
|
---|
349 |
|
---|
350 | def _fleetRetrieved(self, fleet):
|
---|
351 | """Callback for the fleet retrieval result."""
|
---|
352 | if fleet is not None:
|
---|
353 | gateList = ""
|
---|
354 | occupiedGateNumbers = fleet.getOccupiedGateNumbers()
|
---|
355 | for gateNumber in const.lhbpGateNumbers:
|
---|
356 | if gateNumber not in occupiedGateNumbers:
|
---|
357 | if gateList: gateList += ", "
|
---|
358 | gateList += gateNumber
|
---|
359 | fs.sendMessage(const.MESSAGETYPE_GATE_SYSTEM,
|
---|
360 | "Free gates: " + gateList, 20)
|
---|
361 |
|
---|
362 |
|
---|
363 | #---------------------------------------------------------------------------------------
|
---|
364 |
|
---|
365 | class Boeing737(Aircraft):
|
---|
366 | """Base class for the various aircraft in the Boeing 737 family.
|
---|
367 |
|
---|
368 | The aircraft type-specific values in the aircraft state have the following
|
---|
369 | structure:
|
---|
370 | - fuel: left, centre, right
|
---|
371 | - n1: left, right
|
---|
372 | - reverser: left, right"""
|
---|
373 | fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]
|
---|
374 |
|
---|
375 | def __init__(self, flight):
|
---|
376 | super(Boeing737, self).__init__(flight)
|
---|
377 | self._checkers.append(checks.ThrustChecker())
|
---|
378 |
|
---|
379 | self.gearSpeedLimit = 270
|
---|
380 | self.flapSpeedLimits = { 1 : 260,
|
---|
381 | 2 : 260,
|
---|
382 | 5 : 250,
|
---|
383 | 10 : 210,
|
---|
384 | 15 : 200,
|
---|
385 | 25 : 190,
|
---|
386 | 30 : 175,
|
---|
387 | 40 : 162 }
|
---|
388 |
|
---|
389 | def logFuel(self, aircraftState):
|
---|
390 | """Log the amount of fuel"""
|
---|
391 | self.logger.message(aircraftState.timestamp,
|
---|
392 | "Fuel: left=%.0f kg - centre=%.0f kg - right=%.0f kg" % \
|
---|
393 | (aircraftState.fuel[0], aircraftState.fuel[1],
|
---|
394 | aircraftState.fuel[2]))
|
---|
395 | self.logger.message(aircraftState.timestamp,
|
---|
396 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
397 |
|
---|
398 | #---------------------------------------------------------------------------------------
|
---|
399 |
|
---|
400 | class B736(Boeing737):
|
---|
401 | """Boeing 737-600 aircraft."""
|
---|
402 | def __init__(self, flight):
|
---|
403 | super(B736, self).__init__(flight)
|
---|
404 | self.dow = 38307
|
---|
405 | self.mtow = 58328
|
---|
406 | self.mlw = 54657
|
---|
407 | self.mzfw = 51482
|
---|
408 |
|
---|
409 | #---------------------------------------------------------------------------------------
|
---|
410 |
|
---|
411 | class B737(Boeing737):
|
---|
412 | """Boeing 737-700 aircraft."""
|
---|
413 | def __init__(self, flight):
|
---|
414 | super(B737, self).__init__(flight)
|
---|
415 | self.dow = 39250
|
---|
416 | self.mtow = 61410
|
---|
417 | self.mlw = 58059
|
---|
418 | self.mzfw = 54657
|
---|
419 |
|
---|
420 | #---------------------------------------------------------------------------------------
|
---|
421 |
|
---|
422 | class B738(Boeing737):
|
---|
423 | """Boeing 737-800 aircraft."""
|
---|
424 | def __init__(self, flight):
|
---|
425 | super(B738, self).__init__(flight)
|
---|
426 | self.dow = 42690
|
---|
427 | self.mtow = 71709
|
---|
428 | self.mlw = 65317
|
---|
429 | self.mzfw = 61688
|
---|
430 |
|
---|
431 | #---------------------------------------------------------------------------------------
|
---|
432 |
|
---|
433 | class B738Charter(B738):
|
---|
434 | """Boeing 737-800 aircraft used for charters."""
|
---|
435 | def __init__(self, flight):
|
---|
436 | super(B738Charter, self).__init__(flight)
|
---|
437 | self.mtow = 77791
|
---|
438 |
|
---|
439 | #---------------------------------------------------------------------------------------
|
---|
440 |
|
---|
441 | class B733(Boeing737):
|
---|
442 | """Boeing 737-300 aircraft."""
|
---|
443 | def __init__(self, flight):
|
---|
444 | super(B733, self).__init__(flight)
|
---|
445 | self.dow = 32700
|
---|
446 | self.mtow = 62820
|
---|
447 | self.mlw = 51700
|
---|
448 | self.mzfw = 48410
|
---|
449 |
|
---|
450 | #---------------------------------------------------------------------------------------
|
---|
451 |
|
---|
452 | class B734(Boeing737):
|
---|
453 | """Boeing 737-400 aircraft."""
|
---|
454 | def __init__(self, flight):
|
---|
455 | super(B734, self).__init__(flight)
|
---|
456 | self.dow = 33200
|
---|
457 | self.mtow = 68050
|
---|
458 | self.mlw = 56200
|
---|
459 | self.mzfw = 53100
|
---|
460 |
|
---|
461 | #---------------------------------------------------------------------------------------
|
---|
462 |
|
---|
463 | class B735(Boeing737):
|
---|
464 | """Boeing 737-500 aircraft."""
|
---|
465 | def __init__(self, flight):
|
---|
466 | super(B735, self).__init__(flight)
|
---|
467 | self.dow = 31300
|
---|
468 | self.mtow = 60550
|
---|
469 | self.mlw = 50000
|
---|
470 | self.mzfw = 46700
|
---|
471 |
|
---|
472 | #---------------------------------------------------------------------------------------
|
---|
473 |
|
---|
474 | class DH8D(Aircraft):
|
---|
475 | """Bombardier Dash-8 Q400 aircraft.
|
---|
476 |
|
---|
477 | The aircraft type-specific values in the aircraft state have the following
|
---|
478 | structure:
|
---|
479 | - fuel: left, right
|
---|
480 | - n1: left, right
|
---|
481 | - reverser: left, right."""
|
---|
482 | fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]
|
---|
483 |
|
---|
484 | def __init__(self, flight):
|
---|
485 | super(DH8D, self).__init__(flight)
|
---|
486 | self.dow = 17185
|
---|
487 | self.mtow = 29257
|
---|
488 | self.mlw = 28009
|
---|
489 | self.mzfw = 25855
|
---|
490 | self.gearSpeedLimit = 215
|
---|
491 | self.flapSpeedLimits = { 5 : 200,
|
---|
492 | 10 : 181,
|
---|
493 | 15 : 172,
|
---|
494 | 35 : 158 }
|
---|
495 |
|
---|
496 | def logFuel(self, aircraftState):
|
---|
497 | """Log the amount of fuel"""
|
---|
498 | self.logger.message(aircraftState.timestamp,
|
---|
499 | "Fuel: left=%.0f kg - right=%.0f kg" % \
|
---|
500 | (aircraftState.fuel[0], aircraftState.fuel[1]))
|
---|
501 | self.logger.message(aircraftState.timestamp,
|
---|
502 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
503 |
|
---|
504 | #---------------------------------------------------------------------------------------
|
---|
505 |
|
---|
506 | class Boeing767(Aircraft):
|
---|
507 | """Base class for the various aircraft in the Boeing 767 family.
|
---|
508 |
|
---|
509 | The aircraft type-specific values in the aircraft state have the following
|
---|
510 | structure:
|
---|
511 | - fuel: left, centre, right
|
---|
512 | - n1: left, right
|
---|
513 | - reverser: left, right"""
|
---|
514 | fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]
|
---|
515 |
|
---|
516 | def __init__(self, flight):
|
---|
517 | super(Boeing767, self).__init__(flight)
|
---|
518 | self._checkers.append(checks.ThrustChecker())
|
---|
519 | self.gearSpeedLimit = 270
|
---|
520 | self.flapSpeedLimits = { 1 : 255,
|
---|
521 | 5 : 235,
|
---|
522 | 10 : 215,
|
---|
523 | 20 : 215,
|
---|
524 | 25 : 185,
|
---|
525 | 30 : 175 }
|
---|
526 |
|
---|
527 | def logFuel(self, aircraftState):
|
---|
528 | """Log the amount of fuel"""
|
---|
529 | self.logger.message(aircraftState.timestamp,
|
---|
530 | "Fuel: left=%.0f kg - centre=%.0f kg - right=%.0f kg" % \
|
---|
531 | (aircraftState.fuel[0], aircraftState.fuel[1],
|
---|
532 | aircraftState.fuel[2]))
|
---|
533 | self.logger.message(aircraftState.timestamp,
|
---|
534 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
535 |
|
---|
536 | #---------------------------------------------------------------------------------------
|
---|
537 |
|
---|
538 | class B762(Boeing767):
|
---|
539 | """Boeing 767-200 aircraft."""
|
---|
540 | def __init__(self, flight):
|
---|
541 | super(B762, self).__init__(flight)
|
---|
542 | self.dow = 84507
|
---|
543 | self.mtow = 175540
|
---|
544 | self.mlw = 126098
|
---|
545 | self.mzfw = 114758
|
---|
546 |
|
---|
547 | #---------------------------------------------------------------------------------------
|
---|
548 |
|
---|
549 | class B763(Boeing767):
|
---|
550 | """Boeing 767-300 aircraft."""
|
---|
551 | def __init__(self, flight):
|
---|
552 | super(B763, self).__init__(cflight)
|
---|
553 | self.dow = 91311
|
---|
554 | self.mtow = 181436
|
---|
555 | self.mlw = 137892
|
---|
556 | self.mzfw = 130635
|
---|
557 |
|
---|
558 | #---------------------------------------------------------------------------------------
|
---|
559 |
|
---|
560 | class CRJ2(Aircraft):
|
---|
561 | """Bombardier CRJ-200 aircraft.
|
---|
562 |
|
---|
563 | The aircraft type-specific values in the aircraft state have the following
|
---|
564 | structure:
|
---|
565 | - fuel: left, centre, right
|
---|
566 | - n1: left, right
|
---|
567 | - reverser: left, right."""
|
---|
568 | fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]
|
---|
569 |
|
---|
570 | def __init__(self, flight):
|
---|
571 | super(CRJ2, self).__init__(flight)
|
---|
572 | self._checkers.append(checks.ThrustChecker())
|
---|
573 | self.dow = 14549
|
---|
574 | self.mtow = 22995
|
---|
575 | self.mlw = 21319
|
---|
576 | self.mzfw = 19958
|
---|
577 | self.gearSpeedLimit = 240
|
---|
578 | self.flapSpeedLimits = { 8 : 260,
|
---|
579 | 20 : 220,
|
---|
580 | 30 : 190,
|
---|
581 | 45 : 175 }
|
---|
582 |
|
---|
583 | def logFuel(self, aircraftState):
|
---|
584 | """Log the amount of fuel"""
|
---|
585 | self.logger.message(aircraftState.timestamp,
|
---|
586 | "Fuel: left=%.0f kg - centre=%.0f kg - right=%.0f kg" % \
|
---|
587 | (aircraftState.fuel[0], aircraftState.fuel[1],
|
---|
588 | aircraftState.fuel[2]))
|
---|
589 | self.logger.message(aircraftState.timestamp,
|
---|
590 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
591 |
|
---|
592 | #---------------------------------------------------------------------------------------
|
---|
593 |
|
---|
594 | class F70(Aircraft):
|
---|
595 | """Fokker 70 aircraft.
|
---|
596 |
|
---|
597 | The aircraft type-specific values in the aircraft state have the following
|
---|
598 | structure:
|
---|
599 | - fuel: left, centre, right
|
---|
600 | - n1: left, right
|
---|
601 | - reverser: left, right."""
|
---|
602 | fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]
|
---|
603 |
|
---|
604 | def __init__(self, flight):
|
---|
605 | super(F70, self).__init__(flight)
|
---|
606 | self._checkers.append(checks.ThrustChecker())
|
---|
607 | self.dow = 24283
|
---|
608 | self.mtow = 38100 # FIXME: differentiate by registration number,
|
---|
609 | # MTOW of HA-LMF: 41955
|
---|
610 | self.mlw = 36740
|
---|
611 | self.mzfw = 32655
|
---|
612 | self.gearSpeedLimit = 200
|
---|
613 | self.flapSpeedLimits = { 8 : 250,
|
---|
614 | 15 : 220,
|
---|
615 | 25 : 220,
|
---|
616 | 42 : 180 }
|
---|
617 |
|
---|
618 | def logFuel(self, aircraftState):
|
---|
619 | """Log the amount of fuel"""
|
---|
620 | self.logger.message(aircraftState.timestamp,
|
---|
621 | "Fuel: left=%.0f kg - centre=%.0f kg - right=%.0f kg" % \
|
---|
622 | (aircraftState.fuel[0], aircraftState.fuel[1],
|
---|
623 | aircraftState.fuel[2]))
|
---|
624 | self.logger.message(aircraftState.timestamp,
|
---|
625 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
626 |
|
---|
627 | #---------------------------------------------------------------------------------------
|
---|
628 |
|
---|
629 | class DC3(Aircraft):
|
---|
630 | """Lisunov Li-2 (DC-3) aircraft.
|
---|
631 |
|
---|
632 | The aircraft type-specific values in the aircraft state have the following
|
---|
633 | structure:
|
---|
634 | - fuel: left aux, left, right, right aux
|
---|
635 | - rpm: left, right
|
---|
636 | - reverser: left, right."""
|
---|
637 | fuelTanks = [const.FUELTANK_LEFT_AUX, const.FUELTANK_LEFT,
|
---|
638 | const.FUELTANK_RIGHT, const.FUELTANK_RIGHT_AUX]
|
---|
639 |
|
---|
640 | def __init__(self, flight):
|
---|
641 | super(DC3, self).__init__(flight)
|
---|
642 | self.dow = 8627
|
---|
643 | self.mtow = 11884
|
---|
644 | self.mlw = 11793
|
---|
645 | self.mzfw = 11780
|
---|
646 | self.gearSpeedLimit = 148
|
---|
647 | self.flapSpeedLimits = { 15 : 135,
|
---|
648 | 30 : 99,
|
---|
649 | 45 : 97 }
|
---|
650 |
|
---|
651 | def _checkFlightEnd(self, aircraftState):
|
---|
652 | """Check if the end of the flight has arrived.
|
---|
653 |
|
---|
654 | This implementation checks the RPM values to be 0."""
|
---|
655 | for rpm in aircraftState.rpm:
|
---|
656 | if rpm>0: return False
|
---|
657 | return True
|
---|
658 |
|
---|
659 | def logFuel(self, aircraftState):
|
---|
660 | """Log the amount of fuel"""
|
---|
661 | self.logger.message(aircraftState.timestamp,
|
---|
662 | "Fuel: left aux=%.0f kg - left=%.0f kg - right=%.0f kg - right aux=%.0f kg" % \
|
---|
663 | (aircraftState.fuel[0], aircraftState.fuel[1],
|
---|
664 | aircraftState.fuel[2], aircraftState.fuel[3]))
|
---|
665 | self.logger.message(aircraftState.timestamp,
|
---|
666 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
667 |
|
---|
668 | #---------------------------------------------------------------------------------------
|
---|
669 |
|
---|
670 | class T134(Aircraft):
|
---|
671 | """Tupolev Tu-134 aircraft.
|
---|
672 |
|
---|
673 | The aircraft type-specific values in the aircraft state have the following
|
---|
674 | structure:
|
---|
675 | - fuel: left tip, left aux, centre, right aux, right tip, external 1,
|
---|
676 | external 2
|
---|
677 | - n1: left, right
|
---|
678 | - reverser: left, right."""
|
---|
679 | fuelTanks = [const.FUELTANK_LEFT_TIP, const.FUELTANK_EXTERNAL1,
|
---|
680 | const.FUELTANK_LEFT_AUX,
|
---|
681 | const.FUELTANK_CENTRE,
|
---|
682 | const.FUELTANK_RIGHT_AUX,
|
---|
683 | const.FUELTANK_EXTERNAL2, const.FUELTANK_RIGHT_TIP]
|
---|
684 |
|
---|
685 | def __init__(self, flight):
|
---|
686 | super(T134, self).__init__(flight)
|
---|
687 | self._checkers.append(checks.ThrustChecker())
|
---|
688 | self.dow = 29927
|
---|
689 | self.mtow = 47600
|
---|
690 | self.mlw = 43000
|
---|
691 | self.mzfw = 38500
|
---|
692 | self.gearSpeedLimit = 216
|
---|
693 | self.flapSpeedLimits = { 10 : 240,
|
---|
694 | 20 : 216,
|
---|
695 | 30 : 161 }
|
---|
696 |
|
---|
697 | def logFuel(self, aircraftState):
|
---|
698 | """Log the amount of fuel"""
|
---|
699 | self.logger.message(aircraftState.timestamp,
|
---|
700 | "Fuel: left aux=%.0f kg - left tip=%.0f kg - centre= %.0f kg - right tip=%.0f kg - right aux=%.0f kg - external 1=%.0f kg - external 2=%.0f kg" % \
|
---|
701 | (aircraftState.fuel[1], aircraftState.fuel[0],
|
---|
702 | aircraftState.fuel[2],
|
---|
703 | aircraftState.fuel[4], aircraftState.fuel[3],
|
---|
704 | aircraftState.fuel[5], aircraftState.fuel[6]))
|
---|
705 | self.logger.message(aircraftState.timestamp,
|
---|
706 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
707 |
|
---|
708 | #---------------------------------------------------------------------------------------
|
---|
709 |
|
---|
710 | class T154(Aircraft):
|
---|
711 | """Tupolev Tu-154 aircraft.
|
---|
712 |
|
---|
713 | The aircraft type-specific values in the aircraft state have the following
|
---|
714 | structure:
|
---|
715 | - fuel: left aux, left, centre, centre 2, right, right aux
|
---|
716 | - n1: left, centre, right
|
---|
717 | - reverser: left, right"""
|
---|
718 | fuelTanks = [const.FUELTANK_LEFT_AUX, const.FUELTANK_LEFT,
|
---|
719 | const.FUELTANK_CENTRE, const.FUELTANK_CENTRE2,
|
---|
720 | const.FUELTANK_RIGHT, const.FUELTANK_RIGHT_AUX]
|
---|
721 | def __init__(self, flight):
|
---|
722 | super(T154, self).__init__(flight)
|
---|
723 | self._checkers.append(checks.ThrustChecker())
|
---|
724 | self.dow = 53259
|
---|
725 | self.mtow = 98000
|
---|
726 | self.mlw = 78000
|
---|
727 | self.mzfw = 72000
|
---|
728 | self.gearSpeedLimit = 216
|
---|
729 | self.flapSpeedLimits = { 15 : 227,
|
---|
730 | 28 : 194,
|
---|
731 | 45 : 162 }
|
---|
732 |
|
---|
733 | def logFuel(self, aircraftState):
|
---|
734 | """Log the amount of fuel"""
|
---|
735 | self.logger.message(aircraftState.timestamp,
|
---|
736 | "Fuel: left aux=%.0f kg - left=%.0f kg - centre=%.0f kg - centre 2=%.0f kg - right=%.0f kg - right aux=%.0f kg" % \
|
---|
737 | (aircraftState.fuel[0], aircraftState.fuel[1],
|
---|
738 | aircraftState.fuel[2], aircraftState.fuel[3],
|
---|
739 | aircraftState.fuel[4], aircraftState.fuel[5]))
|
---|
740 | self.logger.message(aircraftState.timestamp,
|
---|
741 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
742 |
|
---|
743 | #---------------------------------------------------------------------------------------
|
---|
744 |
|
---|
745 |
|
---|
746 | class YK40(Aircraft):
|
---|
747 | """Yakovlev Yak-40 aircraft.
|
---|
748 |
|
---|
749 | The aircraft type-specific values in the aircraft state have the following
|
---|
750 | structure:
|
---|
751 | - fuel: left, right
|
---|
752 | - n1: left, right
|
---|
753 | - reverser: left, right"""
|
---|
754 | fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]
|
---|
755 |
|
---|
756 | def __init__(self, flight):
|
---|
757 | super(YK40, self).__init__(flight)
|
---|
758 | self._checkers.append(checks.ThrustChecker())
|
---|
759 | self.dow = 9400
|
---|
760 | self.mtow = 17200
|
---|
761 | self.mlw = 16800
|
---|
762 | self.mzfw = 12100
|
---|
763 | self.gearSpeedLimit = 165
|
---|
764 | self.flapSpeedLimits = { 20 : 165,
|
---|
765 | 35 : 135 }
|
---|
766 |
|
---|
767 | def logFuel(self, aircraftState):
|
---|
768 | """Log the amount of fuel"""
|
---|
769 | self.logger.message(aircraftState.timestamp,
|
---|
770 | "Fuel: left=%.0f kg - right=%.0f kg" % \
|
---|
771 | (aircraftState.fuel[0], aircraftState.fuel[1]))
|
---|
772 | self.logger.message(aircraftState.timestamp,
|
---|
773 | "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
|
---|
774 |
|
---|
775 | #---------------------------------------------------------------------------------------
|
---|
776 |
|
---|
777 | MostFuelTankAircraft = T134
|
---|
778 |
|
---|
779 | #---------------------------------------------------------------------------------------
|
---|
780 |
|
---|
781 | _classes = { const.AIRCRAFT_B736 : B736,
|
---|
782 | const.AIRCRAFT_B737 : B737,
|
---|
783 | const.AIRCRAFT_B738 : B738,
|
---|
784 | const.AIRCRAFT_B738C : B738Charter,
|
---|
785 | const.AIRCRAFT_B733 : B733,
|
---|
786 | const.AIRCRAFT_B734 : B734,
|
---|
787 | const.AIRCRAFT_B735 : B735,
|
---|
788 | const.AIRCRAFT_DH8D : DH8D,
|
---|
789 | const.AIRCRAFT_B762 : B762,
|
---|
790 | const.AIRCRAFT_B763 : B763,
|
---|
791 | const.AIRCRAFT_CRJ2 : CRJ2,
|
---|
792 | const.AIRCRAFT_F70 : F70,
|
---|
793 | const.AIRCRAFT_DC3 : DC3,
|
---|
794 | const.AIRCRAFT_T134 : T134,
|
---|
795 | const.AIRCRAFT_T154 : T154,
|
---|
796 | const.AIRCRAFT_YK40 : YK40 }
|
---|
797 |
|
---|
798 | #---------------------------------------------------------------------------------------
|
---|
799 |
|
---|
800 | if __name__ == "__main__":
|
---|
801 | value = SmoothedValue()
|
---|
802 |
|
---|
803 | print "Adding 1, 12.0"
|
---|
804 | value.add(1, 12.0)
|
---|
805 | print value.get()
|
---|
806 |
|
---|
807 | print "Adding 1, 15.0"
|
---|
808 | value.add(1, 15.0)
|
---|
809 | print value.get()
|
---|
810 |
|
---|
811 | print "Adding 2, 18.0"
|
---|
812 | value.add(2, 18.0)
|
---|
813 | print value.get()
|
---|
814 |
|
---|
815 | print "Adding 2, 20.0"
|
---|
816 | value.add(2, 20.0)
|
---|
817 | print value.get()
|
---|
818 |
|
---|
819 | print "Adding 5, 22.0"
|
---|
820 | value.add(5, 22.0)
|
---|
821 | print value.get()
|
---|
822 |
|
---|
823 | print "Adding 5, 25.0"
|
---|
824 | value.add(5, 25.0)
|
---|
825 | print value.get()
|
---|
826 |
|
---|
827 | print "Adding 5, 29.0"
|
---|
828 | value.add(5, 29.0)
|
---|
829 | print value.get()
|
---|
830 |
|
---|
831 | print "Adding 5, 21.0"
|
---|
832 | value.add(5, 21.0)
|
---|
833 | print value.get()
|
---|
834 |
|
---|
835 | print "Adding 5, 26.0"
|
---|
836 | value.add(5, 26.0)
|
---|
837 | print value.get()
|
---|
838 |
|
---|
839 | print "Adding 2, 30.0"
|
---|
840 | value.add(2, 30.0)
|
---|
841 | print value.get()
|
---|
842 |
|
---|
843 | print "Adding 2, 55.0"
|
---|
844 | value.add(2, 55.0)
|
---|
845 | print value.get()
|
---|
846 |
|
---|
847 | #---------------------------------------------------------------------------------------
|
---|