diff --git a/boards/ark/fmu-v6x/extras/px4_io-v2_default.bin b/boards/ark/fmu-v6x/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/ark/fmu-v6x/extras/px4_io-v2_default.bin and b/boards/ark/fmu-v6x/extras/px4_io-v2_default.bin differ diff --git a/boards/cubepilot/cubeorange/extras/cubepilot_io-v2_default.bin b/boards/cubepilot/cubeorange/extras/cubepilot_io-v2_default.bin index fee2b66993..09dc41bce8 100755 Binary files a/boards/cubepilot/cubeorange/extras/cubepilot_io-v2_default.bin and b/boards/cubepilot/cubeorange/extras/cubepilot_io-v2_default.bin differ diff --git a/boards/cubepilot/cubeorangeplus/extras/cubepilot_io-v2_default.bin b/boards/cubepilot/cubeorangeplus/extras/cubepilot_io-v2_default.bin index 3eab1b7bde..09dc41bce8 100755 Binary files a/boards/cubepilot/cubeorangeplus/extras/cubepilot_io-v2_default.bin and b/boards/cubepilot/cubeorangeplus/extras/cubepilot_io-v2_default.bin differ diff --git a/boards/cubepilot/cubeyellow/extras/cubepilot_io-v2_default.bin b/boards/cubepilot/cubeyellow/extras/cubepilot_io-v2_default.bin index fee2b66993..09dc41bce8 100755 Binary files a/boards/cubepilot/cubeyellow/extras/cubepilot_io-v2_default.bin and b/boards/cubepilot/cubeyellow/extras/cubepilot_io-v2_default.bin differ diff --git a/boards/holybro/durandal-v1/extras/px4_io-v2_default.bin b/boards/holybro/durandal-v1/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/holybro/durandal-v1/extras/px4_io-v2_default.bin and b/boards/holybro/durandal-v1/extras/px4_io-v2_default.bin differ diff --git a/boards/holybro/pix32v5/extras/px4_io-v2_default.bin b/boards/holybro/pix32v5/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/holybro/pix32v5/extras/px4_io-v2_default.bin and b/boards/holybro/pix32v5/extras/px4_io-v2_default.bin differ diff --git a/boards/mro/x21-777/extras/px4_io-v2_default.bin b/boards/mro/x21-777/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/mro/x21-777/extras/px4_io-v2_default.bin and b/boards/mro/x21-777/extras/px4_io-v2_default.bin differ diff --git a/boards/mro/x21/extras/px4_io-v2_default.bin b/boards/mro/x21/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/mro/x21/extras/px4_io-v2_default.bin and b/boards/mro/x21/extras/px4_io-v2_default.bin differ diff --git a/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld b/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld index 0e6701aae2..5e1f8375b8 100644 --- a/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld @@ -561,7 +561,7 @@ *(.text.uart_xmitchars_done) *(.text._ZN4EKF225PublishYawEstimatorStatusERKy) *(.text.sin) -*(.text._ZN6Safety19safetyButtonHandlerEv) +*(.text._ZN6Safety19safetySwitchHandlerEv) *(.text._ZN3Ekf19controlAuxVelFusionERKN9estimator9imuSampleE) *(.text._ZNK6matrix6MatrixIfLj2ELj1EEplERKS1_) *(.text._ZThn24_N7Sensors3RunEv) diff --git a/boards/px4/fmu-v2/extras/px4_io-v2_default.bin b/boards/px4/fmu-v2/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/px4/fmu-v2/extras/px4_io-v2_default.bin and b/boards/px4/fmu-v2/extras/px4_io-v2_default.bin differ diff --git a/boards/px4/fmu-v3/extras/px4_io-v2_default.bin b/boards/px4/fmu-v3/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/px4/fmu-v3/extras/px4_io-v2_default.bin and b/boards/px4/fmu-v3/extras/px4_io-v2_default.bin differ diff --git a/boards/px4/fmu-v4pro/extras/px4_io-v2_default.bin b/boards/px4/fmu-v4pro/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/px4/fmu-v4pro/extras/px4_io-v2_default.bin and b/boards/px4/fmu-v4pro/extras/px4_io-v2_default.bin differ diff --git a/boards/px4/fmu-v5/extras/px4_io-v2_default.bin b/boards/px4/fmu-v5/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/px4/fmu-v5/extras/px4_io-v2_default.bin and b/boards/px4/fmu-v5/extras/px4_io-v2_default.bin differ diff --git a/boards/px4/fmu-v5x/extras/px4_io-v2_default.bin b/boards/px4/fmu-v5x/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/px4/fmu-v5x/extras/px4_io-v2_default.bin and b/boards/px4/fmu-v5x/extras/px4_io-v2_default.bin differ diff --git a/boards/px4/fmu-v6c/extras/px4_io-v2_default.bin b/boards/px4/fmu-v6c/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/px4/fmu-v6c/extras/px4_io-v2_default.bin and b/boards/px4/fmu-v6c/extras/px4_io-v2_default.bin differ diff --git a/boards/px4/fmu-v6x/extras/px4_io-v2_default.bin b/boards/px4/fmu-v6x/extras/px4_io-v2_default.bin index 145089ae0d..140ad0438d 100755 Binary files a/boards/px4/fmu-v6x/extras/px4_io-v2_default.bin and b/boards/px4/fmu-v6x/extras/px4_io-v2_default.bin differ diff --git a/boards/px4/fmu-v6xrt/extras/px4_io-v2_default.bin b/boards/px4/fmu-v6xrt/extras/px4_io-v2_default.bin index 5140391401..140ad0438d 100755 Binary files a/boards/px4/fmu-v6xrt/extras/px4_io-v2_default.bin and b/boards/px4/fmu-v6xrt/extras/px4_io-v2_default.bin differ diff --git a/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld b/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld index a52a3b46b0..ed148c6797 100644 --- a/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld @@ -573,7 +573,7 @@ *(.text.uart_xmitchars_done) *(.text._ZN4EKF225PublishYawEstimatorStatusERKy) *(.text.sin) -*(.text._ZN6Safety19safetyButtonHandlerEv) +*(.text._ZN6Safety19safetySwitchHandlerEv) *(.text._ZN3Ekf19controlAuxVelFusionERKN9estimator9imuSampleE) *(.text._ZNK6matrix6MatrixIfLj2ELj1EEplERKS1_) *(.text._ZThn24_N7Sensors3RunEv) diff --git a/boards/siyi/n7/extras/px4_io-v2_default.bin b/boards/siyi/n7/extras/px4_io-v2_default.bin index 957f0f13a1..140ad0438d 100755 Binary files a/boards/siyi/n7/extras/px4_io-v2_default.bin and b/boards/siyi/n7/extras/px4_io-v2_default.bin differ diff --git a/boards/sky-drones/smartap-airlink/extras/px4_io-v2_default.bin b/boards/sky-drones/smartap-airlink/extras/px4_io-v2_default.bin index 25a00e2357..140ad0438d 100755 Binary files a/boards/sky-drones/smartap-airlink/extras/px4_io-v2_default.bin and b/boards/sky-drones/smartap-airlink/extras/px4_io-v2_default.bin differ diff --git a/boards/thepeach/k1/extras/px4_io-v2_default.bin b/boards/thepeach/k1/extras/px4_io-v2_default.bin index 957f0f13a1..140ad0438d 100755 Binary files a/boards/thepeach/k1/extras/px4_io-v2_default.bin and b/boards/thepeach/k1/extras/px4_io-v2_default.bin differ diff --git a/boards/thepeach/r1/extras/px4_io-v2_default.bin b/boards/thepeach/r1/extras/px4_io-v2_default.bin index 957f0f13a1..140ad0438d 100755 Binary files a/boards/thepeach/r1/extras/px4_io-v2_default.bin and b/boards/thepeach/r1/extras/px4_io-v2_default.bin differ diff --git a/boards/zeroone/x6/extras/px4_io-v2_default.bin b/boards/zeroone/x6/extras/px4_io-v2_default.bin old mode 100644 new mode 100755 index 145089ae0d..140ad0438d Binary files a/boards/zeroone/x6/extras/px4_io-v2_default.bin and b/boards/zeroone/x6/extras/px4_io-v2_default.bin differ diff --git a/msg/CMakeLists.txt b/msg/CMakeLists.txt index fdc23a889f..bd1bf2436b 100644 --- a/msg/CMakeLists.txt +++ b/msg/CMakeLists.txt @@ -186,6 +186,7 @@ set(msg_files Rpm.msg RtlStatus.msg RtlTimeEstimate.msg + SafetySwitch.msg SatelliteInfo.msg SensorAccel.msg SensorAccelFifo.msg diff --git a/msg/SafetySwitch.msg b/msg/SafetySwitch.msg new file mode 100644 index 0000000000..beeb08a8b5 --- /dev/null +++ b/msg/SafetySwitch.msg @@ -0,0 +1,2 @@ +uint64 timestamp # time since system start (microseconds) +bool state # Represents the state of the safety switch (on/off) diff --git a/src/drivers/px4io/px4io.cpp b/src/drivers/px4io/px4io.cpp index d10573984d..2b264d0312 100644 --- a/src/drivers/px4io/px4io.cpp +++ b/src/drivers/px4io/px4io.cpp @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -211,9 +212,11 @@ private: /* advertised topics */ uORB::PublicationMulti _input_rc_pub{ORB_ID(input_rc)}; uORB::Publication _px4io_status_pub{ORB_ID(px4io_status)}; + uORB::Publication _safety_switch_pub{ORB_ID(safety_switch)}; ButtonPublisher _button_publisher; bool _previous_safety_off{false}; + bool _previous_safety_switch_state{false}; bool _lockdown_override{false}; ///< override the safety lockdown @@ -863,6 +866,20 @@ int PX4IO::io_handle_status(uint16_t status) _button_publisher.safetyButtonTriggerEvent(); } + /** + * Get and handle the safety switch status + */ + const bool safety_switch_state = status & PX4IO_P_STATUS_FLAGS_SAFETY_SWITCH_STATE; + + if (safety_switch_state != _previous_safety_switch_state) { + safety_switch_s safety_switch{}; + safety_switch.timestamp = hrt_absolute_time(); + safety_switch.state = safety_switch_state; + _safety_switch_pub.publish(safety_switch); + + _previous_safety_switch_state = safety_switch_state; + } + /** * Inform PX4IO board about safety_off state for LED control */ diff --git a/src/drivers/safety_button/SafetyButton.cpp b/src/drivers/safety_button/SafetyButton.cpp index aa5c45e8d9..0c4af4b777 100644 --- a/src/drivers/safety_button/SafetyButton.cpp +++ b/src/drivers/safety_button/SafetyButton.cpp @@ -63,10 +63,10 @@ SafetyButton::~SafetyButton() } void -SafetyButton::CheckSafetyRequest(bool button_pressed) +SafetyButton::CheckSafetyRequest(bool safety_switch_state) { /* Keep button pressed for one second to turn off safety */ - if (button_pressed) { + if (safety_switch_state) { if (_button_counter <= CYCLE_COUNT) { _button_counter++; @@ -79,10 +79,18 @@ SafetyButton::CheckSafetyRequest(bool button_pressed) } else { _button_counter = 0; } + + /* Collect the raw safety switch state */ + if (safety_switch_state != _previous_safety_switch_state) { + safety_switch_s safety_switch{}; + safety_switch.timestamp = hrt_absolute_time(); + safety_switch.state = safety_switch_state; + _safety_switch_pub.publish(safety_switch); + } } void -SafetyButton::CheckPairingRequest(bool button_pressed) +SafetyButton::CheckPairingRequest(bool safety_switch_state) { // Need to press the button 3 times within 2 seconds const hrt_abstime now = hrt_absolute_time(); @@ -93,7 +101,7 @@ SafetyButton::CheckPairingRequest(bool button_pressed) _pairing_button_counter = 0; } - if (!_button_prev_sate && button_pressed) { + if (!_previous_safety_switch_state && safety_switch_state) { if (_pairing_start == 0) { _pairing_start = now; } @@ -120,7 +128,7 @@ SafetyButton::FlashButton() LED_PATTERN pattern = LED_PATTERN::FMU_REFUSE_TO_ARM; // cycle the blink state machine - if (_button_prev_sate) { + if (_previous_safety_switch_state) { if (armed.armed) { pattern = LED_PATTERN::IO_FMU_ARMED; @@ -154,16 +162,16 @@ SafetyButton::Run() return; } - const bool button_pressed = px4_arch_gpioread(GPIO_BTN_SAFETY); + const bool safety_switch_state = px4_arch_gpioread(GPIO_BTN_SAFETY); // control safety switch LED & safety button if (!_has_px4io) { FlashButton(); - CheckSafetyRequest(button_pressed); + CheckSafetyRequest(safety_switch_state); } - CheckPairingRequest(button_pressed); - _button_prev_sate = button_pressed; + CheckPairingRequest(safety_switch_state); + _previous_safety_switch_state = safety_switch_state; } int diff --git a/src/drivers/safety_button/SafetyButton.hpp b/src/drivers/safety_button/SafetyButton.hpp index 0f38b6ba82..abae71d878 100644 --- a/src/drivers/safety_button/SafetyButton.hpp +++ b/src/drivers/safety_button/SafetyButton.hpp @@ -40,6 +40,10 @@ #include #include