ICM20948+madgwickフィルター 地磁気は不使用で6軸のみ使用 最初5s静置してジャイロのオフセットを求めキャリブレーション 地磁気を測らないためヨー軸ドリフトがあるが,緩やかに動かせば2,3分程度はヨー軸も正しい値を測定できた

Dependencies:   mbed MadgwickFilter

Committer:
hiramitsu
Date:
Mon Oct 18 13:41:49 2021 +0000
Revision:
0:ce9707156696
ICM20948 (use acce and gyro, omit mag)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hiramitsu 0:ce9707156696 1 #ifndef ICM20948_HPP
hiramitsu 0:ce9707156696 2 #define ICM20948_HPP
hiramitsu 0:ce9707156696 3
hiramitsu 0:ce9707156696 4
hiramitsu 0:ce9707156696 5 // USER BANK 0
hiramitsu 0:ce9707156696 6 #define ICM20948_WHO_AM_I 0x00 // Should return 0xEA
hiramitsu 0:ce9707156696 7 #define ICM20948_PWR_MGMT_1 0x06 // Device defaults to the SLEEP mode
hiramitsu 0:ce9707156696 8 #define ICM20948_PWR_MGMT_2 0x07
hiramitsu 0:ce9707156696 9 #define ICM20948_ACCEL_XOUT_H 0x2D
hiramitsu 0:ce9707156696 10 #define ICM20948_ACCEL_XOUT_L 0x2E
hiramitsu 0:ce9707156696 11 #define ICM20948_ACCEL_YOUT_H 0x2F
hiramitsu 0:ce9707156696 12 #define ICM20948_ACCEL_YOUT_L 0x30
hiramitsu 0:ce9707156696 13 #define ICM20948_ACCEL_ZOUT_H 0x31
hiramitsu 0:ce9707156696 14 #define ICM20948_ACCEL_ZOUT_L 0x32
hiramitsu 0:ce9707156696 15 #define ICM20948_GYRO_XOUT_H 0x33
hiramitsu 0:ce9707156696 16 #define ICM20948_GYRO_XOUT_L 0x34
hiramitsu 0:ce9707156696 17 #define ICM20948_GYRO_YOUT_H 0x35
hiramitsu 0:ce9707156696 18 #define ICM20948_GYRO_YOUT_L 0x36
hiramitsu 0:ce9707156696 19 #define ICM20948_GYRO_ZOUT_H 0x37
hiramitsu 0:ce9707156696 20 #define ICM20948_GYRO_ZOUT_L 0x38
hiramitsu 0:ce9707156696 21 #define ICM20948_TEMP_OUT_H 0x39
hiramitsu 0:ce9707156696 22 #define ICM20948_TEMP_OUT_L 0x3A
hiramitsu 0:ce9707156696 23
hiramitsu 0:ce9707156696 24 // USER BANK 2
hiramitsu 0:ce9707156696 25 #define ICM20948_GYRO_SMPLRT_DIV 0x00
hiramitsu 0:ce9707156696 26 #define ICM20948_GYRO_CONFIG_1 0x01
hiramitsu 0:ce9707156696 27 #define ICM20948_ACCEL_SMPLRT_DIV_2 0x11
hiramitsu 0:ce9707156696 28 #define ICM20948_ACCEL_CONFIG 0x14
hiramitsu 0:ce9707156696 29
hiramitsu 0:ce9707156696 30 // COMMON
hiramitsu 0:ce9707156696 31 #define ICM20948_REG_BANK_SEL 0x7F
hiramitsu 0:ce9707156696 32
hiramitsu 0:ce9707156696 33 // OTHER
hiramitsu 0:ce9707156696 34 #define USER_BANK_0 0x00
hiramitsu 0:ce9707156696 35 #define USER_BANK_1 0x10
hiramitsu 0:ce9707156696 36 #define USER_BANK_2 0x20
hiramitsu 0:ce9707156696 37 #define USER_BANK_3 0x30
hiramitsu 0:ce9707156696 38
hiramitsu 0:ce9707156696 39 // ジャイロのレンジは2:1bitの値に相当
hiramitsu 0:ce9707156696 40 // ジャイロのモジュール内ローパスフィルタは5:3,0bitに相当
hiramitsu 0:ce9707156696 41 #define GYRO_RATE_250 0x00
hiramitsu 0:ce9707156696 42 #define GYRO_RATE_500 0x02
hiramitsu 0:ce9707156696 43 #define GYRO_RATE_1000 0x04
hiramitsu 0:ce9707156696 44 #define GYRO_RATE_2000 0x06
hiramitsu 0:ce9707156696 45 #define GYRO_LPF_OFF 0x00
hiramitsu 0:ce9707156696 46 #define GYRO_LPF_230Hz 0x01
hiramitsu 0:ce9707156696 47 #define GYRO_LPF_17Hz 0x29
hiramitsu 0:ce9707156696 48 #define GYRO_SMPLRT_100Hz 0x0A
hiramitsu 0:ce9707156696 49
hiramitsu 0:ce9707156696 50 // 加速度のレンジは2:1bitの値に相当
hiramitsu 0:ce9707156696 51 // 加速度のモジュール内ローパスフィルタは5:3,0bitに相当
hiramitsu 0:ce9707156696 52 #define ACC_RATE_2g 0x00
hiramitsu 0:ce9707156696 53 #define ACC_RATE_4g 0x02
hiramitsu 0:ce9707156696 54 #define ACC_RATE_8g 0x04
hiramitsu 0:ce9707156696 55 #define ACC_RATE_16g 0x06
hiramitsu 0:ce9707156696 56 #define ACC_LPF_OFF 0x00
hiramitsu 0:ce9707156696 57 #define ACC_LPF_136HZ 0x11
hiramitsu 0:ce9707156696 58 #define ACC_SMPLRT_100Hz 0x0A
hiramitsu 0:ce9707156696 59
hiramitsu 0:ce9707156696 60
hiramitsu 0:ce9707156696 61
hiramitsu 0:ce9707156696 62
hiramitsu 0:ce9707156696 63 // Using the GY-521 breakout board, I set ADO to 0 by grounding through a 4k7 resistor
hiramitsu 0:ce9707156696 64 // Seven-bit device address is 110100 for ADO = 0 and 110101 for ADO = 1
hiramitsu 0:ce9707156696 65 #define ADO 0
hiramitsu 0:ce9707156696 66 #if ADO
hiramitsu 0:ce9707156696 67 #define ICM20948_slave_addr 0x69<<1 // Device address when ADO = 1
hiramitsu 0:ce9707156696 68 #else
hiramitsu 0:ce9707156696 69 #define ICM20948_slave_addr 0x68<<1 // Device address when ADO = 0
hiramitsu 0:ce9707156696 70 #endif
hiramitsu 0:ce9707156696 71
hiramitsu 0:ce9707156696 72 #define IMU_ONE_G 9.80665
hiramitsu 0:ce9707156696 73 //#define ICM20948_slave_addr 0xD0
hiramitsu 0:ce9707156696 74 extern float aRes, gRes;
hiramitsu 0:ce9707156696 75 extern Serial pc;
hiramitsu 0:ce9707156696 76
hiramitsu 0:ce9707156696 77 class ICM20948 {
hiramitsu 0:ce9707156696 78 public:
hiramitsu 0:ce9707156696 79 ICM20948();
hiramitsu 0:ce9707156696 80 ~ICM20948();
hiramitsu 0:ce9707156696 81
hiramitsu 0:ce9707156696 82 void ICM_WriteByte(uint8_t ICM20948_reg, uint8_t ICM20948_data);
hiramitsu 0:ce9707156696 83 uint8_t ICM_ReadByte(uint8_t ICM20948_reg);
hiramitsu 0:ce9707156696 84 void whoAmI();
hiramitsu 0:ce9707156696 85 void powerOn();
hiramitsu 0:ce9707156696 86 void init();
hiramitsu 0:ce9707156696 87 void gyroCalib();
hiramitsu 0:ce9707156696 88 void getAccGyro(float acc[3], float gyro[3]);
hiramitsu 0:ce9707156696 89 int16_t getIMUTemp();
hiramitsu 0:ce9707156696 90 private:
hiramitsu 0:ce9707156696 91 float aRes, gRes;
hiramitsu 0:ce9707156696 92 float gyroBias[3];
hiramitsu 0:ce9707156696 93 };
hiramitsu 0:ce9707156696 94
hiramitsu 0:ce9707156696 95 #endif