From 70439f172d50a3d1d0816331118fa2fbdf2421a8 Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Thu, 25 Apr 2024 22:20:01 +0300 Subject: [PATCH] selfcheck.py: address situation when individual cells voltage is unknown When length of cell_voltage array is 1, it means that cell voltage is unknown and overall voltage is reported instead. Consider this situation gathering the number of cells from PX4 parameters. --- clover/src/selfcheck.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clover/src/selfcheck.py b/clover/src/selfcheck.py index 274594b7..538b9f0f 100755 --- a/clover/src/selfcheck.py +++ b/clover/src/selfcheck.py @@ -303,6 +303,14 @@ def check_fcu(): failure('cell voltage is not available, https://clover.coex.tech/power') else: cell = battery.cell_voltage[0] + # number of cells 1 means this is overall voltage + if len(battery.cell_voltage) == 1: + n_cells = get_param('BAT1_N_CELLS', strict=False) + if n_cells is None: + # older PX4 + n_cells = get_param('BAT_N_CELLS', strict=True) + cell /= n_cells + if cell > 4.3 or cell < 3.0: failure('incorrect cell voltage: %.2f V, https://clover.coex.tech/power', cell) elif cell < 3.7: