IMU Configurationโ
Sequenceโ
Added a step to select the internal 8Mhz oscillator as the clock source
// Set MPU9250 Clock Source to use the X Gyro for reference, which is slightly better than the default internal clock source.
// +-----+-----+-----+-----+-----+-----+-----+-----+
// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// +-----+-----+-----+-----+-----+-----+-----+-----+
// | | | | | | CLKSEL[2:0] |
// +-----+-----+-----+-----+-----+-----+-----+-----+
uint8_t buf[2] = {MPU9250_RA_PWR_MGMT_1, MPU9250_CLOCK_PLL_XGYRO};
i2c_write_blocking(i2c_default, this->i2c_addr, buf, 2, false);
#if defined IMU_VERBOSE_CONFIG
printf("[IMU][CONFIG] wrote %d to MPU9250_RA_PWR_MGMT_1:%d\n", buf[1], MPU9250_RA_PWR_MGMT_1);
#endif
sleep_ms(DELAY_BETWEEN_WR_MS);
Added full scale range sensitivity selection for both accelerometer and gyroscope.
// Set Gyro full scale range
// +-----+-----+-----+-----+-----+-----+-----+-----+
// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// +-----+-----+-----+-----+-----+-----+-----+-----+
// | | | |FS_SEL[1:0]| | | |
// +-----+-----+-----+-----+-----+-----+-----+-----+
buf[0] = MPU9250_GYRO_CONFIG;
buf[1] = (uint8_t)setting.gyro_fs_sel << 3;
i2c_write_blocking(i2c_default, this->i2c_addr, buf, 2, false);
#if defined IMU_VERBOSE_CONFIG
printf("[IMU][CONFIG] wrote %d to MPU9250_GYRO_CONFIG:%d\n", buf[1], MPU9250_GYRO_CONFIG);
#endif
sleep_ms(DELAY_BETWEEN_WR_MS);
// Set Accel full scale range
// +-----+-----+-----+-----+-----+-----+-----+-----+
// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// +-----+-----+-----+-----+-----+-----+-----+-----+
// | | | |AFS_SEL[1:0]| | | |
// +-----+-----+-----+-----+-----+-----+-----+-----+
buf[0] = MPU9250_ACCEL_CONFIG;
buf[1] = (uint8_t)setting.accel_fs_sel << 3;
i2c_write_blocking(i2c_default, this->i2c_addr, buf, 2, false);
#if defined IMU_VERBOSE_CONFIG
printf("[IMU][CONFIG] wrote %d to MPU9250_ACCEL_CONFIG:%d\n", buf[1], MPU9250_ACCEL_CONFIG);
#endif
sleep_ms(DELAY_BETWEEN_WR_MS);
Validating Sequenceโ
[IMU][CONFIG] wrote 1 to MPU9250_RA_PWR_MGMT_1:107
[IMU][CONFIG] wrote 0 to MPU9250_GYRO_CONFIG:27 // GYRO_250DPS
[IMU][CONFIG] wrote 0 to MPU9250_ACCEL_CONFIG:28 // ACCEL_2G
Tasks contd.โ
MPU9250 IMU Driverโ
- Done: Implement full scale range and gyro sensitivity selection, currently using default settings.
- Done: Add hardware reset & calibration sequence
Attitude Estimationโ
- Done: Refactor the existing attitude estimation algorithm with modularity/flexibility in mind.
Defines Usedโ
#define DELAY_BETWEEN_WR_MS 50 // Delay between I2C writes during configuration
#define MPU9250_GYRO_CONFIG 0x1B // Gyro FS_SEL address
#define MPU9250_ACCEL_CONFIG 0x1C // Accel AFS_SEL address
#define MPU9250_CLOCK_PLL_XGYRO 0x01 // Xgyro pll clock
#define MPU9250_RA_PWR_MGMT_1 0x6B // Power management register 1 address