From 65537bdaca1a576b4b5f7aa9be16d84f7df12e98 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 25 Aug 2023 19:50:39 +1000 Subject: [PATCH] AP_BattMonitor: cope with NaN in consumed_mah --- libraries/AP_BattMonitor/AP_BattMonitor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.cpp b/libraries/AP_BattMonitor/AP_BattMonitor.cpp index 4389510893..9bab38a85a 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor.cpp @@ -566,7 +566,11 @@ bool AP_BattMonitor::current_amps(float ¤t, uint8_t instance) const { /// consumed_mah - returns total current drawn since start-up in milliampere.hours bool AP_BattMonitor::consumed_mah(float &mah, const uint8_t instance) const { if ((instance < _num_instances) && (drivers[instance] != nullptr) && drivers[instance]->has_current()) { - mah = state[instance].consumed_mah; + const float consumed_mah = state[instance].consumed_mah; + if (isnan(consumed_mah)) { + return false; + } + mah = consumed_mah; return true; } else { return false;