From b7f8ee8ee744288fe25bc28ce819cf4a1de140a8 Mon Sep 17 00:00:00 2001 From: Silvan Fuhrer Date: Wed, 4 Oct 2023 13:28:04 +0200 Subject: [PATCH] batteryCheck: improve user notification for low battery events Signed-off-by: Silvan Fuhrer --- .../HealthAndArmingChecks/checks/batteryCheck.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/commander/HealthAndArmingChecks/checks/batteryCheck.cpp b/src/modules/commander/HealthAndArmingChecks/checks/batteryCheck.cpp index 6f617f2728..239eca727d 100644 --- a/src/modules/commander/HealthAndArmingChecks/checks/batteryCheck.cpp +++ b/src/modules/commander/HealthAndArmingChecks/checks/batteryCheck.cpp @@ -195,6 +195,7 @@ void BatteryChecks::checkAndReport(const Context &context, Report &reporter) } if (context.isArmed()) { + // if armed, only allow increase of battery warning severity if (worst_warning > reporter.failsafeFlags().battery_warning) { reporter.failsafeFlags().battery_warning = worst_warning; } @@ -205,16 +206,23 @@ void BatteryChecks::checkAndReport(const Context &context, Report &reporter) if (reporter.failsafeFlags().battery_warning > battery_status_s::BATTERY_WARNING_NONE && reporter.failsafeFlags().battery_warning < battery_status_s::BATTERY_WARNING_FAILED) { - bool critical_or_higher = reporter.failsafeFlags().battery_warning >= battery_status_s::BATTERY_WARNING_CRITICAL; + const bool critical_or_higher = reporter.failsafeFlags().battery_warning >= battery_status_s::BATTERY_WARNING_CRITICAL; NavModes affected_modes = critical_or_higher ? NavModes::All : NavModes::None; events::LogLevel log_level = critical_or_higher ? events::Log::Critical : events::Log::Warning; /* EVENT + * @description + * The battery state of charge of the worst battery is below the warning threshold. + * + * + * This check can be configured via BAT_LOW_THR, BAT_CRIT_THR and BAT_EMERGEN_THR parameters. + * */ reporter.armingCheckFailure(affected_modes, health_component_t::battery, events::ID("check_battery_low"), log_level, "Low battery"); if (reporter.mavlink_log_pub()) { - mavlink_log_emergency(reporter.mavlink_log_pub(), "Preflight Fail: low battery\t"); + mavlink_log_emergency(reporter.mavlink_log_pub(), "Low battery level\t"); + } } }