battery: report at least one cell for a connected battery

This commit is contained in:
Matthias Grob 2020-10-16 11:14:50 +02:00 committed by Lorenz Meier
parent d9954ecaf0
commit 39b0c7b2bf
1 changed files with 3 additions and 2 deletions

View File

@ -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 &timestamp, 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;
}