mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-20 11:23:06 +08:00
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:
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user