mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-09 22:08:56 +08:00
feat(ina2xx): count ignored zero readings with perf counter
EKF Update Change Indicator / unit_tests (push) Has been cancelled
EKF Update Change Indicator / unit_tests (push) Has been cancelled
This commit is contained in:
@@ -51,6 +51,7 @@ INA220::INA220(const I2CSPIDriverConfig &config, int battery_index) :
|
||||
_comms_errors(perf_alloc(PC_COUNT, "ina220_com_err")),
|
||||
_collection_errors(perf_alloc(PC_COUNT, "ina220_collection_err")),
|
||||
_measure_errors(perf_alloc(PC_COUNT, "ina220_measurement_err")),
|
||||
_zero_reading_perf(perf_alloc(PC_COUNT, "ina220_zero_reading")),
|
||||
_ch_type((PM_CH_TYPE)config.custom2),
|
||||
_battery(battery_index, this, INA220_SAMPLE_INTERVAL_US, battery_status_s::SOURCE_POWER_MODULE)
|
||||
{
|
||||
@@ -105,6 +106,7 @@ INA220::~INA220()
|
||||
perf_free(_comms_errors);
|
||||
perf_free(_collection_errors);
|
||||
perf_free(_measure_errors);
|
||||
perf_free(_zero_reading_perf);
|
||||
}
|
||||
|
||||
int INA220::read(uint8_t address, int16_t &data)
|
||||
@@ -253,6 +255,8 @@ INA220::collect()
|
||||
// exactly 0 is very improbable, we just ignore those readings.
|
||||
// The battery library keeps the old value.
|
||||
|
||||
if (!_bus_voltage || !_bus_current) { perf_count(_zero_reading_perf); }
|
||||
|
||||
if (_bus_voltage) { _battery.updateVoltage(_voltage); }
|
||||
|
||||
if (_bus_current) { _battery.updateCurrent(_current); }
|
||||
@@ -354,6 +358,7 @@ INA220::print_status()
|
||||
if (_initialized) {
|
||||
perf_print_counter(_sample_perf);
|
||||
perf_print_counter(_comms_errors);
|
||||
perf_print_counter(_zero_reading_perf);
|
||||
|
||||
switch (_ch_type) {
|
||||
case PM_CH_TYPE_VBATT:
|
||||
|
||||
@@ -180,6 +180,7 @@ private:
|
||||
perf_counter_t _comms_errors;
|
||||
perf_counter_t _collection_errors;
|
||||
perf_counter_t _measure_errors;
|
||||
perf_counter_t _zero_reading_perf;
|
||||
|
||||
int16_t _bus_voltage{0};
|
||||
int16_t _bus_power{0};
|
||||
|
||||
@@ -49,6 +49,7 @@ INA226::INA226(const I2CSPIDriverConfig &config, int battery_index) :
|
||||
_comms_errors(perf_alloc(PC_COUNT, "ina226_com_err")),
|
||||
_collection_errors(perf_alloc(PC_COUNT, "ina226_collection_err")),
|
||||
_measure_errors(perf_alloc(PC_COUNT, "ina226_measurement_err")),
|
||||
_zero_reading_perf(perf_alloc(PC_COUNT, "ina226_zero_reading")),
|
||||
_battery(battery_index, this, INA226_SAMPLE_INTERVAL_US, battery_status_s::SOURCE_POWER_MODULE)
|
||||
{
|
||||
float fvalue = MAX_CURRENT;
|
||||
@@ -96,6 +97,7 @@ INA226::~INA226()
|
||||
perf_free(_comms_errors);
|
||||
perf_free(_collection_errors);
|
||||
perf_free(_measure_errors);
|
||||
perf_free(_zero_reading_perf);
|
||||
}
|
||||
|
||||
int INA226::read(uint8_t address, int16_t &data)
|
||||
@@ -233,6 +235,8 @@ INA226::collect()
|
||||
// exactly 0 is very improbable, we just ignore those readings.
|
||||
// The battery library keeps the old value.
|
||||
|
||||
if (!_bus_voltage || !_current) { perf_count(_zero_reading_perf); }
|
||||
|
||||
if (_bus_voltage) { _battery.updateVoltage(static_cast<float>(_bus_voltage * INA226_VSCALE)); }
|
||||
|
||||
if (_current) { _battery.updateCurrent(static_cast<float>(_current * _current_lsb)); }
|
||||
@@ -341,6 +345,7 @@ INA226::print_status()
|
||||
if (_initialized) {
|
||||
perf_print_counter(_sample_perf);
|
||||
perf_print_counter(_comms_errors);
|
||||
perf_print_counter(_zero_reading_perf);
|
||||
|
||||
printf("poll interval: %u \n", _measure_interval);
|
||||
|
||||
|
||||
@@ -186,6 +186,7 @@ private:
|
||||
perf_counter_t _comms_errors;
|
||||
perf_counter_t _collection_errors;
|
||||
perf_counter_t _measure_errors;
|
||||
perf_counter_t _zero_reading_perf;
|
||||
|
||||
int16_t _bus_voltage{0};
|
||||
int16_t _power{0};
|
||||
|
||||
@@ -49,6 +49,7 @@ INA228::INA228(const I2CSPIDriverConfig &config, int battery_index) :
|
||||
_comms_errors(perf_alloc(PC_COUNT, "ina228_com_err")),
|
||||
_collection_errors(perf_alloc(PC_COUNT, "ina228_collection_err")),
|
||||
_measure_errors(perf_alloc(PC_COUNT, "ina228_measurement_err")),
|
||||
_zero_reading_perf(perf_alloc(PC_COUNT, "ina228_zero_reading")),
|
||||
_battery(battery_index, this, INA228_SAMPLE_INTERVAL_US, battery_status_s::SOURCE_POWER_MODULE)
|
||||
{
|
||||
float fvalue = MAX_CURRENT;
|
||||
@@ -111,6 +112,7 @@ INA228::~INA228()
|
||||
perf_free(_comms_errors);
|
||||
perf_free(_collection_errors);
|
||||
perf_free(_measure_errors);
|
||||
perf_free(_zero_reading_perf);
|
||||
}
|
||||
|
||||
int INA228::read(uint8_t address, int16_t &data)
|
||||
@@ -328,6 +330,8 @@ INA228::collect()
|
||||
// exactly 0 is very improbable, we just ignore those readings.
|
||||
// The battery library keeps the old value.
|
||||
|
||||
if (!_bus_voltage || !_current || !_temperature) { perf_count(_zero_reading_perf); }
|
||||
|
||||
if (_bus_voltage) { _battery.updateVoltage(static_cast<float>(_bus_voltage * INA228_VSCALE)); }
|
||||
|
||||
if (_current) { _battery.updateCurrent(static_cast<float>(_current * _current_lsb)); }
|
||||
@@ -438,6 +442,7 @@ INA228::print_status()
|
||||
if (_initialized) {
|
||||
perf_print_counter(_sample_perf);
|
||||
perf_print_counter(_comms_errors);
|
||||
perf_print_counter(_zero_reading_perf);
|
||||
|
||||
printf("poll interval: %u \n", _measure_interval);
|
||||
|
||||
|
||||
@@ -338,6 +338,7 @@ private:
|
||||
perf_counter_t _comms_errors;
|
||||
perf_counter_t _collection_errors;
|
||||
perf_counter_t _measure_errors;
|
||||
perf_counter_t _zero_reading_perf;
|
||||
|
||||
int32_t _bus_voltage{0};
|
||||
int64_t _power{0};
|
||||
|
||||
@@ -102,6 +102,7 @@ INA238::~INA238()
|
||||
perf_free(_sample_perf);
|
||||
perf_free(_comms_errors);
|
||||
perf_free(_collection_errors);
|
||||
perf_free(_zero_reading_perf);
|
||||
}
|
||||
|
||||
int INA238::read(uint8_t address, uint16_t &data)
|
||||
@@ -257,6 +258,8 @@ int INA238::collect()
|
||||
// exactly 0 is very improbable, we just ignore those readings.
|
||||
// The battery library keeps the old value.
|
||||
|
||||
if (!bus_voltage || !current || !temperature) { perf_count(_zero_reading_perf); }
|
||||
|
||||
if (bus_voltage) { _battery.updateVoltage(static_cast<float>(bus_voltage * INA238_VSCALE)); }
|
||||
|
||||
if (current) { _battery.updateCurrent(static_cast<float>(current * _current_lsb)); }
|
||||
@@ -382,6 +385,7 @@ void INA238::print_status()
|
||||
if (_initialized) {
|
||||
perf_print_counter(_sample_perf);
|
||||
perf_print_counter(_comms_errors);
|
||||
perf_print_counter(_zero_reading_perf);
|
||||
|
||||
printf("poll interval: %u \n", _measure_interval);
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ private:
|
||||
perf_counter_t _comms_errors;
|
||||
perf_counter_t _collection_errors;
|
||||
perf_counter_t _bad_register_perf{perf_alloc(PC_COUNT, MODULE_NAME": bad register")};
|
||||
perf_counter_t _zero_reading_perf{perf_alloc(PC_COUNT, MODULE_NAME": zero reading")};
|
||||
|
||||
// Configuration state, computed from params
|
||||
float _max_current;
|
||||
|
||||
Reference in New Issue
Block a user