1 | # Module for the simulator-independent aircraft classes
|
---|
2 |
|
---|
3 | #---------------------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | import const
|
---|
6 | import checks
|
---|
7 |
|
---|
8 | import time
|
---|
9 |
|
---|
10 | #---------------------------------------------------------------------------------------
|
---|
11 |
|
---|
12 | class Aircraft(object):
|
---|
13 | """Base class for aircraft."""
|
---|
14 | @staticmethod
|
---|
15 | def create(flight):
|
---|
16 | """Create an aircraft instance for the type in the given flight."""
|
---|
17 | return _classes[flight.aircraftType](flight)
|
---|
18 |
|
---|
19 | def __init__(self, flight):
|
---|
20 | """Construct the aircraft for the given type."""
|
---|
21 | self._flight = flight
|
---|
22 | self._aircraftState = None
|
---|
23 |
|
---|
24 | self._checkers = []
|
---|
25 |
|
---|
26 | self._checkers.append(checks.StageChecker())
|
---|
27 |
|
---|
28 | self._checkers.append(checks.AltimeterLogger())
|
---|
29 |
|
---|
30 | self._checkers.append(checks.NAV1Logger())
|
---|
31 | self._checkers.append(checks.NAV2Logger())
|
---|
32 | self._checkers.append(checks.SquawkLogger())
|
---|
33 |
|
---|
34 | self._checkers.append(checks.AnticollisionLightsLogger())
|
---|
35 | self._checkers.append(checks.LandingLightsLogger())
|
---|
36 | self._checkers.append(checks.StrobeLightsLogger())
|
---|
37 | self._checkers.append(checks.NavLightsLogger())
|
---|
38 |
|
---|
39 | self._checkers.append(checks.FlapsLogger())
|
---|
40 |
|
---|
41 | self._checkers.append(checks.GearsLogger())
|
---|
42 |
|
---|
43 | @property
|
---|
44 | def type(self):
|
---|
45 | """Get the type of the aircraft."""
|
---|
46 | return self._flight.aircraftType
|
---|
47 |
|
---|
48 | @property
|
---|
49 | def flight(self):
|
---|
50 | """Get the flight the aircraft belongs to."""
|
---|
51 | return self._flight
|
---|
52 |
|
---|
53 | @property
|
---|
54 | def logger(self):
|
---|
55 | """Get the logger to use for the aircraft."""
|
---|
56 | return self._flight.logger
|
---|
57 |
|
---|
58 | def modelChanged(self, timestamp, aircraftName, modelName):
|
---|
59 | """Called when the simulator's aircraft changes."""
|
---|
60 | self._flight.logger.message(timestamp,
|
---|
61 | "Aircraft: name='%s', model='%s'" % \
|
---|
62 | (aircraftName, modelName))
|
---|
63 |
|
---|
64 | def handleState(self, aircraftState):
|
---|
65 | """Called when the state of the aircraft changes."""
|
---|
66 | for checker in self._checkers:
|
---|
67 | checker.check(self._flight, self, self._flight.logger,
|
---|
68 | self._aircraftState, aircraftState)
|
---|
69 |
|
---|
70 | self._aircraftState = aircraftState
|
---|
71 |
|
---|
72 | def setStage(self, aircraftState, newStage):
|
---|
73 | """Set the given stage as the new one and do whatever should be
|
---|
74 | done."""
|
---|
75 | self._flight.setStage(aircraftState.timestamp, newStage)
|
---|
76 |
|
---|
77 | def flare(self):
|
---|
78 | """Called when it is detected that we are during flare.
|
---|
79 |
|
---|
80 | On the first call, it should start monitoring some parameters more
|
---|
81 | closely to determine flare time."""
|
---|
82 | pass
|
---|
83 |
|
---|
84 | def cancelFlare(self):
|
---|
85 | """Cancel flare, if it has started."""
|
---|
86 | pass
|
---|
87 |
|
---|
88 | def checkFlightEnd(self, aircraftState):
|
---|
89 | """Check if the end of the flight has arrived.
|
---|
90 |
|
---|
91 | This default implementation checks the N1 values, but for
|
---|
92 | piston-powered aircraft you need to check the RPMs."""
|
---|
93 | for n1 in aircraftState.n1:
|
---|
94 | if n1>=0.5: return False
|
---|
95 | return True
|
---|
96 |
|
---|
97 | #---------------------------------------------------------------------------------------
|
---|
98 |
|
---|
99 | class Boeing737(Aircraft):
|
---|
100 | """Base class for the various aircraft in the Boeing 737 family.
|
---|
101 |
|
---|
102 | The aircraft type-specific values in the aircraft state have the following
|
---|
103 | structure:
|
---|
104 | - fuel: centre, left, right
|
---|
105 | - n1: left, right
|
---|
106 | - reverser: left, right"""
|
---|
107 | pass
|
---|
108 |
|
---|
109 | #---------------------------------------------------------------------------------------
|
---|
110 |
|
---|
111 | class B736(Boeing737):
|
---|
112 | """Boeing 737-600 aircraft."""
|
---|
113 | def __init__(self, flight):
|
---|
114 | super(B736, self).__init__(flight)
|
---|
115 |
|
---|
116 | #---------------------------------------------------------------------------------------
|
---|
117 |
|
---|
118 | class B737(Boeing737):
|
---|
119 | """Boeing 737-700 aircraft."""
|
---|
120 | def __init__(self, flight):
|
---|
121 | super(B737, self).__init__(flight)
|
---|
122 |
|
---|
123 | #---------------------------------------------------------------------------------------
|
---|
124 |
|
---|
125 | class B738(Boeing737):
|
---|
126 | """Boeing 737-800 aircraft."""
|
---|
127 | def __init__(self, flight):
|
---|
128 | super(B738, self).__init__(flight)
|
---|
129 |
|
---|
130 | #---------------------------------------------------------------------------------------
|
---|
131 |
|
---|
132 | class B733(Boeing737):
|
---|
133 | """Boeing 737-300 aircraft."""
|
---|
134 | def __init__(self, flight):
|
---|
135 | super(B733, self).__init__(flight)
|
---|
136 |
|
---|
137 | #---------------------------------------------------------------------------------------
|
---|
138 |
|
---|
139 | class B734(Boeing737):
|
---|
140 | """Boeing 737-400 aircraft."""
|
---|
141 | def __init__(self, flight):
|
---|
142 | super(B734, self).__init__(flight)
|
---|
143 |
|
---|
144 | #---------------------------------------------------------------------------------------
|
---|
145 |
|
---|
146 | class B735(Boeing737):
|
---|
147 | """Boeing 737-500 aircraft."""
|
---|
148 | def __init__(self, flight):
|
---|
149 | super(B735, self).__init__(flight)
|
---|
150 |
|
---|
151 | #---------------------------------------------------------------------------------------
|
---|
152 |
|
---|
153 | class DH8D(Aircraft):
|
---|
154 | """Bombardier Dash-8 Q400 aircraft.
|
---|
155 |
|
---|
156 | The aircraft type-specific values in the aircraft state have the following
|
---|
157 | structure:
|
---|
158 | - fuel: centre, left, right
|
---|
159 | - n1: left, right
|
---|
160 | - reverser: left, right."""
|
---|
161 | def __init__(self, flight):
|
---|
162 | super(DH8D, self).__init__(flight)
|
---|
163 |
|
---|
164 | #---------------------------------------------------------------------------------------
|
---|
165 |
|
---|
166 | class Boeing767(Aircraft):
|
---|
167 | """Base class for the various aircraft in the Boeing 767 family.
|
---|
168 |
|
---|
169 | The aircraft type-specific values in the aircraft state have the following
|
---|
170 | structure:
|
---|
171 | - fuel: centre, left, right
|
---|
172 | - n1: left, right
|
---|
173 | - reverser: left, right"""
|
---|
174 |
|
---|
175 | #---------------------------------------------------------------------------------------
|
---|
176 |
|
---|
177 | class B762(Boeing767):
|
---|
178 | """Boeing 767-200 aircraft."""
|
---|
179 | def __init__(self, flight):
|
---|
180 | super(B762, self).__init__(flight)
|
---|
181 |
|
---|
182 | #---------------------------------------------------------------------------------------
|
---|
183 |
|
---|
184 | class B763(Boeing767):
|
---|
185 | """Boeing 767-300 aircraft."""
|
---|
186 | def __init__(self, flight):
|
---|
187 | super(B763, self).__init__(cflight)
|
---|
188 |
|
---|
189 | #---------------------------------------------------------------------------------------
|
---|
190 |
|
---|
191 | class CRJ2(Aircraft):
|
---|
192 | """Bombardier CRJ-200 aircraft.
|
---|
193 |
|
---|
194 | The aircraft type-specific values in the aircraft state have the following
|
---|
195 | structure:
|
---|
196 | - fuel: centre, left, right
|
---|
197 | - n1: left, right
|
---|
198 | - reverser: left, right."""
|
---|
199 | def __init__(self, flight):
|
---|
200 | super(CRJ2, self).__init__(flight)
|
---|
201 |
|
---|
202 | #---------------------------------------------------------------------------------------
|
---|
203 |
|
---|
204 | class F70(Aircraft):
|
---|
205 | """Fokker 70 aircraft.
|
---|
206 |
|
---|
207 | The aircraft type-specific values in the aircraft state have the following
|
---|
208 | structure:
|
---|
209 | - fuel: centre, left, right
|
---|
210 | - n1: left, right
|
---|
211 | - reverser: left, right."""
|
---|
212 | def __init__(self, flight):
|
---|
213 | super(F70, self).__init__(flight)
|
---|
214 |
|
---|
215 | #---------------------------------------------------------------------------------------
|
---|
216 |
|
---|
217 | class DC3(Aircraft):
|
---|
218 | """Lisunov Li-2 (DC-3) aircraft.
|
---|
219 |
|
---|
220 | The aircraft type-specific values in the aircraft state have the following
|
---|
221 | structure:
|
---|
222 | - fuel: left, right, left aux, right aix
|
---|
223 | - rpm: left, right
|
---|
224 | - reverser: left, right."""
|
---|
225 | def __init__(self, flight):
|
---|
226 | super(DC3, self).__init__(flight)
|
---|
227 |
|
---|
228 | def _checkFlightEnd(self, aircraftState):
|
---|
229 | """Check if the end of the flight has arrived.
|
---|
230 |
|
---|
231 | This implementation checks the RPM values to be 0."""
|
---|
232 | for rpm in aircraftState.rpm:
|
---|
233 | if rpm>0: return
|
---|
234 | self._setStage(aircraftState, const.STAGE_END)
|
---|
235 |
|
---|
236 | #---------------------------------------------------------------------------------------
|
---|
237 |
|
---|
238 | class T134(Aircraft):
|
---|
239 | """Tupolev Tu-134 aircraft.
|
---|
240 |
|
---|
241 | The aircraft type-specific values in the aircraft state have the following
|
---|
242 | structure:
|
---|
243 | - fuel: centre, left tip, left aux, right tip, right aux, external 1,
|
---|
244 | external 2
|
---|
245 | - n1: left, right
|
---|
246 | - reverser: left, right."""
|
---|
247 | def __init__(self, flight):
|
---|
248 | super(T134, self).__init__(flight)
|
---|
249 |
|
---|
250 | #---------------------------------------------------------------------------------------
|
---|
251 |
|
---|
252 | class T154(Aircraft):
|
---|
253 | """Tupolev Tu-154 aircraft.
|
---|
254 |
|
---|
255 | The aircraft type-specific values in the aircraft state have the following
|
---|
256 | structure:
|
---|
257 | - fuel: centre, left, right, centre 2, left aux, right aux
|
---|
258 | - n1: left, centre, right
|
---|
259 | - reverser: left, right"""
|
---|
260 | def __init__(self, flight):
|
---|
261 | super(T154, self).__init__(flight)
|
---|
262 |
|
---|
263 | #---------------------------------------------------------------------------------------
|
---|
264 |
|
---|
265 | class YK40(Aircraft):
|
---|
266 | """Yakovlev Yak-40 aircraft.
|
---|
267 |
|
---|
268 | The aircraft type-specific values in the aircraft state have the following
|
---|
269 | structure:
|
---|
270 | - fuel: left, right
|
---|
271 | - n1: left, right
|
---|
272 | - reverser: left, right"""
|
---|
273 | def __init__(self, flight):
|
---|
274 | super(YK40, self).__init__(flight)
|
---|
275 |
|
---|
276 | #---------------------------------------------------------------------------------------
|
---|
277 |
|
---|
278 | _classes = { const.AIRCRAFT_B736 : B736,
|
---|
279 | const.AIRCRAFT_B737 : B737,
|
---|
280 | const.AIRCRAFT_B738 : B738,
|
---|
281 | const.AIRCRAFT_B733 : B733,
|
---|
282 | const.AIRCRAFT_B734 : B734,
|
---|
283 | const.AIRCRAFT_B735 : B735,
|
---|
284 | const.AIRCRAFT_DH8D : DH8D,
|
---|
285 | const.AIRCRAFT_B762 : B762,
|
---|
286 | const.AIRCRAFT_B763 : B763,
|
---|
287 | const.AIRCRAFT_CRJ2 : CRJ2,
|
---|
288 | const.AIRCRAFT_F70 : F70,
|
---|
289 | const.AIRCRAFT_DC3 : DC3,
|
---|
290 | const.AIRCRAFT_T134 : T134,
|
---|
291 | const.AIRCRAFT_T154 : T154,
|
---|
292 | const.AIRCRAFT_YK40 : YK40 }
|
---|
293 |
|
---|
294 | #---------------------------------------------------------------------------------------
|
---|