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 <silvan@auterion.com>
This commit is contained in:
Silvan Fuhrer 2023-10-25 04:07:10 +02:00
parent f68f88b97c
commit 1e223b21eb
2 changed files with 13 additions and 1 deletions

View File

@ -287,16 +287,27 @@ void Battery::computeScale()
float Battery::computeRemainingTime(float current_a) float Battery::computeRemainingTime(float current_a)
{ {
float time_remaining_s = NAN; float time_remaining_s = NAN;
bool reset_current_avg_filter = false;
if (_vehicle_status_sub.updated()) { if (_vehicle_status_sub.updated()) {
vehicle_status_s vehicle_status; vehicle_status_s vehicle_status;
if (_vehicle_status_sub.copy(&vehicle_status)) { if (_vehicle_status_sub.copy(&vehicle_status)) {
_armed = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED); _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); _current_average_filter_a.reset(_params.bat_avrg_current);
} }

View File

@ -178,4 +178,5 @@ private:
hrt_abstime _last_timestamp{0}; hrt_abstime _last_timestamp{0};
bool _armed{false}; bool _armed{false};
hrt_abstime _last_unconnected_timestamp{0}; hrt_abstime _last_unconnected_timestamp{0};
bool _vtol_was_in_mc_mode{false};
}; };