From 1e223b21eb414d64489f8d0eb486c0f01c50a959 Mon Sep 17 00:00:00 2001 From: Silvan Fuhrer Date: Wed, 25 Oct 2023 04:07:10 +0200 Subject: [PATCH] battery: reset current filter when transitioning to FW VTOLs consume a lot more power in hover copared to fixed-wing fligt. The remaining flight time thus should reset if one switches from MC to FW, as otherwise it takes several minutes until the estimate goes down. Signed-off-by: Silvan Fuhrer --- src/lib/battery/battery.cpp | 13 ++++++++++++- src/lib/battery/battery.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/battery/battery.cpp b/src/lib/battery/battery.cpp index 2ed157dee4..92bb5374b9 100644 --- a/src/lib/battery/battery.cpp +++ b/src/lib/battery/battery.cpp @@ -287,16 +287,27 @@ void Battery::computeScale() float Battery::computeRemainingTime(float current_a) { float time_remaining_s = NAN; + bool reset_current_avg_filter = false; if (_vehicle_status_sub.updated()) { vehicle_status_s vehicle_status; if (_vehicle_status_sub.copy(&vehicle_status)) { _armed = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED); + + if (vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING && _vtol_was_in_mc_mode) { + reset_current_avg_filter = true; + _vtol_was_in_mc_mode = false; + + } else if (vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING) { + _vtol_was_in_mc_mode = true; + } } } - if (!PX4_ISFINITE(_current_average_filter_a.getState()) || _current_average_filter_a.getState() < FLT_EPSILON) { + // reset filter if not feasible, negative or we did a VTOL transition to FW mode + if (!PX4_ISFINITE(_current_average_filter_a.getState()) || _current_average_filter_a.getState() < FLT_EPSILON || + reset_current_avg_filter) { _current_average_filter_a.reset(_params.bat_avrg_current); } diff --git a/src/lib/battery/battery.h b/src/lib/battery/battery.h index 26dc4e3e61..5db6e700c7 100644 --- a/src/lib/battery/battery.h +++ b/src/lib/battery/battery.h @@ -178,4 +178,5 @@ private: hrt_abstime _last_timestamp{0}; bool _armed{false}; hrt_abstime _last_unconnected_timestamp{0}; + bool _vtol_was_in_mc_mode{false}; };