PLANET-Q MPU9250 Library
Dependents: IZU2020_AVIONICS IZU2020_AVIONICS
PQMPU9250.h@4:13d220528a23, 2019-11-24 (annotated)
- Committer:
- tanahashi
- Date:
- Sun Nov 24 05:05:18 2019 +0000
- Revision:
- 4:13d220528a23
- Parent:
- 3:9042b3662a14
- Child:
- 5:cf516bc2bdda
test;
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:13d220528a23 | 84 | /** |
tanahashi | 4:13d220528a23 | 85 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 86 | */ |
tanahashi | 0:c5ccb9d0afba | 87 | bool test_AK8963(); |
tanahashi | 0:c5ccb9d0afba | 88 | |
tanahashi | 0:c5ccb9d0afba | 89 | /** |
tanahashi | 0:c5ccb9d0afba | 90 | * センサ設定 |
tanahashi | 0:c5ccb9d0afba | 91 | * @param accel_config 加速度の測定レンジ |
tanahashi | 0:c5ccb9d0afba | 92 | * @param gyro_config 角速度の測定レンジ |
tanahashi | 0:c5ccb9d0afba | 93 | * @param mag_config 地磁気センサの設定 |
tanahashi | 0:c5ccb9d0afba | 94 | */ |
tanahashi | 0:c5ccb9d0afba | 95 | void set(AccelConfig_t accel_config, GyroConfig_t gyro_config, MagConfig_t mag_config); |
tanahashi | 0:c5ccb9d0afba | 96 | |
tanahashi | 0:c5ccb9d0afba | 97 | /** |
tanahashi | 0:c5ccb9d0afba | 98 | * 加速度センサ設定 |
tanahashi | 0:c5ccb9d0afba | 99 | * @param accel_config 角速度センサの測定レンジ |
tanahashi | 0:c5ccb9d0afba | 100 | * |
tanahashi | 0:c5ccb9d0afba | 101 | */ |
tanahashi | 0:c5ccb9d0afba | 102 | void set_accel(AccelConfig_t accel_config); |
tanahashi | 4:13d220528a23 | 103 | |
tanahashi | 4:13d220528a23 | 104 | /** |
tanahashi | 4:13d220528a23 | 105 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 106 | */ |
tanahashi | 0:c5ccb9d0afba | 107 | void set_gyro(GyroConfig_t gyro_config); |
tanahashi | 4:13d220528a23 | 108 | |
tanahashi | 4:13d220528a23 | 109 | /** |
tanahashi | 4:13d220528a23 | 110 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 111 | */ |
tanahashi | 0:c5ccb9d0afba | 112 | void set_mag(MagConfig_t mag_config); |
tanahashi | 4:13d220528a23 | 113 | |
tanahashi | 4:13d220528a23 | 114 | /** |
tanahashi | 4:13d220528a23 | 115 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 116 | */ |
tanahashi | 0:c5ccb9d0afba | 117 | void offset(float *accel, float *gyro, float *mag); |
tanahashi | 4:13d220528a23 | 118 | |
tanahashi | 4:13d220528a23 | 119 | /** |
tanahashi | 4:13d220528a23 | 120 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 121 | */ |
tanahashi | 0:c5ccb9d0afba | 122 | void offset_accel(float *accel); |
tanahashi | 4:13d220528a23 | 123 | |
tanahashi | 4:13d220528a23 | 124 | /** |
tanahashi | 4:13d220528a23 | 125 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 126 | */ |
tanahashi | 0:c5ccb9d0afba | 127 | void offset_gyro(float *gyro); |
tanahashi | 4:13d220528a23 | 128 | |
tanahashi | 4:13d220528a23 | 129 | /** |
tanahashi | 4:13d220528a23 | 130 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 131 | */ |
tanahashi | 0:c5ccb9d0afba | 132 | void offset_mag(float *mag); |
tanahashi | 4:13d220528a23 | 133 | |
tanahashi | 4:13d220528a23 | 134 | /** |
tanahashi | 4:13d220528a23 | 135 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 136 | */ |
tanahashi | 0:c5ccb9d0afba | 137 | void read(float *accel, float *gyro, float *mag); |
tanahashi | 4:13d220528a23 | 138 | |
tanahashi | 4:13d220528a23 | 139 | /** |
tanahashi | 4:13d220528a23 | 140 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 141 | */ |
tanahashi | 0:c5ccb9d0afba | 142 | void read_accel(float *accel); |
tanahashi | 4:13d220528a23 | 143 | |
tanahashi | 4:13d220528a23 | 144 | /** |
tanahashi | 4:13d220528a23 | 145 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 146 | */ |
tanahashi | 0:c5ccb9d0afba | 147 | void read_gyro(float *gyro); |
tanahashi | 4:13d220528a23 | 148 | |
tanahashi | 4:13d220528a23 | 149 | /** |
tanahashi | 4:13d220528a23 | 150 | * センサ動作開始 |
tanahashi | 4:13d220528a23 | 151 | */ |
tanahashi | 0:c5ccb9d0afba | 152 | void read_mag(float *mag); |
tanahashi | 0:c5ccb9d0afba | 153 | }; |
tanahashi | 0:c5ccb9d0afba | 154 | |
tanahashi | 0:c5ccb9d0afba | 155 | #endif |