Battery: delay initialization of SoC (#20729)

* Battery: delay initialization of SoC

* battery: rework of battery initialization delay

Co-authored-by: Matthias Grob <maetugr@gmail.com>
This commit is contained in:
Yannick Fuhrer 2022-12-26 18:44:22 +01:00 committed by GitHub
parent 54d825730e
commit 98529a5b49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -118,6 +118,18 @@ void Battery::updateBatteryStatus(const hrt_abstime &timestamp)
_current_filter_a.reset(_current_a);
}
// Require minimum voltage toherwise override connected status
if (_voltage_filter_v.getState() < 2.1f) {
_connected = false;
}
if (!_connected || (_last_unconnected_timestamp == 0)) {
_last_unconnected_timestamp = timestamp;
}
// wait with initializing filters to avoid relying on a voltage sample from the rising edge
_battery_initialized = _connected && (timestamp > _last_unconnected_timestamp + 2_s);
sumDischarged(timestamp, _current_a);
_state_of_charge_volt_based =
calculateStateOfChargeVoltageBased(_voltage_filter_v.getState(), _current_filter_a.getState());
@ -131,13 +143,6 @@ void Battery::updateBatteryStatus(const hrt_abstime &timestamp)
if (_connected && _battery_initialized) {
_warning = determineWarning(_state_of_charge);
}
if (_voltage_filter_v.getState() > 2.1f) {
_battery_initialized = true;
} else {
_connected = false;
}
}
battery_status_s Battery::getBatteryStatus()

View File

@ -175,4 +175,5 @@ private:
uint8_t _warning{battery_status_s::BATTERY_WARNING_NONE};
hrt_abstime _last_timestamp{0};
bool _armed{false};
hrt_abstime _last_unconnected_timestamp{0};
};