battery: skip charge estimation if N cells is 0

This triggers the undefined behaviour fuzzer, so let's try to fix it.

Signed-off-by: Julian Oes <julian@oes.ch>
This commit is contained in:
Julian Oes 2022-07-14 08:40:49 +12:00 committed by Beat Küng
parent 44d1003f8e
commit 84577ce2c2

View File

@ -206,6 +206,10 @@ void Battery::sumDischarged(const hrt_abstime &timestamp, float current_a)
float Battery::calculateStateOfChargeVoltageBased(const float voltage_v, const float current_a)
{
if (_params.n_cells == 0) {
return -1.0f;
}
// remaining battery capacity based on voltage
float cell_voltage = voltage_v / _params.n_cells;