battery: make time remaining estimation dependent on level flight cha… (#22401)

* battery: make time remaining estimation dependent on level flight characteristis for FW

* battery: fix that FW flight is also correctly detected when vehicle_status is not updated

Signed-off-by: Silvan Fuhrer <silvan@auterion.com>

* FixedwingPositionControl: Move constant to header file

* flight phase estimation: use tecs height rate reference to check for level flight

---------

Signed-off-by: Silvan Fuhrer <silvan@auterion.com>
Co-authored-by: Silvan Fuhrer <silvan@auterion.com>
This commit is contained in:
KonradRudin
2024-02-06 17:32:09 +01:00
committed by GitHub
parent bf52d8adc9
commit 3576d513cd
8 changed files with 60 additions and 4 deletions
+9 -2
View File
@@ -311,16 +311,23 @@ float Battery::computeRemainingTime(float current_a)
if (_vehicle_status_sub.copy(&vehicle_status)) {
_armed = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED);
_vehicle_status_is_fw = (vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING);
}
}
_flight_phase_estimation_sub.update();
if (!PX4_ISFINITE(_current_average_filter_a.getState()) || _current_average_filter_a.getState() < FLT_EPSILON) {
_current_average_filter_a.reset(_params.bat_avrg_current);
}
if (_armed && PX4_ISFINITE(current_a)) {
// only update with positive numbers
_current_average_filter_a.update(fmaxf(current_a, 0.f));
// For FW only update when we are in level flight
if (!_vehicle_status_is_fw || ((hrt_absolute_time() - _flight_phase_estimation_sub.get().timestamp) < 2_s
&& _flight_phase_estimation_sub.get().flight_phase == flight_phase_estimation_s::FLIGHT_PHASE_LEVEL)) {
// only update with positive numbers
_current_average_filter_a.update(fmaxf(current_a, 0.f));
}
}
// Remaining time estimation only possible with capacity