Ignore:
Timestamp:
05/27/12 11:15:19 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Added support for smoothed IAS and VS values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r191 r197  
    1212import traceback
    1313
     14from collections import deque
     15
     16#---------------------------------------------------------------------------------------
     17
     18class 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       
    1439#---------------------------------------------------------------------------------------
    1540
     
    3661        self._checkers = []
    3762
     63        config = flight.config
    3864        # Loggers
    3965
     
    5884        self._checkers.append(checks.SpoilerLogger())
    5985
    60         if flight.config.isMessageTypeFS(const.MESSAGETYPE_VISIBILITY):
     86        if config.isMessageTypeFS(const.MESSAGETYPE_VISIBILITY):
    6187            self._checkers.append(checks.VisibilityChecker())
    6288
     
    6692        # queried from it, so the model should have a reference to the GUI as
    6793        # well and access such data via the GUI!
    68         if flight.config.onlineACARS and not flight.entranceExam:
     94        if config.onlineACARS and not flight.entranceExam:
    6995            self._checkers.append(checks.ACARSSender(flight._gui))
    7096
     
    93119        self._checkers.append(checks.SpeedChecker())
    94120        self._checkers.append(checks.VSChecker())
    95         self._checkers.append(checks.OverspeedChecker())
     121
     122        timeout = 5.0 + config.realIASSmoothingLength - 1
     123        self._checkers.append(checks.OverspeedChecker(timeout = timeout))
     124                             
    96125        self._checkers.append(checks.StallChecker())
    97126
     
    99128       
    100129        self._checkers.append(checks.ReverserChecker())
     130
     131        self._smoothedIAS = SmoothedValue()
     132        self._smoothedVS = SmoothedValue()
    101133
    102134    @property
     
    132164
    133165    def handleState(self, aircraftState):
    134         """Called when the state of the aircraft changes."""
     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        print "handleState, realVSSmoothingLength:", config.realVSSmoothingLength
     176        self._smoothedVS.add(config.realVSSmoothingLength, aircraftState.vs)
     177        aircraftState.smoothedVS = self._smoothedVS.get()
     178       
    135179        for checker in self._checkers:
    136180            try:
     
    753797
    754798#---------------------------------------------------------------------------------------
     799
     800if __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#---------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.