mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-19 19:04:33 +08:00
drivers/safety_button: only publish safety at 1 Hz or immeidately on change
This commit is contained in:
@@ -213,13 +213,18 @@ SafetyButton::Run()
|
||||
if (!PX4_MFT_HW_SUPPORTED(PX4_MFT_PX4IO)) {
|
||||
FlashButton();
|
||||
|
||||
safety_s safety{};
|
||||
safety.timestamp = hrt_absolute_time();
|
||||
safety.safety_switch_available = true;
|
||||
safety.safety_off = _safety_btn_off || _safety_disabled;
|
||||
const bool safety_off = _safety_btn_off || _safety_disabled;
|
||||
|
||||
// publish the safety status
|
||||
_to_safety.publish(safety);
|
||||
// publish immediately on change, otherwise at 1 Hz
|
||||
if ((hrt_elapsed_time(&_safety.timestamp) >= 1_s)
|
||||
|| (_safety.safety_off != safety_off)) {
|
||||
|
||||
_safety.safety_switch_available = true;
|
||||
_safety.safety_off = safety_off;
|
||||
_safety.timestamp = hrt_absolute_time();
|
||||
|
||||
_to_safety.publish(_safety);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ private:
|
||||
uORB::PublicationQueued<led_control_s> _to_led_control{ORB_ID(led_control)};
|
||||
uORB::Publication<tune_control_s> _to_tune_control{ORB_ID(tune_control)};
|
||||
|
||||
safety_s _safety{};
|
||||
|
||||
uint8_t _button_counter{0};
|
||||
uint8_t _blink_counter{0};
|
||||
|
||||
Reference in New Issue
Block a user