diff --git a/src/modules/commander/failure_detector/FailureDetector.cpp b/src/modules/commander/failure_detector/FailureDetector.cpp index 46c9353450..b4a2469932 100644 --- a/src/modules/commander/failure_detector/FailureDetector.cpp +++ b/src/modules/commander/failure_detector/FailureDetector.cpp @@ -77,14 +77,20 @@ FailureDetector::update_attitude_status() const bool roll_status = (max_roll > 0.0f) && (fabsf(roll) > max_roll); const bool pitch_status = (max_pitch > 0.0f) && (fabsf(pitch) > max_pitch); + // Update hysteresis + _roll_failure_hysteresis.set_hysteresis_time_from(false, (hrt_abstime)(1e6f * _param_fd_fail_r_ttri.get())); + _pitch_failure_hysteresis.set_hysteresis_time_from(false, (hrt_abstime)(1e6f * _param_fd_fail_p_ttri.get())); + _roll_failure_hysteresis.set_state_and_update(roll_status); + _pitch_failure_hysteresis.set_state_and_update(pitch_status); + // Update bitmask _status &= ~(FAILURE_ROLL | FAILURE_PITCH); - if (roll_status) { + if (_roll_failure_hysteresis.get_state()) { _status |= FAILURE_ROLL; } - if (pitch_status) { + if (_pitch_failure_hysteresis.get_state()) { _status |= FAILURE_PITCH; } diff --git a/src/modules/commander/failure_detector/FailureDetector.hpp b/src/modules/commander/failure_detector/FailureDetector.hpp index fb5a9eb682..85f91891fd 100644 --- a/src/modules/commander/failure_detector/FailureDetector.hpp +++ b/src/modules/commander/failure_detector/FailureDetector.hpp @@ -46,6 +46,7 @@ #include #include #include +#include // subscriptions #include @@ -75,7 +76,9 @@ private: DEFINE_PARAMETERS( (ParamInt) _param_fd_fail_p, - (ParamInt) _param_fd_fail_r + (ParamInt) _param_fd_fail_r, + (ParamFloat) _param_fd_fail_r_ttri, + (ParamFloat) _param_fd_fail_p_ttri ) // Subscriptions @@ -84,5 +87,8 @@ private: uint8_t _status{FAILURE_NONE}; + systemlib::Hysteresis _roll_failure_hysteresis{false}; + systemlib::Hysteresis _pitch_failure_hysteresis{false}; + bool update_attitude_status(); }; diff --git a/src/modules/commander/failure_detector/failure_detector_params.c b/src/modules/commander/failure_detector/failure_detector_params.c index 330276e331..b7642978af 100644 --- a/src/modules/commander/failure_detector/failure_detector_params.c +++ b/src/modules/commander/failure_detector/failure_detector_params.c @@ -46,7 +46,7 @@ * FailureDetector Max Roll * * Maximum roll angle before FailureDetector triggers the attitude_failure flag - * If flight termination is enabled (@CBRK_FLIGHTTERM set to zero), the autopilot + * If flight termination is enabled (@CBRK_FLIGHTTERM set to 0), the autopilot * will terminate the flight and set all the outputs to their failsafe value * as soon as the attitude_failure flag is set. * @@ -63,7 +63,7 @@ PARAM_DEFINE_INT32(FD_FAIL_R, 60); * FailureDetector Max Pitch * * Maximum pitch angle before FailureDetector triggers the attitude_failure flag - * If flight termination is enabled (@CBRK_FLIGHTTERM set to zero), the autopilot + * If flight termination is enabled (@CBRK_FLIGHTTERM set to 0), the autopilot * will terminate the flight and set all the outputs to their failsafe value * as soon as the attitude_failure flag is set. * @@ -75,3 +75,31 @@ PARAM_DEFINE_INT32(FD_FAIL_R, 60); * @group Failure Detector */ PARAM_DEFINE_INT32(FD_FAIL_P, 60); + +/** + * Roll failure trigger time + * + * Seconds (decimal) that roll has to exceed FD_FAIL_R before being considered as a failure. + * + * @unit s + * @min 0.02 + * @max 5 + * @decimal 2 + * + * @group Failure Detector + */ +PARAM_DEFINE_FLOAT(FD_FAIL_R_TTRI, 0.3); + +/** + * Pitch failure trigger time + * + * Seconds (decimal) that pitch has to exceed FD_FAIL_P before being considered as a failure. + * + * @unit s + * @min 0.02 + * @max 5 + * @decimal 2 + * + * @group Failure Detector + */ +PARAM_DEFINE_FLOAT(FD_FAIL_P_TTRI, 0.3);