[auav] Robustify I2C transfers and enforce minimum sample time

This commit is contained in:
Niklas Hauser
2025-11-25 17:09:52 +01:00
committed by Niklas Hauser
parent bd3b3d647f
commit 932abfd558
3 changed files with 17 additions and 6 deletions
@@ -65,6 +65,7 @@ AUAV::AUAV(const I2CSPIDriverConfig &config) :
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")), _sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors")) _comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors"))
{ {
I2C::_retries = 5;
} }
AUAV::~AUAV() AUAV::~AUAV()
@@ -130,15 +131,21 @@ int AUAV::init()
int AUAV::probe() int AUAV::probe()
{ {
uint8_t res_data = 0; uint8_t res_data;
int status = transfer(nullptr, 0, &res_data, sizeof(res_data));
for (unsigned i = 0; i < 10; i++) {
res_data = 0;
int status = transfer(nullptr, 0, &res_data, 1);
/* Check that the sensor is active. Reported in bit 6 of the status byte */ /* Check that the sensor is active. Reported in bit 6 of the status byte */
if ((res_data & 0x40) == 0) { if (status == PX4_OK && (res_data & 0x40)) {
status = PX4_ERROR; return PX4_OK;
} }
return status; px4_usleep(10'000);
}
return PX4_ERROR;
} }
void AUAV::handle_state_read_calibdata() void AUAV::handle_state_read_calibdata()
@@ -51,6 +51,8 @@ static constexpr uint8_t EEPROM_ABS_ES = 0x38;
/* Measurement rate is 50Hz */ /* Measurement rate is 50Hz */
static constexpr unsigned ABS_MEAS_RATE = 50; static constexpr unsigned ABS_MEAS_RATE = 50;
static constexpr int64_t ABS_CONVERSION_INTERVAL = (1000000 / ABS_MEAS_RATE); /* microseconds */ static constexpr int64_t ABS_CONVERSION_INTERVAL = (1000000 / ABS_MEAS_RATE); /* microseconds */
/* reading too fast can yield all zero data -> incorrect sensor reading */
static_assert(ABS_CONVERSION_INTERVAL >= 7000, "Conversion interval is too fast");
/* Conversions */ /* Conversions */
static constexpr float MBAR_TO_PA = 100.0f; static constexpr float MBAR_TO_PA = 100.0f;
@@ -51,6 +51,8 @@ static constexpr uint8_t EEPROM_DIFF_ES = 0x34;
/* Measurement rate is 100Hz */ /* Measurement rate is 100Hz */
static constexpr unsigned DIFF_MEAS_RATE = 100; static constexpr unsigned DIFF_MEAS_RATE = 100;
static constexpr int64_t DIFF_CONVERSION_INTERVAL = (1000000 / DIFF_MEAS_RATE); /* microseconds */ static constexpr int64_t DIFF_CONVERSION_INTERVAL = (1000000 / DIFF_MEAS_RATE); /* microseconds */
/* reading too fast can yield all zero data -> incorrect sensor reading */
static_assert(DIFF_CONVERSION_INTERVAL >= 7000, "Conversion interval is too fast");
/* Conversions */ /* Conversions */
static constexpr float INH_TO_PA = 249.08f; static constexpr float INH_TO_PA = 249.08f;