From ff112a726b3a0b035f714dcac706452606c4f58b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Mar 2020 08:18:12 +1100 Subject: [PATCH] AP_Battery: fixed bug in SUI driver fixed bug in total voltage --- libraries/AP_BattMonitor/AP_BattMonitor_SMBus_SUI.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_SUI.cpp b/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_SUI.cpp index eea77013a2..e975523bcf 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_SUI.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_SUI.cpp @@ -139,10 +139,11 @@ void AP_BattMonitor_SMBus_SUI::read_cell_voltages() pack_voltage_mv = total_mv; } else { // we can't get total pack voltage. Use average of cells we have so far + const uint16_t cell_mv = pack_voltage_mv / SUI_MAX_CELL_READ; for (uint8_t i = SUI_MAX_CELL_READ; i < cell_count; i++) { - _state.cell_voltages.cells[i] = pack_voltage_mv / SUI_MAX_CELL_READ; - pack_voltage_mv += _state.cell_voltages.cells[i]; + _state.cell_voltages.cells[i] = cell_mv; } + pack_voltage_mv += cell_mv * (cell_count - SUI_MAX_CELL_READ); } }