From 1f60a86d3296bb8dba27d3bd4039af0a6267cf65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 1 Apr 2020 16:05:46 +0200 Subject: [PATCH] fix commander: need to copy all battery states in a cycle Previously if in a cycle only a disconnected battery status updated, the battery health state would switch to unhealthy during that time. Fixes intermittent 'Arming denied! Check battery' preflight failures on v5x with 1 power module connected. --- src/modules/commander/Commander.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index ec0a183fe6..7f681c7a80 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -3796,13 +3796,12 @@ void Commander::battery_status_check() battery_status_s batteries[ORB_MULTI_MAX_INSTANCES]; size_t num_connected_batteries = 0; - for (size_t i = 0; i < sizeof(_battery_subs) / sizeof(_battery_subs[0]); i++) { - if (_battery_subs[i].updated() && _battery_subs[i].copy(&batteries[num_connected_batteries])) { - // We need to update the status flag if ANY battery is updated, because the system source might have - // changed, or might be nothing (if there is no battery connected) - battery_sub_updated = true; + // We need to update the status flag if ANY battery is updated, because the system source might have + // changed, or might be nothing (if there is no battery connected) + battery_sub_updated |= _battery_subs[i].updated(); + if (_battery_subs[i].copy(&batteries[num_connected_batteries])) { if (batteries[num_connected_batteries].connected) { num_connected_batteries++; }