fix(ina2xx): Reject exact zero readings

INA220 special case: only reject zero readings when output goes to
battery library, which if not updated just keeps the previous value.
When output goes to power_monitor uOrb message, publish zero readings as
well, as we do not have the option of publishing only a subset of
readings.
This commit is contained in:
Balduin
2026-04-09 14:04:13 +02:00
parent 44c128aade
commit 7c5cdf0ed7
4 changed files with 40 additions and 9 deletions
+10 -2
View File
@@ -247,8 +247,16 @@ INA220::collect()
switch (_ch_type) {
case PM_CH_TYPE_VBATT: {
_battery.setConnected(success);
_battery.updateVoltage(_voltage);
_battery.updateCurrent(_current);
// Sometimes the read operation "succeeds" but results in wrong
// zero readings. Given that with noise a true reading of
// exactly 0 is very improbable, we just ignore those readings.
// The battery library keeps the old value.
if (_bus_voltage) { _battery.updateVoltage(_voltage); }
if (_bus_current) { _battery.updateCurrent(_current); }
_battery.updateAndPublishBatteryStatus(hrt_absolute_time());
}
break;
+9 -2
View File
@@ -227,8 +227,15 @@ INA226::collect()
// success = success && (read(INA226_REG_SHUNTVOLTAGE, _shunt) == PX4_OK);
if (setConnected(success)) {
_battery.updateVoltage(static_cast<float>(_bus_voltage * INA226_VSCALE));
_battery.updateCurrent(static_cast<float>(_current * _current_lsb));
// Sometimes the read operation "succeeds" but results in wrong
// zero readings. Given that with noise a true reading of
// exactly 0 is very improbable, we just ignore those readings.
// The battery library keeps the old value.
if (_bus_voltage) { _battery.updateVoltage(static_cast<float>(_bus_voltage * INA226_VSCALE)); }
if (_current) { _battery.updateCurrent(static_cast<float>(_current * _current_lsb)); }
}
_battery.updateAndPublishBatteryStatus(hrt_absolute_time());
+10 -2
View File
@@ -322,8 +322,16 @@ INA228::collect()
success = success && (read(INA228_REG_DIETEMP, _temperature) == PX4_OK);
if (setConnected(success)) {
_battery.updateVoltage(static_cast<float>(_bus_voltage * INA228_VSCALE));
_battery.updateCurrent(static_cast<float>(_current * _current_lsb));
// Sometimes the read operation "succeeds" but results in wrong
// zero readings. Given that with noise a true reading of
// exactly 0 is very improbable, we just ignore those readings.
// The battery library keeps the old value.
if (_bus_voltage) { _battery.updateVoltage(static_cast<float>(_bus_voltage * INA228_VSCALE)); }
if (_current) { _battery.updateCurrent(static_cast<float>(_current * _current_lsb)); }
_battery.updateTemperature(static_cast<float>(_temperature * INA228_TSCALE));
}
+11 -3
View File
@@ -251,9 +251,17 @@ int INA238::collect()
success = success && (RegisterRead(Register::DIETEMP, (uint16_t &)temperature) == PX4_OK);
if (setConnected(success)) {
_battery.updateVoltage(static_cast<float>(bus_voltage * INA238_VSCALE));
_battery.updateCurrent(static_cast<float>(current * _current_lsb));
_battery.updateTemperature(static_cast<float>(temperature * INA238_TSCALE));
// Sometimes the read operation "succeeds" but results in wrong
// zero readings. Given that with noise a true reading of
// exactly 0 is very improbable, we just ignore those readings.
// The battery library keeps the old value.
if (bus_voltage) { _battery.updateVoltage(static_cast<float>(bus_voltage * INA238_VSCALE)); }
if (current) { _battery.updateCurrent(static_cast<float>(current * _current_lsb)); }
if (temperature) { _battery.updateTemperature(static_cast<float>(temperature * INA238_TSCALE)); }
_battery.updateAndPublishBatteryStatus(hrt_absolute_time());
}