From 39b0c7b2bf8ff55b0392602f738fad7e1cc3f589 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Fri, 16 Oct 2020 11:14:50 +0200 Subject: [PATCH] battery: report at least one cell for a connected battery --- src/lib/battery/battery.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/battery/battery.cpp b/src/lib/battery/battery.cpp index 9012aad797..0c95896299 100644 --- a/src/lib/battery/battery.cpp +++ b/src/lib/battery/battery.cpp @@ -109,7 +109,8 @@ void Battery::reset() _battery_status.current_a = -1.f; _battery_status.remaining = 1.f; _battery_status.scale = 1.f; - _battery_status.cell_count = _params.n_cells; + // Publish at least one cell such that the total voltage gets into MAVLink BATTERY_STATUS + _battery_status.cell_count = math::max(_params.n_cells, 1); // TODO: check if it is sane to reset warning to NONE _battery_status.warning = battery_status_s::BATTERY_WARNING_NONE; _battery_status.connected = false; @@ -157,7 +158,7 @@ void Battery::updateBatteryStatus(const hrt_abstime ×tamp, float voltage_v, static constexpr int uorb_max_cells = sizeof(_battery_status.voltage_cell_v) / sizeof( _battery_status.voltage_cell_v[0]); - // Fill cell voltages with average values to work around BATTERY_STATUS message not allowing to report just total voltage + // Fill cell voltages with average values to work around MAVLink BATTERY_STATUS not allowing to report just total voltage for (int i = 0; (i < _battery_status.cell_count) && (i < uorb_max_cells); i++) { _battery_status.voltage_cell_v[i] = _battery_status.voltage_filtered_v / _battery_status.cell_count; }