Changeset 8:85698811c70e for src/acft.py
- Timestamp:
- 02/04/12 15:10:19 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/acft.py
r7 r8 3 3 #--------------------------------------------------------------------------------------- 4 4 5 import const 6 import checks 7 5 8 import time 6 7 import const8 9 9 10 #--------------------------------------------------------------------------------------- … … 11 12 class Aircraft(object): 12 13 """Base class for aircraft.""" 13 def __init__(self, type): 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): 14 20 """Construct the aircraft for the given type.""" 15 self._ type = type21 self._flight = flight 16 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()) 17 42 18 43 @property 19 44 def type(self): 20 45 """Get the type of the aircraft.""" 21 return self._type 22 23 def modelChanged(self, aircraftName, modelName): 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): 24 59 """Called when the simulator's aircraft changes.""" 25 print "Aircraft.modelChanged: aircraftName='%s', modelName='%s'" % \ 26 (aircraftName, modelName) 60 self._flight.logger.message(timestamp, 61 "Aircraft: name='%s', model='%s'" % \ 62 (aircraftName, modelName)) 27 63 28 64 def handleState(self, aircraftState): 29 65 """Called when the state of the aircraft changes.""" 30 timeStr = time.ctime(aircraftState.timestamp) 31 32 if self._aircraftState is None or \ 33 self._aircraftState.paused != aircraftState.paused: 34 print "Aircraft.handleState: %s: paused=%d" % \ 35 (timeStr, aircraftState.paused) 36 37 if self._aircraftState is None or \ 38 self._aircraftState.trickMode != aircraftState.trickMode: 39 print "Aircraft.handleState: %s: trickMode=%d" % \ 40 (timeStr, aircraftState.trickMode) 41 42 if self._aircraftState is None or \ 43 self._aircraftState.overspeed != aircraftState.overspeed: 44 print "Aircraft.handleState: %s: overspeed=%d" % \ 45 (timeStr, aircraftState.overspeed) 46 47 if self._aircraftState is None or \ 48 self._aircraftState.stalled != aircraftState.stalled: 49 print "Aircraft.handleState: %s: stalled=%d" % \ 50 (timeStr, aircraftState.stalled) 51 52 if self._aircraftState is None or \ 53 self._aircraftState.onTheGround != aircraftState.onTheGround: 54 print "Aircraft.handleState: %s: onTheGround=%d" % \ 55 (timeStr, aircraftState.onTheGround) 56 57 if self._aircraftState is None or \ 58 self._aircraftState.grossWeight != aircraftState.grossWeight: 59 print "Aircraft.handleState: %s: grossWeight=%f" % \ 60 (timeStr, aircraftState.grossWeight) 61 62 if self._aircraftState is None or \ 63 self._aircraftState.heading != aircraftState.heading: 64 print "Aircraft.handleState: %s: heading=%f" % \ 65 (timeStr, aircraftState.heading) 66 67 if self._aircraftState is None or \ 68 self._aircraftState.pitch != aircraftState.pitch: 69 print "Aircraft.handleState: %s: pitch=%f" % \ 70 (timeStr, aircraftState.pitch) 71 72 if self._aircraftState is None or \ 73 self._aircraftState.bank != aircraftState.bank: 74 print "Aircraft.handleState: %s: bank=%f" % \ 75 (timeStr, aircraftState.bank) 76 77 if self._aircraftState is None or \ 78 self._aircraftState.ias != aircraftState.ias: 79 print "Aircraft.handleState: %s: ias=%f" % \ 80 (timeStr, aircraftState.ias) 81 82 if self._aircraftState is None or \ 83 self._aircraftState.groundSpeed != aircraftState.groundSpeed: 84 print "Aircraft.handleState: %s: groundSpeed=%f" % \ 85 (timeStr, aircraftState.groundSpeed) 86 87 if self._aircraftState is None or \ 88 self._aircraftState.vs != aircraftState.vs: 89 print "Aircraft.handleState: %s: vs=%f" % \ 90 (timeStr, aircraftState.vs) 91 92 if self._aircraftState is None or \ 93 self._aircraftState.altitude != aircraftState.altitude: 94 print "Aircraft.handleState: %s: altitude=%f" % \ 95 (timeStr, aircraftState.altitude) 96 97 if self._aircraftState is None or \ 98 self._aircraftState.gLoad != aircraftState.gLoad: 99 print "Aircraft.handleState: %s: gLoad=%f" % \ 100 (timeStr, aircraftState.gLoad) 101 102 if self._aircraftState is None or \ 103 self._aircraftState.flapsSet != aircraftState.flapsSet: 104 print "Aircraft.handleState: %s: flapsSet=%f" % \ 105 (timeStr, aircraftState.flapsSet) 106 107 if self._aircraftState is None or \ 108 self._aircraftState.flaps != aircraftState.flaps: 109 print "Aircraft.handleState: %s: flaps=%f" % \ 110 (timeStr, aircraftState.flaps) 111 112 if self._aircraftState is None or \ 113 self._aircraftState.navLightsOn != aircraftState.navLightsOn: 114 print "Aircraft.handleState: %s: navLightsOn=%d" % \ 115 (timeStr, aircraftState.navLightsOn) 116 117 if self._aircraftState is None or \ 118 self._aircraftState.antiCollisionLightsOn != aircraftState.antiCollisionLightsOn: 119 print "Aircraft.handleState: %s: antiCollisionLightsOn=%d" % \ 120 (timeStr, aircraftState.antiCollisionLightsOn) 121 122 if self._aircraftState is None or \ 123 self._aircraftState.strobeLightsOn != aircraftState.strobeLightsOn: 124 print "Aircraft.handleState: %s: strobeLightsOn=%d" % \ 125 (timeStr, aircraftState.strobeLightsOn) 126 127 if self._aircraftState is None or \ 128 self._aircraftState.landingLightsOn != aircraftState.landingLightsOn: 129 print "Aircraft.handleState: %s: landingLightsOn=%d" % \ 130 (timeStr, aircraftState.landingLightsOn) 131 132 if self._aircraftState is None or \ 133 self._aircraftState.pitotHeatOn != aircraftState.pitotHeatOn: 134 print "Aircraft.handleState: %s: pitotHeatOn=%d" % \ 135 (timeStr, aircraftState.pitotHeatOn) 136 137 if self._aircraftState is None or \ 138 self._aircraftState.gearsDown != aircraftState.gearsDown: 139 print "Aircraft.handleState: %s: gearsDown=%f" % \ 140 (timeStr, aircraftState.gearsDown) 141 142 if self._aircraftState is None or \ 143 self._aircraftState.spoilersArmed != aircraftState.spoilersArmed: 144 print "Aircraft.handleState: %s: spoilersArmed=%f" % \ 145 (timeStr, aircraftState.spoilersArmed) 146 147 if self._aircraftState is None or \ 148 self._aircraftState.spoilersExtension != aircraftState.spoilersExtension: 149 print "Aircraft.handleState: %s: spoilersExtension=%f" % \ 150 (timeStr, aircraftState.spoilersExtension) 151 152 if self._aircraftState is None or \ 153 self._aircraftState.altimeter != aircraftState.altimeter: 154 print "Aircraft.handleState: %s: altimeter=%f" % \ 155 (timeStr, aircraftState.altimeter) 156 157 if self._aircraftState is None or \ 158 self._aircraftState.nav1 != aircraftState.nav1: 159 print "Aircraft.handleState: %s: nav1=%s" % \ 160 (timeStr, aircraftState.nav1) 161 162 if self._aircraftState is None or \ 163 self._aircraftState.nav2 != aircraftState.nav2: 164 print "Aircraft.handleState: %s: nav2=%s" % \ 165 (timeStr, aircraftState.nav2) 166 167 if self._aircraftState is None or \ 168 self._aircraftState.fuel != aircraftState.fuel: 169 print "Aircraft.handleState: %s: fuel=%s" % \ 170 (timeStr, aircraftState.fuel) 171 172 if self._aircraftState is None or \ 173 self._aircraftState.n1 != aircraftState.n1: 174 print "Aircraft.handleState: %s: n1=%s" % \ 175 (timeStr, aircraftState.n1) 176 177 if self._aircraftState is None or \ 178 self._aircraftState.reverser != aircraftState.reverser: 179 print "Aircraft.handleState: %s: reverser=%s" % \ 180 (timeStr, aircraftState.reverser) 66 for checker in self._checkers: 67 checker.check(self._flight, self, self._flight.logger, 68 self._aircraftState, aircraftState) 181 69 182 70 self._aircraftState = aircraftState 183 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 184 97 #--------------------------------------------------------------------------------------- 185 98 … … 198 111 class B736(Boeing737): 199 112 """Boeing 737-600 aircraft.""" 200 def __init__(self ):201 super(B736, self).__init__( const.AIRCRAFT_B736)113 def __init__(self, flight): 114 super(B736, self).__init__(flight) 202 115 203 116 #--------------------------------------------------------------------------------------- … … 205 118 class B737(Boeing737): 206 119 """Boeing 737-700 aircraft.""" 207 def __init__(self ):208 super(B737, self).__init__( const.AIRCRAFT_B737)120 def __init__(self, flight): 121 super(B737, self).__init__(flight) 209 122 210 123 #--------------------------------------------------------------------------------------- … … 212 125 class B738(Boeing737): 213 126 """Boeing 737-800 aircraft.""" 214 def __init__(self ):215 super(B738, self).__init__( const.AIRCRAFT_B738)127 def __init__(self, flight): 128 super(B738, self).__init__(flight) 216 129 217 130 #--------------------------------------------------------------------------------------- … … 219 132 class B733(Boeing737): 220 133 """Boeing 737-300 aircraft.""" 221 def __init__(self ):222 super(B733, self).__init__( const.AIRCRAFT_B733)134 def __init__(self, flight): 135 super(B733, self).__init__(flight) 223 136 224 137 #--------------------------------------------------------------------------------------- … … 226 139 class B734(Boeing737): 227 140 """Boeing 737-400 aircraft.""" 228 def __init__(self ):229 super(B734, self).__init__( const.AIRCRAFT_B734)141 def __init__(self, flight): 142 super(B734, self).__init__(flight) 230 143 231 144 #--------------------------------------------------------------------------------------- … … 233 146 class B735(Boeing737): 234 147 """Boeing 737-500 aircraft.""" 235 def __init__(self ):236 super(B735, self).__init__( const.AIRCRAFT_B735)148 def __init__(self, flight): 149 super(B735, self).__init__(flight) 237 150 238 151 #--------------------------------------------------------------------------------------- … … 246 159 - n1: left, right 247 160 - reverser: left, right.""" 248 def __init__(self ):249 super(DH8D, self).__init__( const.AIRCRAFT_DH8D)161 def __init__(self, flight): 162 super(DH8D, self).__init__(flight) 250 163 251 164 #--------------------------------------------------------------------------------------- … … 264 177 class B762(Boeing767): 265 178 """Boeing 767-200 aircraft.""" 266 def __init__(self ):267 super(B762, self).__init__( const.AIRCRAFT_B762)179 def __init__(self, flight): 180 super(B762, self).__init__(flight) 268 181 269 182 #--------------------------------------------------------------------------------------- … … 271 184 class B763(Boeing767): 272 185 """Boeing 767-300 aircraft.""" 273 def __init__(self ):274 super(B763, self).__init__(c onst.AIRCRAFT_B763)186 def __init__(self, flight): 187 super(B763, self).__init__(cflight) 275 188 276 189 #--------------------------------------------------------------------------------------- … … 284 197 - n1: left, right 285 198 - reverser: left, right.""" 286 def __init__(self ):287 super(CRJ2, self).__init__( const.AIRCRAFT_CRJ2)199 def __init__(self, flight): 200 super(CRJ2, self).__init__(flight) 288 201 289 202 #--------------------------------------------------------------------------------------- … … 297 210 - n1: left, right 298 211 - reverser: left, right.""" 299 def __init__(self ):300 super(F70, self).__init__( const.AIRCRAFT_F70)212 def __init__(self, flight): 213 super(F70, self).__init__(flight) 301 214 302 215 #--------------------------------------------------------------------------------------- … … 310 223 - rpm: left, right 311 224 - reverser: left, right.""" 312 def __init__(self): 313 super(DC3, self).__init__(const.AIRCRAFT_DC3) 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) 314 235 315 236 #--------------------------------------------------------------------------------------- … … 324 245 - n1: left, right 325 246 - reverser: left, right.""" 326 def __init__(self ):327 super(T134, self).__init__( const.AIRCRAFT_T134)247 def __init__(self, flight): 248 super(T134, self).__init__(flight) 328 249 329 250 #--------------------------------------------------------------------------------------- … … 337 258 - n1: left, centre, right 338 259 - reverser: left, right""" 339 def __init__(self ):340 super(T154, self).__init__( const.AIRCRAFT_T154)260 def __init__(self, flight): 261 super(T154, self).__init__(flight) 341 262 342 263 #--------------------------------------------------------------------------------------- … … 350 271 - n1: left, right 351 272 - reverser: left, right""" 352 def __init__(self): 353 super(YK40, self).__init__(const.AIRCRAFT_YK40) 354 355 #--------------------------------------------------------------------------------------- 356 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 #---------------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.