mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-29 03:30:48 +08:00
fix(battery): improve voltage check for battery connection status (#29439)
This commit is contained in:
1 parent
6832906c46
commit
b4da2c3d26
4 files changed
+23
-5
No files matched your search
@@ -331,6 +331,11 @@ void
|
||||
UavcanBatteryBridge::filterData(const uavcan::ReceivedDataStructure<uavcan::equipment::power::BatteryInfo> &msg,
|
||||
uint8_t instance)
|
||||
{
|
||||
// Skip a non-finite voltage sample
|
||||
if (!PX4_ISFINITE(msg.voltage)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_battery[instance]->setConnected(true);
|
||||
_battery[instance]->updateVoltage(msg.voltage);
|
||||
_battery[instance]->updateCurrent(msg.current);
|
||||
|
||||
@@ -101,7 +101,12 @@ Battery::Battery(int index, ModuleParams *parent, const int sample_interval_us,
|
||||
|
||||
void Battery::updateVoltage(const float voltage_v)
|
||||
{
|
||||
_voltage_v = voltage_v;
|
||||
// Skip a non-finite sample and keep the last valid voltage
|
||||
_voltage_valid = PX4_ISFINITE(voltage_v);
|
||||
|
||||
if (_voltage_valid) {
|
||||
_voltage_v = voltage_v;
|
||||
}
|
||||
}
|
||||
|
||||
void Battery::updateCurrent(const float current_a)
|
||||
@@ -111,7 +116,8 @@ void Battery::updateCurrent(const float current_a)
|
||||
_current_a = _params.i_overwrite;
|
||||
|
||||
} else {
|
||||
_current_a = current_a;
|
||||
// -1 is the invalid value, a non-finite current would corrupt the discharge count and the filters
|
||||
_current_a = PX4_ISFINITE(current_a) ? current_a : -1.f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +213,10 @@ void Battery::publishBatteryStatus(const battery_status_s &battery_status)
|
||||
|
||||
void Battery::updateAndPublishBatteryStatus(const hrt_abstime ×tamp)
|
||||
{
|
||||
if (!_voltage_valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateBatteryStatus(timestamp);
|
||||
|
||||
battery_status_s battery_status = getBatteryStatus();
|
||||
@@ -240,7 +250,7 @@ void Battery::updateDt(const hrt_abstime ×tamp)
|
||||
|
||||
float Battery::sumDischarged(float current_a)
|
||||
{
|
||||
if (_dt_discharge > FLT_EPSILON && fabsf(current_a + 1.f) > FLT_EPSILON) {
|
||||
if (_dt_discharge > FLT_EPSILON && PX4_ISFINITE(current_a) && fabsf(current_a + 1.f) > FLT_EPSILON) {
|
||||
// mAh since last loop: (current[A] * 1000 = [mA]) * (dt[s] / 3600 = [h])
|
||||
// current = -1 means invalid current measurement
|
||||
_discharged_mah_loop = (current_a * 1e3f) * (_dt_discharge / 3600.f);
|
||||
@@ -406,7 +416,7 @@ float Battery::computeRemainingTime(float current_a)
|
||||
|
||||
_vehicle_status_was_fw = _vehicle_status_is_fw;
|
||||
|
||||
if (_armed && PX4_ISFINITE(current_a)) {
|
||||
if (_armed && PX4_ISFINITE(current_a) && fabsf(current_a + 1.f) > FLT_EPSILON) {
|
||||
// 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)) {
|
||||
|
||||
@@ -189,6 +189,7 @@ private:
|
||||
uint8_t _priority{0};
|
||||
bool _battery_initialized{false};
|
||||
float _voltage_v{0.f};
|
||||
bool _voltage_valid{true};
|
||||
AlphaFilter<float> _ocv_filter_v;
|
||||
AlphaFilter<float> _cell_voltage_filter_v;
|
||||
float _current_a{-1};
|
||||
|
||||
@@ -86,7 +86,9 @@ EscBattery::Run()
|
||||
|
||||
if (_esc_status_sub.copy(&esc_status)) {
|
||||
|
||||
if (esc_status.esc_count == 0 || esc_status.esc_count > esc_status_s::CONNECTED_ESC_MAX) {
|
||||
// Nothing to average: invalid ESC count or no ESC online
|
||||
if (esc_status.esc_count == 0 || esc_status.esc_count > esc_status_s::CONNECTED_ESC_MAX
|
||||
|| esc_status.esc_online_flags == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user