mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 01:45:55 +08:00
IO safety button: cleanup disabling safety
This commit is contained in:
committed by
Lorenz Meier
parent
3fbd008c4e
commit
3ab4213314
@@ -75,8 +75,6 @@ static unsigned blink_counter = 0;
|
||||
*/
|
||||
#define ARM_COUNTER_THRESHOLD 10
|
||||
|
||||
static bool safety_button_pressed;
|
||||
|
||||
static void safety_check_button(void *arg);
|
||||
static void failsafe_blink(void *arg);
|
||||
|
||||
@@ -97,46 +95,24 @@ failsafe_led_init(void)
|
||||
static void
|
||||
safety_check_button(void *arg)
|
||||
{
|
||||
/*
|
||||
* Debounce the safety button, change state if it has been held for long enough.
|
||||
*
|
||||
*/
|
||||
safety_button_pressed = BUTTON_SAFETY;
|
||||
const bool safety_button_pressed = BUTTON_SAFETY;
|
||||
|
||||
/*
|
||||
* Keep pressed for a while to disable safety.
|
||||
/* Keep safety button pressed for one second to turn off safety
|
||||
*
|
||||
* Note that the counting sequence has to be same length
|
||||
* for arming / disarming in order to end up as proper
|
||||
* state machine, keep ARM_COUNTER_THRESHOLD the same
|
||||
* length in all cases of the if/else struct below.
|
||||
* Note that safety cannot be turned on again by button because a button
|
||||
* hardware problem could accidentally disable it in flight.
|
||||
*/
|
||||
if (safety_button_pressed && !(r_status_flags & PX4IO_P_STATUS_FLAGS_SAFETY_OFF) &&
|
||||
(r_setup_arming & PX4IO_P_SETUP_ARMING_IO_ARM_OK)) {
|
||||
|
||||
if (counter < ARM_COUNTER_THRESHOLD) {
|
||||
if (counter <= ARM_COUNTER_THRESHOLD) {
|
||||
counter++;
|
||||
|
||||
} else if (counter == ARM_COUNTER_THRESHOLD) {
|
||||
/* switch to safety off state - the system still needs to be
|
||||
* fully armed by the operator
|
||||
*/
|
||||
atomic_modify_or(&r_status_flags, PX4IO_P_STATUS_FLAGS_SAFETY_OFF);
|
||||
counter++;
|
||||
}
|
||||
|
||||
} else if (safety_button_pressed && (r_status_flags & PX4IO_P_STATUS_FLAGS_SAFETY_OFF)) {
|
||||
|
||||
if (counter < ARM_COUNTER_THRESHOLD) {
|
||||
counter++;
|
||||
|
||||
} else if (counter == ARM_COUNTER_THRESHOLD) {
|
||||
/* we are not switching out of the armed state
|
||||
* as a stuck button could cause this during
|
||||
* normal operation. The system needs to be
|
||||
* disarmed by software
|
||||
*/
|
||||
counter++;
|
||||
if (counter == ARM_COUNTER_THRESHOLD) {
|
||||
// switch safety off -> ready to arm state
|
||||
atomic_modify_or(&r_status_flags, PX4IO_P_STATUS_FLAGS_SAFETY_OFF);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user