battery: connected check outside of determineWarning()

This commit is contained in:
Matthias Grob
2021-06-25 15:28:29 +02:00
parent e45b862f1d
commit a51d47f8e8
2 changed files with 13 additions and 15 deletions
+12 -14
View File
@@ -137,8 +137,8 @@ void Battery::updateBatteryStatus(const hrt_abstime &timestamp, float voltage_v,
estimateStateOfCharge(_voltage_filter_v.getState(), _current_filter_a.getState(), _throttle_filter.getState()); estimateStateOfCharge(_voltage_filter_v.getState(), _current_filter_a.getState(), _throttle_filter.getState());
computeScale(); computeScale();
if (_battery_initialized) { if (connected && _battery_initialized) {
determineWarning(connected); determineWarning();
} }
if (_voltage_filter_v.getState() > 2.1f) { if (_voltage_filter_v.getState() > 2.1f) {
@@ -239,22 +239,20 @@ void Battery::estimateStateOfCharge(const float voltage_v, const float current_a
} }
} }
void Battery::determineWarning(bool connected) void Battery::determineWarning()
{ {
if (connected) { // propagate warning state only if the state is higher, otherwise remain in current warning state
// propagate warning state only if the state is higher, otherwise remain in current warning state if (_battery_status.remaining < _params.emergen_thr) {
if (_state_of_charge < _params.emergen_thr) { _warning = battery_status_s::BATTERY_WARNING_EMERGENCY;
_warning = battery_status_s::BATTERY_WARNING_EMERGENCY;
} else if (_state_of_charge < _params.crit_thr) { } else if (_battery_status.remaining < _params.crit_thr) {
_warning = battery_status_s::BATTERY_WARNING_CRITICAL; _warning = battery_status_s::BATTERY_WARNING_CRITICAL;
} else if (_state_of_charge < _params.low_thr) { } else if (_battery_status.remaining < _params.low_thr) {
_warning = battery_status_s::BATTERY_WARNING_LOW; _warning = battery_status_s::BATTERY_WARNING_LOW;
} else { } else {
_warning = battery_status_s::BATTERY_WARNING_NONE; _warning = battery_status_s::BATTERY_WARNING_NONE;
}
} }
} }
+1 -1
View File
@@ -197,7 +197,7 @@ protected:
private: private:
void sumDischarged(const hrt_abstime &timestamp, float current_a); void sumDischarged(const hrt_abstime &timestamp, float current_a);
void estimateStateOfCharge(const float voltage_v, const float current_a, const float throttle); void estimateStateOfCharge(const float voltage_v, const float current_a, const float throttle);
void determineWarning(bool connected); void determineWarning();
void computeScale(); void computeScale();
uORB::PublicationMulti<battery_status_s> _battery_status_pub{ORB_ID(battery_status)}; uORB::PublicationMulti<battery_status_s> _battery_status_pub{ORB_ID(battery_status)};