mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 19:07:45 +08:00
battery: connected check outside of determineWarning()
This commit is contained in:
@@ -137,8 +137,8 @@ void Battery::updateBatteryStatus(const hrt_abstime ×tamp, 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,23 +239,21 @@ 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 (_state_of_charge < _params.emergen_thr) {
|
if (_battery_status.remaining < _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;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battery::computeScale()
|
void Battery::computeScale()
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void sumDischarged(const hrt_abstime ×tamp, float current_a);
|
void sumDischarged(const hrt_abstime ×tamp, 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)};
|
||||||
|
|||||||
Reference in New Issue
Block a user