mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
battery: use mechanism to keep an up to date armed state
This commit is contained in:
@@ -56,7 +56,6 @@ Battery::Battery(int index, ModuleParams *parent, const int sample_interval_us,
|
|||||||
_voltage_filter_v.setParameters(expected_filter_dt, 1.f);
|
_voltage_filter_v.setParameters(expected_filter_dt, 1.f);
|
||||||
_current_filter_a.setParameters(expected_filter_dt, .5f);
|
_current_filter_a.setParameters(expected_filter_dt, .5f);
|
||||||
_current_average_filter_a.setParameters(expected_filter_dt, 50.f);
|
_current_average_filter_a.setParameters(expected_filter_dt, 50.f);
|
||||||
|
|
||||||
_throttle_filter.setParameters(expected_filter_dt, 1.f);
|
_throttle_filter.setParameters(expected_filter_dt, 1.f);
|
||||||
|
|
||||||
if (index > 9 || index < 1) {
|
if (index > 9 || index < 1) {
|
||||||
@@ -275,14 +274,19 @@ float Battery::computeRemainingTime(float current_a)
|
|||||||
|
|
||||||
// Remaining time estimation only possible with capacity
|
// Remaining time estimation only possible with capacity
|
||||||
if (_params.capacity > 0.f) {
|
if (_params.capacity > 0.f) {
|
||||||
vehicle_status_s vehicle_status{};
|
if (_vehicle_status_sub.updated()) {
|
||||||
_vehicle_status_sub.copy(&vehicle_status);
|
vehicle_status_s vehicle_status;
|
||||||
|
|
||||||
|
if (_vehicle_status_sub.copy(&vehicle_status)) {
|
||||||
|
_armed = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!PX4_ISFINITE(_current_average_filter_a.getState()) || _current_average_filter_a.getState() < FLT_EPSILON) {
|
if (!PX4_ISFINITE(_current_average_filter_a.getState()) || _current_average_filter_a.getState() < FLT_EPSILON) {
|
||||||
_current_average_filter_a.reset(_params.bat_avrg_current);
|
_current_average_filter_a.reset(_params.bat_avrg_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED && PX4_ISFINITE(current_a)) {
|
if (_armed && PX4_ISFINITE(current_a)) {
|
||||||
// only update with positive numbers
|
// only update with positive numbers
|
||||||
_current_average_filter_a.update(fmaxf(current_a, 0.f));
|
_current_average_filter_a.update(fmaxf(current_a, 0.f));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,4 +170,5 @@ private:
|
|||||||
float _scale{1.f};
|
float _scale{1.f};
|
||||||
uint8_t _warning{battery_status_s::BATTERY_WARNING_NONE};
|
uint8_t _warning{battery_status_s::BATTERY_WARNING_NONE};
|
||||||
hrt_abstime _last_timestamp{0};
|
hrt_abstime _last_timestamp{0};
|
||||||
|
bool _armed{false};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user