mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-20 03:13:44 +08:00
[auav] Robustify I2C transfers and enforce minimum sample time
This commit is contained in:
committed by
Niklas Hauser
parent
bd3b3d647f
commit
932abfd558
@@ -65,6 +65,7 @@ AUAV::AUAV(const I2CSPIDriverConfig &config) :
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors"))
|
||||
{
|
||||
I2C::_retries = 5;
|
||||
}
|
||||
|
||||
AUAV::~AUAV()
|
||||
@@ -130,15 +131,21 @@ int AUAV::init()
|
||||
|
||||
int AUAV::probe()
|
||||
{
|
||||
uint8_t res_data = 0;
|
||||
int status = transfer(nullptr, 0, &res_data, sizeof(res_data));
|
||||
uint8_t res_data;
|
||||
|
||||
/* Check that the sensor is active. Reported in bit 6 of the status byte */
|
||||
if ((res_data & 0x40) == 0) {
|
||||
status = PX4_ERROR;
|
||||
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 */
|
||||
if (status == PX4_OK && (res_data & 0x40)) {
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
px4_usleep(10'000);
|
||||
}
|
||||
|
||||
return status;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
void AUAV::handle_state_read_calibdata()
|
||||
|
||||
@@ -51,6 +51,8 @@ static constexpr uint8_t EEPROM_ABS_ES = 0x38;
|
||||
/* Measurement rate is 50Hz */
|
||||
static constexpr unsigned ABS_MEAS_RATE = 50;
|
||||
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 */
|
||||
static constexpr float MBAR_TO_PA = 100.0f;
|
||||
|
||||
@@ -51,6 +51,8 @@ static constexpr uint8_t EEPROM_DIFF_ES = 0x34;
|
||||
/* Measurement rate is 100Hz */
|
||||
static constexpr unsigned DIFF_MEAS_RATE = 100;
|
||||
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 */
|
||||
static constexpr float INH_TO_PA = 249.08f;
|
||||
|
||||
Reference in New Issue
Block a user