From a0e6f9cd70397dd741efdb5d72d94b9ac88e97ce Mon Sep 17 00:00:00 2001 From: RomanBapst Date: Mon, 7 Oct 2024 14:05:02 +0300 Subject: [PATCH] commander: try to fix arm authorization spamming Signed-off-by: RomanBapst --- src/modules/commander/Commander.cpp | 2 +- src/modules/commander/HealthAndArmingChecks/Common.hpp | 5 +++++ .../HealthAndArmingChecks/HealthAndArmingChecks.cpp | 4 +++- .../HealthAndArmingChecks/HealthAndArmingChecks.hpp | 3 ++- .../commander/HealthAndArmingChecks/checks/systemCheck.cpp | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index a151b15989b4..eb6d67224c30 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -594,7 +594,7 @@ transition_result_t Commander::arm(arm_disarm_reason_t calling_reason, bool run_ return TRANSITION_DENIED; } - _health_and_arming_checks.update(); + _health_and_arming_checks.update(false, true); if (!_health_and_arming_checks.canArm(_vehicle_status.nav_state)) { tune_negative(true); diff --git a/src/modules/commander/HealthAndArmingChecks/Common.hpp b/src/modules/commander/HealthAndArmingChecks/Common.hpp index da7c5c296509..7fb454cbeb7c 100644 --- a/src/modules/commander/HealthAndArmingChecks/Common.hpp +++ b/src/modules/commander/HealthAndArmingChecks/Common.hpp @@ -128,10 +128,15 @@ class Context bool isArmed() const { return _status.arming_state == vehicle_status_s::ARMING_STATE_ARMED; } + bool isArmingRequest() const { return _is_arming_request; } + + void setIsArmingRequest(bool is_arming_request) { _is_arming_request = is_arming_request; } + const vehicle_status_s &status() const { return _status; } private: const vehicle_status_s &_status; + bool _is_arming_request{false}; // true if we currently have an arming request }; diff --git a/src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.cpp b/src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.cpp index a6381485139f..dbfea11ce881 100644 --- a/src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.cpp +++ b/src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.cpp @@ -50,12 +50,14 @@ HealthAndArmingChecks::HealthAndArmingChecks(ModuleParams *parent, vehicle_statu _failsafe_flags.home_position_invalid = true; } -bool HealthAndArmingChecks::update(bool force_reporting) +bool HealthAndArmingChecks::update(bool force_reporting, bool is_arming_request) { _reporter.reset(); _reporter.prepare(_context.status().vehicle_type); + _context.setIsArmingRequest(is_arming_request); + for (unsigned i = 0; i < sizeof(_checks) / sizeof(_checks[0]); ++i) { if (!_checks[i]) { break; diff --git a/src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.hpp b/src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.hpp index fdf38f5d5d77..f0dc8404f29f 100644 --- a/src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.hpp +++ b/src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.hpp @@ -83,9 +83,10 @@ class HealthAndArmingChecks : public ModuleParams * Run arming checks and report if necessary. * This should be called regularly (e.g. 1Hz). * @param force_reporting if true, force reporting even if nothing changed + * @param is_arming_request if true, then we are running the checks based on an actual arming request * @return true if there was a report (also when force_reporting=true) */ - bool update(bool force_reporting = false); + bool update(bool force_reporting = false, bool is_arming_request = false); /** * Whether arming is possible for a given navigation mode diff --git a/src/modules/commander/HealthAndArmingChecks/checks/systemCheck.cpp b/src/modules/commander/HealthAndArmingChecks/checks/systemCheck.cpp index dbb025210137..32beaba9af7b 100644 --- a/src/modules/commander/HealthAndArmingChecks/checks/systemCheck.cpp +++ b/src/modules/commander/HealthAndArmingChecks/checks/systemCheck.cpp @@ -173,7 +173,7 @@ void SystemChecks::checkAndReport(const Context &context, Report &reporter) } // Arm Requirements: authorization - if (_param_com_arm_auth_req.get() != 0 && !context.isArmed()) { + if (_param_com_arm_auth_req.get() != 0 && !context.isArmed() && context.isArmingRequest()) { if (arm_auth_check() != vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED) { /* EVENT */