43 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(interface->get_device_id())),
44 _interface(interface),
45 _device_type(device_type),
99 PX4_DEBUG(
"probe init failed");
119 while (--tries != 0) {
120 state = px4_enter_critical_section();
138 px4_leave_critical_section(state);
150 state = px4_enter_critical_section();
152 px4_leave_critical_section(state);
206 uint8_t expected = 0;
207 bool unknown_product_id =
true;
229 if (whoami != expected) {
230 PX4_DEBUG(
"unexpected WHOAMI 0x%02x", whoami);
258 unknown_product_id =
false;
265 if (unknown_product_id) {
283 if (desired_sample_rate_hz == 0) {
287 uint8_t div = 1000 / desired_sample_rate_hz;
312 if (frequency_hz == 0) {
315 }
else if (frequency_hz <= 5) {
318 }
else if (frequency_hz <= 10) {
321 }
else if (frequency_hz <= 20) {
324 }
else if (frequency_hz <= 42) {
327 }
else if (frequency_hz <= 98) {
330 }
else if (frequency_hz <= 188) {
333 }
else if (frequency_hz <= 256) {
348 if (frequency_hz == 0) {
351 }
else if (frequency_hz <= 5) {
354 }
else if (frequency_hz <= 10) {
357 }
else if (frequency_hz <= 21) {
360 }
else if (frequency_hz <= 44) {
363 }
else if (frequency_hz <= 99) {
366 }
else if (frequency_hz <= 218) {
369 }
else if (frequency_hz <= 420) {
376 #ifndef CONSTRAINED_FLASH 388 const uint16_t repeats = 100;
395 float accel_baseline[3] {};
396 float gyro_baseline[3] {};
399 float accel_ftrim[3] {};
400 float gyro_ftrim[3] {};
403 for (uint8_t i = 0; i < repeats; i++) {
430 for (uint8_t i = 0; i < repeats; i++) {
443 for (uint8_t i = 0; i < 3; i++) {
444 accel_baseline[i] /= repeats;
445 gyro_baseline[i] /= repeats;
459 atrim[0] = ((trims[0] >> 3) & 0x1C) | ((trims[3] >> 4) & 0x03);
460 atrim[1] = ((trims[1] >> 3) & 0x1C) | ((trims[3] >> 2) & 0x03);
461 atrim[2] = ((trims[2] >> 3) & 0x1C) | ((trims[3] >> 0) & 0x03);
462 gtrim[0] = trims[0] & 0x1F;
463 gtrim[1] = trims[1] & 0x1F;
464 gtrim[2] = trims[2] & 0x1F;
467 for (uint8_t i = 0; i < 3; i++) {
468 accel_ftrim[i] = 4096 * 0.34f * powf(0.92
f / 0.34
f, (atrim[i] - 1) / 30.0
f);
469 gyro_ftrim[i] = 25 * 131.0f * powf(1.046
f, gtrim[i] - 1);
475 for (uint8_t i = 0; i < 3; i++) {
476 float diff = accel[i] - accel_baseline[i];
477 float err = 100 * (diff - accel_ftrim[i]) / accel_ftrim[i];
478 ::printf(
"ACCEL[%u] baseline=%d accel=%d diff=%d ftrim=%d err=%d\n",
480 (
int)(1000 * accel_baseline[i]),
481 (
int)(1000 * accel[i]),
483 (
int)(1000 * accel_ftrim[i]),
486 if (fabsf(err) > 14) {
492 for (uint8_t i = 0; i < 3; i++) {
493 float diff = gyro[i] - gyro_baseline[i];
494 float err = 100 * (diff - gyro_ftrim[i]) / gyro_ftrim[i];
495 ::printf(
"GYRO[%u] baseline=%d gyro=%d diff=%d ftrim=%d err=%d\n",
497 (
int)(1000 * gyro_baseline[i]),
498 (
int)(1000 * gyro[i]),
499 (
int)(1000 * (gyro[i] - gyro_baseline[i])),
500 (
int)(1000 * gyro_ftrim[i]),
503 if (fabsf(err) > 14) {
515 ::printf(
"PASSED\n");
533 PX4_WARN(
"error triggered");
553 return (uint16_t)(buf[0] << 8) | buf[1];
609 }
else if (max_g_in > 4) {
614 }
else if (max_g_in > 2) {
757 (uint8_t *)&mpu_report,
sizeof(mpu_report))) {
780 memcpy(&
_last_accel[0], &mpu_report.accel_x[0], 6);
797 if (report.accel_x == 0 &&
798 report.accel_y == 0 &&
799 report.accel_z == 0 &&
801 report.gyro_x == 0 &&
802 report.gyro_y == 0 &&
803 report.gyro_z == 0) {
827 int16_t accel_xt = report.accel_y;
828 int16_t accel_yt = ((report.accel_x == -32768) ? 32767 : -report.accel_x);
830 int16_t gyro_xt = report.gyro_y;
831 int16_t gyro_yt = ((report.gyro_x == -32768) ? 32767 : -report.gyro_x);
836 report.accel_x = accel_xt;
837 report.accel_y = accel_yt;
838 report.gyro_x = gyro_xt;
839 report.gyro_y = gyro_yt;
865 float temperature = 0.0f;
868 temperature = (report.temp / 326.8f + 25.0f);
871 temperature = (report.temp / 340.0f + 35.0f);
877 _px4_accel.
update(timestamp_sample, report.accel_x, report.accel_y, report.accel_z);
878 _px4_gyro.
update(timestamp_sample, report.gyro_x, report.gyro_y, report.gyro_z);
901 PX4_INFO(
"registers");
905 printf(
"%02x:%02x ", (
unsigned)reg, (
unsigned)v);
#define BIT_INT_ANYRD_2CLEAR
#define ICM_ACC_DLPF_CFG_99HZ
#define MPU_GYRO_DLPF_CFG_98HZ
perf_counter_t _reset_retries
#define MPUREG_INT_STATUS
#define DRV_ACC_DEVTYPE_ICM20608
void write_checked_reg(unsigned reg, uint8_t value)
Write a register in the MPU6000, updating _checked_values.
measure the time elapsed performing an event
#define MPU_GYRO_DLPF_CFG_10HZ
bool is_mpu_device()
is_mpu_device
void update(hrt_abstime timestamp, float x, float y, float z)
#define MPU6000_SET_SPEED(r, s)
int write_reg(unsigned reg, uint8_t value)
Write a register in the MPU6000.
#define ICMREG_ACCEL_CONFIG2
int factory_self_test()
Test behaviour against factory offsets.
#define ICM_ACC_DLPF_CFG_21HZ
#define MPUREG_ICM_UNDOC1_VALUE
#define MPU6000_LOW_BUS_SPEED
int measure()
Fetch measurements from the sensor and update the report buffers.
#define DRV_ACC_DEVTYPE_ICM20689
static constexpr int MPU6000_NUM_CHECKED_REGISTERS
perf_counter_t _sample_perf
bool is_icm_device()
is_icm_device
count the number of times an event occurs
#define MPU_GYRO_DLPF_CFG_42HZ
#define MPU_GYRO_DLPF_CFG_20HZ
void _set_icm_acc_dlpf_filter(uint16_t frequency_hz)
#define MPUREG_PRODUCT_ID
void set_device_type(uint8_t devtype)
static constexpr float CONSTANTS_ONE_G
void set_error_count(uint64_t error_count)
#define MPUREG_ACCEL_CONFIG
#define ICM_ACC_DLPF_CFG_420HZ
#define MPU6000_DEFAULT_ONCHIP_FILTER_FREQ
#define MPUREG_SMPLRT_DIV
PX4Accelerometer _px4_accel
#define DRV_GYR_DEVTYPE_ICM20608
void update(hrt_abstime timestamp, float x, float y, float z)
static constexpr uint8_t _checked_registers[MPU6000_NUM_CHECKED_REGISTERS]
void perf_count(perf_counter_t handle)
Count a performance event.
Report conversation within the mpu, including command byte and interrupt status.
void perf_free(perf_counter_t handle)
Free a counter.
#define ICM_ACC_DLPF_CFG_1046HZ_NOLPF
#define ICM_ACC_DLPF_CFG_5HZ
volatile bool _in_factory_test
#define MPUREG_INT_ENABLE
#define DRV_ACC_DEVTYPE_ICM20602
void set_temperature(float temperature)
#define ICM_ACC_DLPF_CFG_10HZ
perf_counter_t _bad_registers
#define MPUREG_INT_PIN_CFG
#define DRV_ACC_DEVTYPE_MPU6000
#define MPUREG_PWR_MGMT_1
Rotation
Enum for board and external compass rotations.
#define MPU6000_HIGH_BUS_SPEED
#define DRV_GYR_DEVTYPE_MPU6000
#define DRV_GYR_DEVTYPE_ICM20689
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
perf_counter_t _bad_transfers
#define MPU_GYRO_DLPF_CFG_5HZ
#define ICM_ACC_DLPF_CFG_218HZ
void start()
Start automatic measurement.
void set_error_count(uint64_t error_count)
void perf_end(perf_counter_t handle)
End a performance event.
int set_accel_range(unsigned max_g)
Set the MPU6000 measurement range.
#define ICM_ACC_DLPF_CFG_44HZ
#define MPU_GYRO_DLPF_CFG_256HZ_NOLPF2
void modify_reg(unsigned reg, uint8_t clearbits, uint8_t setbits)
Modify a register in the MPU6000.
#define MPU6000_LOW_SPEED_OP(r)
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
virtual int write(unsigned address, void *data, unsigned count)
Write directly to the device.
uint8_t _checked_values[MPU6000_NUM_CHECKED_REGISTERS]
void set_scale(float scale)
#define MPU_CLK_SEL_PLLGYROZ
void check_registers(void)
void set_temperature(float temperature)
#define MPU6000_TIMER_REDUCTION
uint16_t read_reg16(unsigned reg)
perf_counter_t _duplicates
MPU6000(device::Device *interface, enum Rotation rotation, int device_type)
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
Fundamental base class for all physical drivers (I2C, SPI).
#define MPUREG_GYRO_CONFIG
void stop()
Stop automatic measurement.
void print_info()
Diagnostics - print some basic information about the driver.
#define MPU6000_GYRO_DEFAULT_RATE
static constexpr int MPU6000_CHECKED_PRODUCT_ID_INDEX
#define DRV_GYR_DEVTYPE_ICM20602
device::Device * _interface
#define MPU6000_ACCEL_DEFAULT_RANGE_G
int16_t int16_t_from_bytes(uint8_t bytes[])
Converts a signed 16 bit integer from big endian to little endian.
void set_scale(float scale)
DeviceBusType get_device_bus_type() const
Return the bus type the device is connected to.
void set_device_type(uint8_t devtype)
#define MPU_GYRO_DLPF_CFG_2100HZ_NOLPF
#define MPUREG_ICM_UNDOC1
void _set_sample_rate(unsigned desired_sample_rate_hz)
void perf_begin(perf_counter_t handle)
Begin a performance event.
unsigned _call_interval
product code
uint8_t read_reg(unsigned reg, uint32_t speed=MPU6000_LOW_BUS_SPEED)
Read a register from the MPU6000.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
virtual int read(unsigned address, void *data, unsigned count)
Read directly from the device.
#define MPU_GYRO_DLPF_CFG_188HZ
void _set_dlpf_filter(uint16_t frequency_hz)