From 14a7e79a23a02c87f69a398a0dbb966e695330a7 Mon Sep 17 00:00:00 2001 From: alexcekay Date: Wed, 25 Nov 2026 13:55:14 +0100 Subject: [PATCH] feat(esc_battery): let boards set an open circuit voltage ESCs can stay powered without a battery, e.g. when VBAT is back-fed from USB, and then report a low voltage that is flagged as a low battery. A board can now set BOARD_ESC_BATTERY_OPEN_CIRCUIT_V so that such a reading counts as no battery connected. The default of 0V keeps the current behavior. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: alexcekay --- platforms/common/include/px4_platform_common/board_common.h | 6 ++++++ src/modules/esc_battery/EscBattery.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/platforms/common/include/px4_platform_common/board_common.h b/platforms/common/include/px4_platform_common/board_common.h index aaf47003164..be9e5533853 100644 --- a/platforms/common/include/px4_platform_common/board_common.h +++ b/platforms/common/include/px4_platform_common/board_common.h @@ -137,6 +137,12 @@ # define BOARD_ADC_OPEN_CIRCUIT_V (1.5f) #endif +/* Define the default ESC-reported battery voltage at or below which no battery is considered connected */ + +#if !defined(BOARD_ESC_BATTERY_OPEN_CIRCUIT_V) +# define BOARD_ESC_BATTERY_OPEN_CIRCUIT_V (0.0f) +#endif + /* Define the default Under voltage Window on the LTC4417 as set by resistors on the * board. Default is that of the FMUv2 at 3.7V */ diff --git a/src/modules/esc_battery/EscBattery.cpp b/src/modules/esc_battery/EscBattery.cpp index a2c38d898ef..4397421f59e 100644 --- a/src/modules/esc_battery/EscBattery.cpp +++ b/src/modules/esc_battery/EscBattery.cpp @@ -111,7 +111,7 @@ EscBattery::Run() average_voltage_v /= online_esc_count; - _battery.setConnected(true); + _battery.setConnected(average_voltage_v > BOARD_ESC_BATTERY_OPEN_CIRCUIT_V); _battery.updateVoltage(average_voltage_v); _battery.updateCurrent(total_current_a); _battery.updateAndPublishBatteryStatus(esc_status.timestamp);