PLANET-Q MPU9250 Library

Dependents:   IZU2020_AVIONICS IZU2020_AVIONICS

Committer:
tanahashi
Date:
Sun Nov 24 04:30:50 2019 +0000
Revision:
0:c5ccb9d0afba
Child:
1:a2e46936f4b6
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 0:c5ccb9d0afba 48 class MPU9250
tanahashi 0:c5ccb9d0afba 49 {
tanahashi 0:c5ccb9d0afba 50 private:
tanahashi 0:c5ccb9d0afba 51 char cmd[2];
tanahashi 0:c5ccb9d0afba 52 char buff[8];
tanahashi 0:c5ccb9d0afba 53 public:
tanahashi 0:c5ccb9d0afba 54 I2C *_i2c;
tanahashi 0:c5ccb9d0afba 55 int _addr;
tanahashi 0:c5ccb9d0afba 56 float accel_LSB;
tanahashi 0:c5ccb9d0afba 57 float gyro_LSB;
tanahashi 0:c5ccb9d0afba 58 float mag_LSB;
tanahashi 0:c5ccb9d0afba 59 float accel_offset[3];
tanahashi 0:c5ccb9d0afba 60 float gyro_offset[3];
tanahashi 0:c5ccb9d0afba 61 float mag_offset[3];
tanahashi 0:c5ccb9d0afba 62 public:
tanahashi 0:c5ccb9d0afba 63 /**
tanahashi 0:c5ccb9d0afba 64 * コンストラクタ
tanahashi 0:c5ccb9d0afba 65 * @param i2c I2Cのインスタンスへの参照
tanahashi 0:c5ccb9d0afba 66 * @param AD0 AD0ピンのH/Lレベル
tanahashi 0:c5ccb9d0afba 67 */
tanahashi 0:c5ccb9d0afba 68 MPU9250(I2C &i2c, AD0_t AD0);
tanahashi 0:c5ccb9d0afba 69
tanahashi 0:c5ccb9d0afba 70 /**
tanahashi 0:c5ccb9d0afba 71 * センサ動作開始
tanahashi 0:c5ccb9d0afba 72 */
tanahashi 0:c5ccb9d0afba 73 void begin();
tanahashi 0:c5ccb9d0afba 74
tanahashi 0:c5ccb9d0afba 75 /**
tanahashi 0:c5ccb9d0afba 76 * センサ通信テスト
tanahashi 0:c5ccb9d0afba 77 * @return 通信成功の時true
tanahashi 0:c5ccb9d0afba 78 */
tanahashi 0:c5ccb9d0afba 79 bool test();
tanahashi 0:c5ccb9d0afba 80
tanahashi 0:c5ccb9d0afba 81 bool test_AK8963();
tanahashi 0:c5ccb9d0afba 82
tanahashi 0:c5ccb9d0afba 83 /**
tanahashi 0:c5ccb9d0afba 84 * センサ設定
tanahashi 0:c5ccb9d0afba 85 * @param accel_config 加速度の測定レンジ
tanahashi 0:c5ccb9d0afba 86 * @param gyro_config 角速度の測定レンジ
tanahashi 0:c5ccb9d0afba 87 * @param mag_config 地磁気センサの設定
tanahashi 0:c5ccb9d0afba 88 */
tanahashi 0:c5ccb9d0afba 89 void set(AccelConfig_t accel_config, GyroConfig_t gyro_config, MagConfig_t mag_config);
tanahashi 0:c5ccb9d0afba 90
tanahashi 0:c5ccb9d0afba 91 /**
tanahashi 0:c5ccb9d0afba 92 * 加速度センサ設定
tanahashi 0:c5ccb9d0afba 93 * @param accel_config 角速度センサの測定レンジ
tanahashi 0:c5ccb9d0afba 94 *
tanahashi 0:c5ccb9d0afba 95 */
tanahashi 0:c5ccb9d0afba 96
tanahashi 0:c5ccb9d0afba 97 void set_accel(AccelConfig_t accel_config);
tanahashi 0:c5ccb9d0afba 98 void set_gyro(GyroConfig_t gyro_config);
tanahashi 0:c5ccb9d0afba 99 void set_mag(MagConfig_t mag_config);
tanahashi 0:c5ccb9d0afba 100 void offset(float *accel, float *gyro, float *mag);
tanahashi 0:c5ccb9d0afba 101 void offset_accel(float *accel);
tanahashi 0:c5ccb9d0afba 102 void offset_gyro(float *gyro);
tanahashi 0:c5ccb9d0afba 103 void offset_mag(float *mag);
tanahashi 0:c5ccb9d0afba 104 void read(float *accel, float *gyro, float *mag);
tanahashi 0:c5ccb9d0afba 105 void read_accel(float *accel);
tanahashi 0:c5ccb9d0afba 106 void read_gyro(float *gyro);
tanahashi 0:c5ccb9d0afba 107 void read_mag(float *mag);
tanahashi 0:c5ccb9d0afba 108 };
tanahashi 0:c5ccb9d0afba 109
tanahashi 0:c5ccb9d0afba 110 #endif