Skip to content

Commit

Permalink
commander: try to fix arm authorization spamming
Browse files Browse the repository at this point in the history
Signed-off-by: RomanBapst <[email protected]>
  • Loading branch information
RomanBapst committed Oct 14, 2024
1 parent e3dd050 commit a0e6f9c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/modules/commander/Commander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/modules/commander/HealthAndArmingChecks/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit a0e6f9c

Please sign in to comment.