mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 01:53:33 +08:00
commander: ensure health report is always sent out before failsafe notificaation
As the failsafe message can reference the health report, the health report needs to be sent out first. This is generally the case, except there is a rate limiter set to 2 seconds. So if the report changes quickly, it is sent out delayed (potentially after the failsafe report).
This commit is contained in:
@@ -170,6 +170,10 @@ void FailsafeBase::removeActions(ClearCondition condition)
|
||||
|
||||
void FailsafeBase::notifyUser(uint8_t user_intended_mode, Action action, Action delayed_action, Cause cause)
|
||||
{
|
||||
if (_on_notify_user_cb) {
|
||||
_on_notify_user_cb(_on_notify_user_arg);
|
||||
}
|
||||
|
||||
int delay_s = (_current_delay + 500_ms) / 1_s;
|
||||
PX4_DEBUG("User notification: failsafe triggered (action=%i, delayed_action=%i, cause=%i, delay=%is)", (int)action,
|
||||
(int)delayed_action, (int)cause, delay_s);
|
||||
|
||||
@@ -165,6 +165,17 @@ public:
|
||||
bool getDeferFailsafes() const { return _defer_failsafes; }
|
||||
bool failsafeDeferred() const { return _failsafe_defer_started != 0; }
|
||||
|
||||
using UserCallback = void(*)(void *);
|
||||
|
||||
/**
|
||||
* Register a callback that is called before notifying the user.
|
||||
*/
|
||||
void setOnNotifyUserCallback(UserCallback callback, void *arg)
|
||||
{
|
||||
_on_notify_user_cb = callback;
|
||||
_on_notify_user_arg = arg;
|
||||
}
|
||||
|
||||
protected:
|
||||
enum class UserTakeoverAllowed {
|
||||
Always, ///< allow takeover (immediately)
|
||||
@@ -278,6 +289,9 @@ private:
|
||||
|
||||
orb_advert_t _mavlink_log_pub{nullptr};
|
||||
|
||||
UserCallback _on_notify_user_cb{nullptr};
|
||||
void *_on_notify_user_arg{nullptr};
|
||||
|
||||
DEFINE_PARAMETERS_CUSTOM_PARENT(ModuleParams,
|
||||
(ParamFloat<px4::params::COM_FAIL_ACT_T>) _param_com_fail_act_t
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user