From c199994fb81c033b1f2931a065bb026e26ee78a9 Mon Sep 17 00:00:00 2001 From: bdilman Date: Thu, 23 Jan 2025 17:07:56 +0100 Subject: [PATCH] parameterized condition to allow external mode registrations while armed with COM_MODE_ARM_CHK --- .../HealthAndArmingChecks/checks/externalChecks.hpp | 6 +++++- src/modules/commander/ModeManagement.cpp | 2 +- src/modules/commander/commander_params.c | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/modules/commander/HealthAndArmingChecks/checks/externalChecks.hpp b/src/modules/commander/HealthAndArmingChecks/checks/externalChecks.hpp index 7129e4620361..8b833e0185c2 100644 --- a/src/modules/commander/HealthAndArmingChecks/checks/externalChecks.hpp +++ b/src/modules/commander/HealthAndArmingChecks/checks/externalChecks.hpp @@ -38,6 +38,7 @@ #include #include #include +#include static_assert((1ull << arming_check_reply_s::HEALTH_COMPONENT_INDEX_AVOIDANCE) == (uint64_t) health_component_t::avoidance, "enum definition missmatch"); @@ -66,7 +67,7 @@ class ExternalChecks : public HealthAndArmingCheckBase void update(); bool isUnresponsive(int registration_id); - + bool allowUpdateWhileArmed() const { return _param_com_mode_arm_chk.get(); } private: static constexpr hrt_abstime REQUEST_TIMEOUT = 50_ms; static constexpr hrt_abstime UPDATE_INTERVAL = 300_ms; @@ -109,4 +110,7 @@ class ExternalChecks : public HealthAndArmingCheckBase uORB::Subscription _arming_check_reply_sub{ORB_ID(arming_check_reply)}; uORB::Publication _arming_check_request_pub{ORB_ID(arming_check_request)}; + DEFINE_PARAMETERS( + (ParamInt) _param_com_mode_arm_chk + ); }; diff --git a/src/modules/commander/ModeManagement.cpp b/src/modules/commander/ModeManagement.cpp index 14ba7ba28fa3..a7da6ea4e097 100644 --- a/src/modules/commander/ModeManagement.cpp +++ b/src/modules/commander/ModeManagement.cpp @@ -370,7 +370,7 @@ void ModeManagement::update(bool armed, uint8_t user_intended_nav_state, bool fa _failsafe_action_active = failsafe_action_active; _external_checks.update(); - bool allow_update_while_armed = false; + bool allow_update_while_armed = _external_checks.allowUpdateWhileArmed(); #if defined(CONFIG_ARCH_BOARD_PX4_SITL) // For simulation, allow registering modes while armed for developer convenience allow_update_while_armed = true; diff --git a/src/modules/commander/commander_params.c b/src/modules/commander/commander_params.c index 48b0cce5221a..6be3833843fe 100644 --- a/src/modules/commander/commander_params.c +++ b/src/modules/commander/commander_params.c @@ -1018,3 +1018,15 @@ PARAM_DEFINE_FLOAT(COM_THROW_SPEED, 5); * @increment 1 */ PARAM_DEFINE_INT32(COM_FLTT_LOW_ACT, 3); + +/** + * Condition to enable external mode registration while armed + * + * By default, mode registration is disabled while armed. + * + * @value 0 Disabled + * @value 1 Enabled + * + * @group Commander + */ +PARAM_DEFINE_INT32(COM_MODE_ARM_CHK, 0);