Changeset 197:93f89e9049be for src/mlx/acft.py
- Timestamp:
- 05/27/12 11:15:19 (12 years ago)
- Branch:
- default
- hg-Phase:
- (<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/acft.py
r191 r197 12 12 import traceback 13 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 14 39 #--------------------------------------------------------------------------------------- 15 40 … … 36 61 self._checkers = [] 37 62 63 config = flight.config 38 64 # Loggers 39 65 … … 58 84 self._checkers.append(checks.SpoilerLogger()) 59 85 60 if flight.config.isMessageTypeFS(const.MESSAGETYPE_VISIBILITY):86 if config.isMessageTypeFS(const.MESSAGETYPE_VISIBILITY): 61 87 self._checkers.append(checks.VisibilityChecker()) 62 88 … … 66 92 # queried from it, so the model should have a reference to the GUI as 67 93 # 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: 69 95 self._checkers.append(checks.ACARSSender(flight._gui)) 70 96 … … 93 119 self._checkers.append(checks.SpeedChecker()) 94 120 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 96 125 self._checkers.append(checks.StallChecker()) 97 126 … … 99 128 100 129 self._checkers.append(checks.ReverserChecker()) 130 131 self._smoothedIAS = SmoothedValue() 132 self._smoothedVS = SmoothedValue() 101 133 102 134 @property … … 132 164 133 165 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 135 179 for checker in self._checkers: 136 180 try: … … 753 797 754 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 #---------------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.