Ignore:
Timestamp:
04/04/15 09:26:49 (9 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The overspeed and stall conditions are logged with the winds (re #259)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/checks.py

    r611 r622  
    12921292#---------------------------------------------------------------------------------------
    12931293
    1294 class OverspeedChecker(PatientFaultChecker):
     1294class WindSensitiveFaultChecker(FaultChecker):
     1295    """A fault checker which checks for a fault condition that might arise due
     1296    to suddenly changing winds.
     1297
     1298    If the condition is detected, its fact is logged, and the winds are also
     1299    logged repeatedly until and for a while after the condition has ceased. A
     1300    fault is logged only if the condition holds for a certain period of
     1301    time."""
     1302    # The time the winds were logged last. This is global to avoid duplicate
     1303    # logging if several wind-sensitive fault conditions gold
     1304    _windsLastLogged = None
     1305
     1306    # The wind logging interval
     1307    _windsLogInterval = 5.0
     1308
     1309    def __init__(self, faultTimeout = 30.0, afterLoggingTime = 20.0):
     1310        """Construct the fault checker."""
     1311        self._faultTimeout = faultTimeout
     1312        self._afterLoggingTime = afterLoggingTime
     1313
     1314        self._faultStarted = None
     1315        self._faultCeased = None
     1316
     1317    def check(self, flight, aircraft, logger, oldState, state):
     1318        """Check for the condition and do whatever is needed."""
     1319        timestamp = state.timestamp
     1320        logWinds = False
     1321
     1322        if self.isCondition(flight, aircraft, oldState, state):
     1323            logWinds = True
     1324            if self._faultStarted is None:
     1325                self._faultStarted = timestamp
     1326                self._faultCeased = None
     1327                self.logCondition(flight, aircraft, logger, oldState, state,
     1328                                  False)
     1329
     1330                WindSensitiveFaultChecker._windsLastLogged = None
     1331
     1332            elif timestamp >= (self._faultStarted + self._faultTimeout):
     1333                self.logCondition(flight, aircraft, logger, oldState, state,
     1334                                  True)
     1335                self._faultStarted = timestamp
     1336
     1337        else:
     1338            if self._faultStarted is not None and self._faultCeased is None:
     1339                self._faultCeased = timestamp
     1340                self._faultStarted = None
     1341
     1342            if self._faultCeased is not None:
     1343                if timestamp < (self._faultCeased + self._afterLoggingTime):
     1344                    logWinds = True
     1345                else:
     1346                    self._faultCeased = None
     1347
     1348        if logWinds and \
     1349           (WindSensitiveFaultChecker._windsLastLogged is None or
     1350            timestamp >= (WindSensitiveFaultChecker._windsLastLogged +
     1351                          self._windsLogInterval)):
     1352            logger.message(timestamp, "Winds: %.f knots from %.f" %
     1353                           (state.windSpeed, state.windDirection))
     1354            WindSensitiveFaultChecker._windsLastLogged = timestamp
     1355
     1356#---------------------------------------------------------------------------------------
     1357
     1358class OverspeedChecker(WindSensitiveFaultChecker):
    12951359    """Check if Vne has been exceeded."""
    1296     def __init__(self, timeout = 30.0):
    1297         """Construct the checker."""
    1298         super(OverspeedChecker, self).__init__(timeout = timeout)
    1299 
    13001360    def isCondition(self, flight, aircraft, oldState, state):
    13011361        """Check if the fault condition holds."""
    13021362        return state.overspeed
    13031363
    1304     def logFault(self, flight, aircraft, logger, oldState, state):
    1305         """Log the fault."""
    1306         flight.handleFault(OverspeedChecker, state.timestamp,
    1307                            FaultChecker._appendDuring(flight, "Overspeed"),
    1308                            20)
     1364    def logCondition(self, flight, aircraft, logger, oldState, state, isFault):
     1365        """Log the condition fault."""
     1366        if isFault:
     1367            flight.handleFault(OverspeedChecker, state.timestamp,
     1368                               FaultChecker._appendDuring(flight, "Overspeed"),
     1369                               20)
     1370        else:
     1371            logger.message(state.timestamp,
     1372                           FaultChecker._appendDuring(flight, "Overspeed"))
     1373
     1374#---------------------------------------------------------------------------------------
     1375
     1376class StallChecker(WindSensitiveFaultChecker):
     1377    """Check if stall occured."""
     1378    def isCondition(self, flight, aircraft, oldState, state):
     1379        """Check if the fault condition holds."""
     1380        return flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
     1381                                const.STAGE_CRUISE, const.STAGE_DESCENT,
     1382                                const.STAGE_LANDING] and state.stalled
     1383
     1384    def logCondition(self, flight, aircraft, logger, oldState, state, isFault):
     1385        """Log the condition."""
     1386        if isFault:
     1387            score = 40 if flight.stage in [const.STAGE_TAKEOFF,
     1388                                           const.STAGE_LANDING] else 30
     1389            flight.handleFault(StallChecker, state.timestamp,
     1390                               FaultChecker._appendDuring(flight, "Stalled"),
     1391                               score)
     1392        else:
     1393            logger.message(state.timestamp,
     1394                            FaultChecker._appendDuring(flight, "Stalled"))
    13091395
    13101396#---------------------------------------------------------------------------------------
     
    14781564#---------------------------------------------------------------------------------------
    14791565
    1480 class StallChecker(PatientFaultChecker):
    1481     """Check if stall occured."""
    1482     def isCondition(self, flight, aircraft, oldState, state):
    1483         """Check if the fault condition holds."""
    1484         return flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
    1485                                 const.STAGE_CRUISE, const.STAGE_DESCENT,
    1486                                 const.STAGE_LANDING] and state.stalled
    1487 
    1488     def logFault(self, flight, aircraft, logger, oldState, state):
    1489         """Log the fault."""
    1490         score = 40 if flight.stage in [const.STAGE_TAKEOFF,
    1491                                        const.STAGE_LANDING] else 30
    1492         flight.handleFault(StallChecker, state.timestamp,
    1493                            FaultChecker._appendDuring(flight, "Stalled"),
    1494                            score)
    1495 
    1496 #---------------------------------------------------------------------------------------
    1497 
    14981566class StrobeLightsChecker(PatientFaultChecker):
    14991567    """Check if the strobe lights are used properly."""
Note: See TracChangeset for help on using the changeset viewer.