PLANET-Q MPU9250 Library

Dependents:   IZU2020_AVIONICS IZU2020_AVIONICS

Committer:
tanahashi
Date:
Sun Nov 24 04:59:16 2019 +0000
Revision:
3:9042b3662a14
Parent:
2:4f6e30beb2e0
Child:
4:13d220528a23
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tanahashi 0:c5ccb9d0afba 1 #ifndef PQMPU9250_H
tanahashi 0:c5ccb9d0afba 2 #define PQMPU9250_H
tanahashi 0:c5ccb9d0afba 3
tanahashi 0:c5ccb9d0afba 4 #define MPU9250_ADDR_HIGH 0b1101001<<1
tanahashi 0:c5ccb9d0afba 5 #define MPU9250_ADDR_LOW 0b1101000<<1
tanahashi 0:c5ccb9d0afba 6 #define AK8963_ADDR 0b0001100<<1
tanahashi 0:c5ccb9d0afba 7 #define WIA 0x00
tanahashi 0:c5ccb9d0afba 8 #define ST1 0x02
tanahashi 0:c5ccb9d0afba 9 #define HXL 0x03
tanahashi 0:c5ccb9d0afba 10 #define CNTL1 0x0A
tanahashi 0:c5ccb9d0afba 11 #define GYRO_CONFIG 0x1B
tanahashi 0:c5ccb9d0afba 12 #define ACCEL_CONFIG 0x1C
tanahashi 0:c5ccb9d0afba 13 #define INT_PIN_CFG 0x37
tanahashi 0:c5ccb9d0afba 14 #define ACCEL_XOUT_H 0x3B
tanahashi 0:c5ccb9d0afba 15 #define GYRO_XOUT_H 0x43
tanahashi 0:c5ccb9d0afba 16 #define PWR_MGMT_1 0x6B
tanahashi 0:c5ccb9d0afba 17 #define WHO_AM_I 0x75
tanahashi 0:c5ccb9d0afba 18 #define ACCEL_LSB 0.0000610
tanahashi 0:c5ccb9d0afba 19 #define GYRO_LSB 0.00763
tanahashi 0:c5ccb9d0afba 20 #define MAG_LSB 0.150
tanahashi 0:c5ccb9d0afba 21
tanahashi 0:c5ccb9d0afba 22 typedef enum {
tanahashi 0:c5ccb9d0afba 23 AD0_HIGH = MPU9250_ADDR_HIGH,
tanahashi 0:c5ccb9d0afba 24 AD0_LOW = MPU9250_ADDR_LOW
tanahashi 0:c5ccb9d0afba 25 } AD0_t;
tanahashi 0:c5ccb9d0afba 26
tanahashi 0:c5ccb9d0afba 27 typedef enum {
tanahashi 0:c5ccb9d0afba 28 _2G = 0b00000000,
tanahashi 0:c5ccb9d0afba 29 _4G = 0b00001000,
tanahashi 0:c5ccb9d0afba 30 _8G = 0b00010000,
tanahashi 0:c5ccb9d0afba 31 _16G = 0b00011000
tanahashi 0:c5ccb9d0afba 32 } AccelConfig_t;
tanahashi 0:c5ccb9d0afba 33
tanahashi 0:c5ccb9d0afba 34 typedef enum {
tanahashi 0:c5ccb9d0afba 35 _250DPS = 0b00000000,
tanahashi 0:c5ccb9d0afba 36 _500DPS = 0b00001000,
tanahashi 0:c5ccb9d0afba 37 _1000DPS = 0b00010000,
tanahashi 0:c5ccb9d0afba 38 _2000DPS = 0b00011000
tanahashi 0:c5ccb9d0afba 39 } GyroConfig_t;
tanahashi 0:c5ccb9d0afba 40
tanahashi 0:c5ccb9d0afba 41 typedef enum {
tanahashi 0:c5ccb9d0afba 42 _16B_8HZ = 0b00010010,
tanahashi 0:c5ccb9d0afba 43 _16B_100HZ = 0b00010110,
tanahashi 0:c5ccb9d0afba 44 _14B_8HZ = 0b00000010,
tanahashi 0:c5ccb9d0afba 45 _14B_100HZ = 0b00000100
tanahashi 0:c5ccb9d0afba 46 } MagConfig_t;
tanahashi 0:c5ccb9d0afba 47
tanahashi 3:9042b3662a14 48 /** MPU9250
tanahashi 3:9042b3662a14 49 * 9軸センサMPU9250のライブラリ
tanahashi 3:9042b3662a14 50 */
tanahashi 0:c5ccb9d0afba 51 class MPU9250
tanahashi 0:c5ccb9d0afba 52 {
tanahashi 0:c5ccb9d0afba 53 private:
tanahashi 0:c5ccb9d0afba 54 char cmd[2];
tanahashi 0:c5ccb9d0afba 55 char buff[8];
tanahashi 0:c5ccb9d0afba 56 public:
tanahashi 0:c5ccb9d0afba 57 I2C *_i2c;
tanahashi 0:c5ccb9d0afba 58 int _addr;
tanahashi 0:c5ccb9d0afba 59 float accel_LSB;
tanahashi 0:c5ccb9d0afba 60 float gyro_LSB;
tanahashi 0:c5ccb9d0afba 61 float mag_LSB;
tanahashi 0:c5ccb9d0afba 62 float accel_offset[3];
tanahashi 0:c5ccb9d0afba 63 float gyro_offset[3];
tanahashi 0:c5ccb9d0afba 64 float mag_offset[3];
tanahashi 0:c5ccb9d0afba 65 public:
tanahashi 0:c5ccb9d0afba 66 /**
tanahashi 0:c5ccb9d0afba 67 * コンストラクタ
tanahashi 0:c5ccb9d0afba 68 * @param i2c I2Cのインスタンスへの参照
tanahashi 0:c5ccb9d0afba 69 * @param AD0 AD0ピンのH/Lレベル
tanahashi 0:c5ccb9d0afba 70 */
tanahashi 0:c5ccb9d0afba 71 MPU9250(I2C &i2c, AD0_t AD0);
tanahashi 0:c5ccb9d0afba 72
tanahashi 0:c5ccb9d0afba 73 /**
tanahashi 0:c5ccb9d0afba 74 * センサ動作開始
tanahashi 0:c5ccb9d0afba 75 */
tanahashi 0:c5ccb9d0afba 76 void begin();
tanahashi 0:c5ccb9d0afba 77
tanahashi 0:c5ccb9d0afba 78 /**
tanahashi 0:c5ccb9d0afba 79 * センサ通信テスト
tanahashi 0:c5ccb9d0afba 80 * @return 通信成功の時true
tanahashi 0:c5ccb9d0afba 81 */
tanahashi 0:c5ccb9d0afba 82 bool test();
tanahashi 0:c5ccb9d0afba 83
tanahashi 0:c5ccb9d0afba 84 bool test_AK8963();
tanahashi 0:c5ccb9d0afba 85
tanahashi 0:c5ccb9d0afba 86 /**
tanahashi 0:c5ccb9d0afba 87 * センサ設定
tanahashi 0:c5ccb9d0afba 88 * @param accel_config 加速度の測定レンジ
tanahashi 0:c5ccb9d0afba 89 * @param gyro_config 角速度の測定レンジ
tanahashi 0:c5ccb9d0afba 90 * @param mag_config 地磁気センサの設定
tanahashi 0:c5ccb9d0afba 91 */
tanahashi 0:c5ccb9d0afba 92 void set(AccelConfig_t accel_config, GyroConfig_t gyro_config, MagConfig_t mag_config);
tanahashi 0:c5ccb9d0afba 93
tanahashi 0:c5ccb9d0afba 94 /**
tanahashi 0:c5ccb9d0afba 95 * 加速度センサ設定
tanahashi 0:c5ccb9d0afba 96 * @param accel_config 角速度センサの測定レンジ
tanahashi 0:c5ccb9d0afba 97 *
tanahashi 0:c5ccb9d0afba 98 */
tanahashi 0:c5ccb9d0afba 99
tanahashi 0:c5ccb9d0afba 100 void set_accel(AccelConfig_t accel_config);
tanahashi 0:c5ccb9d0afba 101 void set_gyro(GyroConfig_t gyro_config);
tanahashi 0:c5ccb9d0afba 102 void set_mag(MagConfig_t mag_config);
tanahashi 0:c5ccb9d0afba 103 void offset(float *accel, float *gyro, float *mag);
tanahashi 0:c5ccb9d0afba 104 void offset_accel(float *accel);
tanahashi 0:c5ccb9d0afba 105 void offset_gyro(float *gyro);
tanahashi 0:c5ccb9d0afba 106 void offset_mag(float *mag);
tanahashi 0:c5ccb9d0afba 107 void read(float *accel, float *gyro, float *mag);
tanahashi 0:c5ccb9d0afba 108 void read_accel(float *accel);
tanahashi 0:c5ccb9d0afba 109 void read_gyro(float *gyro);
tanahashi 0:c5ccb9d0afba 110 void read_mag(float *mag);
tanahashi 0:c5ccb9d0afba 111 };
tanahashi 0:c5ccb9d0afba 112
tanahashi 0:c5ccb9d0afba 113 #endif