Changeset 274:b866c39279e8


Ignore:
Timestamp:
07/05/12 17:51:58 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Reworked fuel handling so that the model can tell what tanks there are

Location:
src/mlx
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r273 r274  
    174174        This is the function that the simulator calls directly with the new
    175175        state."""
    176         config = self._flight.config
    177 
    178         self._smoothedIAS.add(config.realIASSmoothingLength, aircraftState.ias)
    179         aircraftState.smoothedIAS = self._smoothedIAS.get()
    180 
    181         self._smoothedVS.add(config.realVSSmoothingLength, aircraftState.vs)
    182         aircraftState.smoothedVS = self._smoothedVS.get()
    183        
    184         for checker in self._checkers:
    185             try:
    186                 checker.check(self._flight, self, self._flight.logger,
    187                               self._aircraftState, aircraftState)
    188             except:
    189                 print >> sys.stderr, "Checker", checker, "failed"
    190                 traceback.print_exc()
    191 
    192         self._flight.handleState(self._aircraftState, aircraftState)
    193 
    194         self._maxVS = max(self._maxVS, aircraftState.vs)
    195         self._minVS = min(self._minVS, aircraftState.vs)
    196 
    197         self._aircraftState = aircraftState
     176        try:
     177            config = self._flight.config
     178
     179            self._smoothedIAS.add(config.realIASSmoothingLength, aircraftState.ias)
     180            aircraftState.smoothedIAS = self._smoothedIAS.get()
     181
     182            self._smoothedVS.add(config.realVSSmoothingLength, aircraftState.vs)
     183            aircraftState.smoothedVS = self._smoothedVS.get()
     184
     185            for checker in self._checkers:
     186                try:
     187                    checker.check(self._flight, self, self._flight.logger,
     188                                  self._aircraftState, aircraftState)
     189                except:
     190                    print >> sys.stderr, "Checker", checker, "failed"
     191                    traceback.print_exc()
     192
     193            self._flight.handleState(self._aircraftState, aircraftState)
     194
     195            self._maxVS = max(self._maxVS, aircraftState.vs)
     196            self._minVS = min(self._minVS, aircraftState.vs)
     197        except:
     198            print >> sys.stderr, "Failed to handle the state"
     199            traceback.print_exc()
     200        finally:
     201            self._aircraftState = aircraftState
    198202   
    199203    def setStage(self, aircraftState, newStage):
     
    203207            if newStage==const.STAGE_PUSHANDTAXI:
    204208                self.logger.message(aircraftState.timestamp, "Block time start")
    205                 self.logFuel(aircraftState)
     209                self._flight.logFuel(aircraftState)
    206210                self.logger.message(aircraftState.timestamp,
    207211                                    "Zero-fuel weight: %.0f kg" % (aircraftState.zfw))
     
    234238                                          force = True)
    235239                self.logger.message(aircraftState.timestamp, "Flight time end")
    236                 self.logFuel(aircraftState)
     240                self._flight.logFuel(aircraftState)
    237241                self.logger.message(aircraftState.timestamp,
    238242                                    "Landing weight: %.0f kg, MLW: %.0f" % \
     
    409413    - fuel: left, centre, right
    410414    - n1: left, right
    411     - reverser: left, right"""
    412     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
    413    
     415    - reverser: left, right"""   
    414416    def __init__(self, flight):
    415417        super(Boeing737, self).__init__(flight)
     
    426428                                 40 : 162 }
    427429
    428     def logFuel(self, aircraftState):
    429         """Log the amount of fuel"""
    430         self.logger.message(aircraftState.timestamp,
    431                             "Fuel: left=%.0f kg - centre=%.0f kg - right=%.0f kg" % \
    432                             (aircraftState.fuel[0], aircraftState.fuel[1],
    433                              aircraftState.fuel[2]))
    434         self.logger.message(aircraftState.timestamp,
    435                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    436                            
    437430#---------------------------------------------------------------------------------------
    438431
     
    519512    - n1: left, right
    520513    - reverser: left, right."""
    521     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]   
    522514
    523515    def __init__(self, flight):
     
    533525                                 35 : 158 }
    534526
    535     def logFuel(self, aircraftState):
    536         """Log the amount of fuel"""
    537         self.logger.message(aircraftState.timestamp,
    538                             "Fuel: left=%.0f kg - right=%.0f kg" % \
    539                             (aircraftState.fuel[0], aircraftState.fuel[1]))
    540         self.logger.message(aircraftState.timestamp,
    541                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    542 
    543527#---------------------------------------------------------------------------------------
    544528
     
    551535    - n1: left, right
    552536    - reverser: left, right"""
    553     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
    554537
    555538    def __init__(self, flight):
     
    564547                                 30 : 175 }
    565548
    566     def logFuel(self, aircraftState):
    567         """Log the amount of fuel"""
    568         self.logger.message(aircraftState.timestamp,
    569                             "Fuel: left=%.0f kg - centre=%.0f kg - right=%.0f kg" % \
    570                             (aircraftState.fuel[0], aircraftState.fuel[1],
    571                              aircraftState.fuel[2]))
    572         self.logger.message(aircraftState.timestamp,
    573                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    574                            
    575549#---------------------------------------------------------------------------------------
    576550
     
    605579    - n1: left, right
    606580    - reverser: left, right."""
    607     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
    608 
    609581    def __init__(self, flight):
    610582        super(CRJ2, self).__init__(flight)
     
    620592                                 45 : 175 }
    621593
    622     def logFuel(self, aircraftState):
    623         """Log the amount of fuel"""
    624         self.logger.message(aircraftState.timestamp,
    625                             "Fuel: left=%.0f kg - centre=%.0f kg - right=%.0f kg" % \
    626                             (aircraftState.fuel[0], aircraftState.fuel[1],
    627                              aircraftState.fuel[2]))
    628         self.logger.message(aircraftState.timestamp,
    629                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    630                            
    631594#---------------------------------------------------------------------------------------
    632595
     
    639602    - n1: left, right
    640603    - reverser: left, right."""
    641     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
    642 
    643604    def __init__(self, flight):
    644605        super(F70, self).__init__(flight)
     
    655616                                 42 : 180 }
    656617
    657     def logFuel(self, aircraftState):
    658         """Log the amount of fuel"""
    659         self.logger.message(aircraftState.timestamp,
    660                             "Fuel: left=%.0f kg - centre=%.0f kg - right=%.0f kg" % \
    661                             (aircraftState.fuel[0], aircraftState.fuel[1],
    662                              aircraftState.fuel[2]))
    663         self.logger.message(aircraftState.timestamp,
    664                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    665                            
    666618#---------------------------------------------------------------------------------------
    667619
     
    674626    - rpm: left, right
    675627    - reverser: left, right."""
    676     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
    677     # fuelTanks = [const.FUELTANK_LEFT_AUX, const.FUELTANK_LEFT,
    678     #              const.FUELTANK_RIGHT, const.FUELTANK_RIGHT_AUX]
    679 
    680628    def __init__(self, flight):
    681629        super(DC3, self).__init__(flight)
     
    697645        return True
    698646
    699     def logFuel(self, aircraftState):
    700         """Log the amount of fuel"""
    701         self.logger.message(aircraftState.timestamp,
    702                             "Fuel: left aux=%.0f kg - left=%.0f kg - right=%.0f kg - right aux=%.0f kg" % \
    703                             (aircraftState.fuel[0], aircraftState.fuel[1],
    704                              aircraftState.fuel[2], aircraftState.fuel[3]))
    705         self.logger.message(aircraftState.timestamp,
    706                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    707                            
    708647#---------------------------------------------------------------------------------------
    709648
     
    717656    - n1: left, right
    718657    - reverser: left, right."""
    719     fuelTanks = [const.FUELTANK_LEFT_TIP, const.FUELTANK_EXTERNAL1,
    720                  const.FUELTANK_LEFT_AUX,
    721                  const.FUELTANK_CENTRE,
    722                  const.FUELTANK_RIGHT_AUX,
    723                  const.FUELTANK_EXTERNAL2, const.FUELTANK_RIGHT_TIP]
    724 
    725658    def __init__(self, flight):
    726659        super(T134, self).__init__(flight)
     
    740673        return False
    741674   
    742     def logFuel(self, aircraftState):
    743         """Log the amount of fuel"""
    744         self.logger.message(aircraftState.timestamp,
    745                             "Fuel: left tip=%.0f kg - external 1=%.0f kg - left aux=%.0f kg - centre= %.0f kg - right aux=%.0f kg - external 2=%.0f kg - right tip=%.0f kg" % \
    746                             (aircraftState.fuel[0], aircraftState.fuel[1],
    747                              aircraftState.fuel[2],
    748                              aircraftState.fuel[3], aircraftState.fuel[4],
    749                              aircraftState.fuel[5], aircraftState.fuel[6]))
    750         self.logger.message(aircraftState.timestamp,
    751                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    752                            
    753675    def _appendLightsLoggers(self):
    754676        """Append the loggers needed for the lights."""
     
    773695    - n1: left, centre, right
    774696    - reverser: left, right"""
    775     fuelTanks = [const.FUELTANK_LEFT_AUX, const.FUELTANK_LEFT,
    776                  const.FUELTANK_CENTRE, const.FUELTANK_CENTRE2,
    777                  const.FUELTANK_RIGHT, const.FUELTANK_RIGHT_AUX]
    778697    def __init__(self, flight):
    779698        super(T154, self).__init__(flight)
     
    793712        return False
    794713   
    795     def logFuel(self, aircraftState):
    796         """Log the amount of fuel"""
    797         self.logger.message(aircraftState.timestamp,
    798                             "Fuel: left aux=%.0f kg - left=%.0f kg - centre=%.0f kg - centre 2=%.0f kg - right=%.0f kg - right aux=%.0f kg" % \
    799                             (aircraftState.fuel[0], aircraftState.fuel[1],
    800                              aircraftState.fuel[2], aircraftState.fuel[3],
    801                              aircraftState.fuel[4], aircraftState.fuel[5]))
    802         self.logger.message(aircraftState.timestamp,
    803                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    804 
    805714    def _appendLightsLoggers(self):
    806715        """Append the loggers needed for the lights."""
     
    826735    - n1: left, right
    827736    - reverser: left, right"""
    828     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]
    829    
    830737    def __init__(self, flight):
    831738        super(YK40, self).__init__(flight)
     
    844751        return False
    845752   
    846     def logFuel(self, aircraftState):
    847         """Log the amount of fuel"""
    848         self.logger.message(aircraftState.timestamp,
    849                             "Fuel: left=%.0f kg - right=%.0f kg" % \
    850                             (aircraftState.fuel[0], aircraftState.fuel[1]))
    851         self.logger.message(aircraftState.timestamp,
    852                             "Total fuel: %.0f kg" % (sum(aircraftState.fuel),))
    853 
    854753    def _appendLightsLoggers(self):
    855754        """Append the loggers needed for the lights."""
     
    866765#---------------------------------------------------------------------------------------
    867766
    868 MostFuelTankAircraft = T134
     767mostFuelTanks = [const.FUELTANK_LEFT_TIP, const.FUELTANK_EXTERNAL1,
     768                 const.FUELTANK_LEFT_AUX,
     769                 const.FUELTANK_CENTRE,
     770                 const.FUELTANK_RIGHT_AUX,
     771                 const.FUELTANK_EXTERNAL2, const.FUELTANK_RIGHT_TIP]
    869772
    870773#---------------------------------------------------------------------------------------
  • src/mlx/const.py

    r252 r274  
    468468#-------------------------------------------------------------------------------
    469469
     470_fuelTankLogStrings = { FUELTANK_CENTRE : "centre",
     471                        FUELTANK_LEFT : "left",
     472                        FUELTANK_RIGHT : "right",
     473                        FUELTANK_LEFT_AUX : "left aux",
     474                        FUELTANK_RIGHT_AUX : "right aux",
     475                        FUELTANK_LEFT_TIP : "left tip",
     476                        FUELTANK_RIGHT_TIP : "right tip",
     477                        FUELTANK_EXTERNAL1 : "external 1",
     478                        FUELTANK_EXTERNAL2 : "external 2",
     479                        FUELTANK_CENTRE2 : "centre 2" }
     480
     481def fuelTank2logString(fuelTank):
     482    """Get the log string equivalent of the given fuelTank."""
     483    return _fuelTankLogStrings[fuelTank] \
     484        if fuelTank in _fuelTankLogStrings else "unknown"
     485
     486#-------------------------------------------------------------------------------
     487
    470488# The available gates at LHBP
    471489lhbpGateNumbers = []
  • src/mlx/flight.py

    r262 r274  
    208208        self._updateFlownDistance(currentState)
    209209       
    210         self.endFuel = sum(currentState.fuel)
     210        self.endFuel = currentState.totalFuel
    211211        if self.startFuel is None:
    212212            self.startFuel = self.endFuel
     
    312312        return "_knots" if self.speedInKnots else "_kmph"
    313313
     314    def logFuel(self, aircraftState):
     315        """Log the amount of fuel"""
     316        fuelStr = ""
     317        for (tank, amount) in aircraftState.fuel:
     318            if fuelStr: fuelStr += " - "
     319            fuelStr += "%s=%.0f kg" % (const.fuelTank2logString(tank), amount)
     320           
     321        self.logger.message(aircraftState.timestamp, "Fuel: " + fuelStr)
     322        self.logger.message(aircraftState.timestamp,
     323                            "Total fuel: %.0f kg" % (aircraftState.totalFuel,))                           
     324
    314325    def _updateFlownDistance(self, currentState):
    315326        """Update the flown distance."""
  • src/mlx/fs.py

    r263 r274  
    184184    - flapsSet: the selected degrees of the flaps (float)
    185185    - flaps: the actual degrees of the flaps (float)
    186     - fuelWeight[]: the fuel weights in the different tanks in kgs (array of
    187     floats of as many items as the number fuel tanks)
     186    - fuel[]: the fuel information. It is a list of tuples with items:
     187    the fuel tank identifier and the amount of fuel in that tank in
     188    kgs
     189    - totalFuel: the total amount of fuel in kg
    188190    - n1[]: the N1 values of the turbine engines (array of floats
    189191    of as many items as the number of engines, present only for aircraft with
  • src/mlx/fsuipc.py

    r263 r274  
    658658                                   extra = _disconnect)
    659659
    660     def getFuel(self, tanks, callback):
    661         """Get the fuel from the given tanks.
    662 
    663         The callback will be called with a list of two-tuples, where the tuples
    664         have the following items:
     660    def getFuel(self, callback):
     661        """Get the fuel information for the current model.
     662
     663        The callback will be called with a list of triplets with the following
     664        items:
     665        - the fuel tank identifier
    665666        - the current weight of the fuel in the tank (in kgs)
    666667        - the current total capacity of the tank (in kgs)."""
    667         data = [(0x0af4, "H")]     # Fuel weight
    668         for tank in tanks:
    669             offset = _tank2offset[tank]
    670             data.append( (offset, "u") )     # tank level
    671             data.append( (offset+4, "u") )   # tank capacity
    672 
    673         self._handler.requestRead(data, self._handleFuelRetrieved,
    674                                   extra = callback)
     668        if self._aircraftModel is None:
     669            callback([])
     670        else:
     671            self._aircraftModel.getFuel(self._handler, callback)
    675672
    676673    def setFuelLevel(self, levels):
     
    682679        - the requested level of the fuel as a floating-point value between 0.0
    683680        and 1.0."""
    684         data = []
    685         for (tank, level) in levels:
    686             offset = _tank2offset[tank]
    687             value = long(level * 128.0 * 65536.0)
    688             data.append( (offset, "u", value) )
    689         self._handler.requestWrite(data, self._handleFuelWritten)
     681        if self._aircraftModel is not None:
     682            self._aircraftModel.setFuelLevel(self._handler, levels)
    690683
    691684    def enableTimeSync(self):
     
    999992        if disconnect:
    1000993            self._handler.disconnect()
    1001 
    1002     def _handleFuelRetrieved(self, data, callback):
    1003         """Callback for a fuel retrieval request."""
    1004         fuelWeight = data[0] / 256.0
    1005         result = []
    1006         for i in range(1, len(data), 2):
    1007             capacity = data[i+1] * fuelWeight * const.LBSTOKG
    1008             amount = data[i] * capacity / 128.0 / 65536.0
    1009             result.append( (amount, capacity) )
    1010 
    1011         callback(result)
    1012                                                  
    1013     def _handleFuelWritten(self, success, extra):
    1014         """Callback for a fuel setting request."""
    1015         pass
    1016994
    1017995    def _handleNumHotkeys(self, data, (id, generation)):
     
    13801358        super(GenericAircraftModel, self).addMonitoringData(data, fsType)
    13811359       
    1382         self._addOffsetWithIndexMember(data, 0x0af4, "H", "_monidx_fuelWeight")
    1383 
    1384         self._fuelStartIndex = len(data)
    1385         for tank in self._fuelTanks:
    1386             offset = _tank2offset[tank]
    1387             self._addOffsetWithIndexMember(data, offset, "u")    # tank level
    1388             self._addOffsetWithIndexMember(data, offset+4, "u")  # tank capacity
     1360        self._fuelStartIndex = self._addFuelOffsets(data, "_monidx_fuelWeight")
    13891361
    13901362        self._engineStartIndex = len(data)
     
    14061378                                                                   data)
    14071379
    1408         fuelWeight = data[self._monidx_fuelWeight]/256.0
    1409         state.fuel = []
    1410         for i in range(self._fuelStartIndex,
    1411                        self._fuelStartIndex + 2*len(self._fuelTanks), 2):
    1412             fuel = data[i+1]*data[i]*fuelWeight*const.LBSTOKG/128.0/65536.0
    1413             state.fuel.append(fuel)
    1414 
     1380        (state.fuel, state.totalFuel) = \
     1381            self._convertFuelData(data, index = self._monidx_fuelWeight)
    14151382
    14161383        state.n1 = [] if self._isN1 else None
     
    14311398        return state
    14321399
     1400    def getFuel(self, handler, callback):
     1401        """Get the fuel information for this model.
     1402
     1403        See Simulator.getFuel for more information. This
     1404        implementation simply queries the fuel tanks given to the
     1405        constructor."""
     1406        data = []
     1407        self._addFuelOffsets(data)
     1408
     1409        handler.requestRead(data, self._handleFuelRetrieved,
     1410                            extra = callback)
     1411
     1412    def setFuelLevel(self, handler, levels):
     1413        """Set the fuel level.
     1414
     1415        See the description of Simulator.setFuelLevel. This
     1416        implementation simply sets the fuel tanks as given."""
     1417        data = []
     1418        for (tank, level) in levels:
     1419            offset = _tank2offset[tank]
     1420            value = long(level * 128.0 * 65536.0)
     1421            data.append( (offset, "u", value) )
     1422
     1423        handler.requestWrite(data, self._handleFuelWritten)
     1424
     1425    def _addFuelOffsets(self, data, weightIndexName = None):
     1426        """Add the fuel offsets to the given data array.
     1427
     1428        If weightIndexName is not None, it will be the name of the
     1429        fuel weight index.
     1430
     1431        Returns the index of the first fuel tank's data."""
     1432        self._addOffsetWithIndexMember(data, 0x0af4, "H", weightIndexName)
     1433
     1434        fuelStartIndex = len(data)
     1435        for tank in self._fuelTanks:
     1436            offset = _tank2offset[tank]
     1437            self._addOffsetWithIndexMember(data, offset, "u")    # tank level
     1438            self._addOffsetWithIndexMember(data, offset+4, "u")  # tank capacity
     1439       
     1440        return fuelStartIndex
     1441
     1442    def _convertFuelData(self, data, index = 0, addCapacities = False):
     1443        """Convert the given data into a fuel info list.
     1444
     1445        The list consists of two or three-tuples of the following
     1446        items:
     1447        - the fuel tank ID,
     1448        - the amount of the fuel in kg,
     1449        - if addCapacities is True, the total capacity of the tank."""
     1450        fuelWeight = data[index] / 256.0
     1451        index += 1
     1452
     1453        result = []
     1454        totalFuel = 0
     1455        for fuelTank in self._fuelTanks:
     1456            capacity = data[index+1] * fuelWeight * const.LBSTOKG
     1457            amount = data[index] * capacity / 128.0 / 65536.0
     1458            index += 2
     1459           
     1460            result.append( (fuelTank, amount, capacity) if addCapacities
     1461                           else (fuelTank, amount))
     1462            totalFuel += amount
     1463
     1464        return (result, totalFuel)       
     1465
     1466    def _handleFuelRetrieved(self, data, callback):
     1467        """Callback for a fuel retrieval request."""
     1468        (fuelData, _totalFuel) = self._convertFuelData(data,
     1469                                                       addCapacities = True)
     1470        callback(fuelData)
     1471                                                         
     1472    def _handleFuelWritten(self, success, extra):
     1473        """Callback for a fuel setting request."""
     1474        pass
     1475
    14331476#------------------------------------------------------------------------------
    14341477
     
    14511494class B737Model(GenericAircraftModel):
    14521495    """Generic model for the Boeing 737 Classing and NG aircraft."""
     1496    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
     1497   
    14531498    def __init__(self):
    14541499        """Construct the model."""
    14551500        super(B737Model, self). \
    14561501            __init__(flapsNotches = [0, 1, 2, 5, 10, 15, 25, 30, 40],
    1457                      fuelTanks = acft.Boeing737.fuelTanks,
     1502                     fuelTanks = B737Model.fuelTanks,
    14581503                     numEngines = 2)
    14591504
     
    15191564class B767Model(GenericAircraftModel):
    15201565    """Generic model for the Boeing 767 aircraft."""
     1566    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
     1567
    15211568    def __init__(self):
    15221569        """Construct the model."""
    15231570        super(B767Model, self). \
    15241571            __init__(flapsNotches = [0, 1, 5, 15, 20, 25, 30],
    1525                      fuelTanks = acft.Boeing767.fuelTanks,
     1572                     fuelTanks = Boeing767Model.fuelTanks,
    15261573                     numEngines = 2)
    15271574
     
    15351582class DH8DModel(GenericAircraftModel):
    15361583    """Generic model for the Bombardier  Dash 8-Q400 aircraft."""
     1584    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]   
     1585   
    15371586    def __init__(self):
    15381587        """Construct the model."""
    15391588        super(DH8DModel, self). \
    15401589            __init__(flapsNotches = [0, 5, 10, 15, 35],
    1541                      fuelTanks = acft.DH8D.fuelTanks,
     1590                     fuelTanks = DH8DModel.fuelTanks,
    15421591                     numEngines = 2)
    15431592
     
    15801629class CRJ2Model(GenericAircraftModel):
    15811630    """Generic model for the Bombardier CRJ-200 aircraft."""
     1631    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
     1632
    15821633    def __init__(self):
    15831634        """Construct the model."""
    15841635        super(CRJ2Model, self). \
    15851636            __init__(flapsNotches = [0, 8, 20, 30, 45],
    1586                      fuelTanks = acft.CRJ2.fuelTanks,
     1637                     fuelTanks = CRJ2Model.fuelTanks,
    15871638                     numEngines = 2)
    15881639
     
    15961647class F70Model(GenericAircraftModel):
    15971648    """Generic model for the Fokker F70 aircraft."""
     1649    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
     1650
    15981651    def __init__(self):
    15991652        """Construct the model."""
    16001653        super(F70Model, self). \
    16011654            __init__(flapsNotches = [0, 8, 15, 25, 42],
    1602                      fuelTanks = acft.F70.fuelTanks,
     1655                     fuelTanks = F70Model.fuelTanks,
    16031656                     numEngines = 2)
    16041657
     
    16121665class DC3Model(GenericAircraftModel):
    16131666    """Generic model for the Lisunov Li-2 (DC-3) aircraft."""
     1667    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]   
     1668    # fuelTanks = [const.FUELTANK_LEFT_AUX, const.FUELTANK_LEFT,
     1669    #              const.FUELTANK_RIGHT, const.FUELTANK_RIGHT_AUX]
     1670
    16141671    def __init__(self):
    16151672        """Construct the model."""
    16161673        super(DC3Model, self). \
    16171674            __init__(flapsNotches = [0, 15, 30, 45],
    1618                      fuelTanks = acft.DC3.fuelTanks,
     1675                     fuelTanks = DC3Model.fuelTanks,
    16191676                     numEngines = 2, isN1 = False)
    16201677
     
    16241681        return "FSUIPC/Generic Lisunov Li-2 (DC-3)"
    16251682
     1683    def _convertFuelData(self, data, index = 0, addCapacities = False):
     1684        """Convert the given data into a fuel info list.
     1685
     1686        It assumes to receive the 3 fuel tanks as seen above (left,
     1687        centre and right) and converts it to left aux, left, right,
     1688        and right aux. The amount in the left tank goes into left aux,
     1689        the amount of the right tank goes into right aux and the
     1690        amount of the centre tank goes into the left and right tanks
     1691        evenly distributed."""
     1692        (rawFuelData, totalFuel) = \
     1693            super(DC3Model, self)._convertFuelData(data, index, addCapacities)
     1694
     1695        centreAmount = rawFuelData[1][1]
     1696        if addCapacities:
     1697            centreCapacity = rawFuelData[1][2]
     1698            fuelData = [(const.FUELTANK_LEFT_AUX,
     1699                         rawFuelData[0][1], rawFuelData[0][2]),
     1700                        (const.FUELTANK_LEFT,
     1701                         centreAmount/2.0, centreCapacity/2.0),
     1702                        (const.FUELTANK_RIGHT,
     1703                         centreAmount/2.0, centreCapacity/2.0),
     1704                        (const.FUELTANK_RIGHT_AUX,
     1705                         rawFuelData[2][1], rawFuelData[2][2])]
     1706        else:
     1707            fuelData = [(const.FUELTANK_LEFT_AUX, rawFuelData[0][1]),
     1708                        (const.FUELTANK_LEFT, centreAmount/2.0),
     1709                        (const.FUELTANK_RIGHT, centreAmount/2.0),
     1710                        (const.FUELTANK_RIGHT_AUX, rawFuelData[2][1])]
     1711
     1712        return (fuelData, totalFuel)
     1713
     1714    def setFuelLevel(self, handler, levels):
     1715        """Set the fuel level.
     1716
     1717        See the description of Simulator.setFuelLevel. This
     1718        implementation assumes to get the four-tank representation,
     1719        as returned by getFuel()."""
     1720        leftLevel = 0.0
     1721        centreLevel = 0.0
     1722        rightLevel = 0.0
     1723       
     1724        for (tank, level) in levels:
     1725            if tank==const.FUELTANK_LEFT_AUX: leftLevel += level
     1726            elif tank==const.FUELTANK_LEFT or  tank==const.FUELTANK_RIGHT:
     1727                centreLevel += level
     1728            elif tank==const.FUELTANK_RIGHT_AUX: rightLevel += level
     1729
     1730        super(DC3Model, self).setFuelLevel([(const.FUELTANK_LEFT, leftLevel),
     1731                                            (const.FUELTANK_CENTRE,
     1732                                            centreLevel),
     1733                                            (const.FUELTANK_RIGHT, rightLevel)])
     1734
    16261735#------------------------------------------------------------------------------
    16271736
    16281737class T134Model(GenericAircraftModel):
    16291738    """Generic model for the Tupolev Tu-134 aircraft."""
     1739    fuelTanks = [const.FUELTANK_LEFT_TIP, const.FUELTANK_EXTERNAL1,
     1740                 const.FUELTANK_LEFT_AUX,
     1741                 const.FUELTANK_CENTRE,
     1742                 const.FUELTANK_RIGHT_AUX,
     1743                 const.FUELTANK_EXTERNAL2, const.FUELTANK_RIGHT_TIP]
     1744
    16301745    def __init__(self):
    16311746        """Construct the model."""
    16321747        super(T134Model, self). \
    16331748            __init__(flapsNotches = [0, 10, 20, 30],
    1634                      fuelTanks = acft.T134.fuelTanks,
     1749                     fuelTanks = T134Model.fuelTanks,
    16351750                     numEngines = 2)
    16361751
     
    16441759class T154Model(GenericAircraftModel):
    16451760    """Generic model for the Tupolev Tu-134 aircraft."""
     1761    fuelTanks = [const.FUELTANK_LEFT_AUX, const.FUELTANK_LEFT,
     1762                 const.FUELTANK_CENTRE, const.FUELTANK_CENTRE2,
     1763                 const.FUELTANK_RIGHT, const.FUELTANK_RIGHT_AUX]
     1764
    16461765    def __init__(self):
    16471766        """Construct the model."""
    16481767        super(T154Model, self). \
    16491768            __init__(flapsNotches = [0, 15, 28, 45],
    1650                      fuelTanks = acft.T154.fuelTanks,
     1769                     fuelTanks = T154Model.fuelTanks,
    16511770                     numEngines = 3)
    16521771
     
    16681787class YK40Model(GenericAircraftModel):
    16691788    """Generic model for the Yakovlev Yak-40 aircraft."""
     1789    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]
     1790   
    16701791    def __init__(self):
    16711792        """Construct the model."""
    16721793        super(YK40Model, self). \
    16731794            __init__(flapsNotches = [0, 20, 35],
    1674                      fuelTanks = acft.YK40.fuelTanks,
     1795                     fuelTanks = YK40Model.fuelTanks,
    16751796                     numEngines = 2)
    16761797
  • src/mlx/gui/flight.py

    r262 r274  
    11631163            gui.beginBusy(xstr("fuel_get_busy"))
    11641164           
    1165             gui.simulator.getFuel(gui.flight.aircraft.fuelTanks,
    1166                                   self._handleFuel)
     1165            gui.simulator.getFuel(self._handleFuel)
    11671166        else:
    11681167            self._wizard.nextPage()
     
    13741373        self.setMainWidget(self._fuelAlignment)
    13751374
    1376         tanks = acft.MostFuelTankAircraft.fuelTanks
    1377         tankData = ((2500, 3900),) * len(tanks)
    1378         self._setupTanks(tanks, tankData)
     1375        tankData = [(tank, 2500, 3900) for tank in acft.mostFuelTanks]
     1376        self._setupTanks(tankData)
    13791377
    13801378        self.addCancelFlightButton()
     
    13871385    def activate(self):
    13881386        """Activate the page."""
    1389         gui = self._wizard.gui
    1390 
    1391         self._setupTanks(gui.flight.aircraft.fuelTanks,
    1392                          self._wizard._fuelData)
     1387        self._setupTanks(self._wizard._fuelData)
    13931388
    13941389    def finalize(self):
     
    14101405            self._wizard.nextPage()       
    14111406
    1412     def _setupTanks(self, tanks, tankData):
     1407    def _setupTanks(self, tankData):
    14131408        """Setup the tanks for the given data."""
    1414         numTanks = len(tanks)
     1409        numTanks = len(tankData)
    14151410        if self._fuelTable is not None:
    14161411            self._fuelAlignment.remove(self._fuelTable)
     
    14191414        self._fuelTable = gtk.Table(numTanks, 1)
    14201415        self._fuelTable.set_col_spacings(16)
    1421         for i in range(0, numTanks):
    1422             tank = tanks[i]
    1423             (current, capacity) = tankData[i]
    1424 
     1416        index = 0
     1417        for (tank, current, capacity) in tankData:
    14251418            fuelTank = FuelTank(tank,
    14261419                                xstr("fuel_tank_" +
    14271420                                     const.fuelTank2string(tank)),
    14281421                                capacity, current)
    1429             self._fuelTable.attach(fuelTank, i, i+1, 0, 1)
     1422            self._fuelTable.attach(fuelTank, index, index+1, 0, 1)
    14301423            self._fuelTanks.append(fuelTank)
     1424            index += 1
    14311425           
    14321426        self._fuelAlignment.add(self._fuelTable)
  • src/mlx/gui/monitor.py

    r263 r274  
    281281
    282282            fuelStr = ""
    283             for fuel in aircraftState.fuel:
     283            for (_tank, fuel) in aircraftState.fuel:
    284284                if fuelStr: fuelStr += ", "
    285285                fuelStr += "%.0f" % (fuel,)               
Note: See TracChangeset for help on using the changeset viewer.