PLANET-Q MPU9250 Library
Dependents: IZU2020_AVIONICS IZU2020_AVIONICS
PQMPU9250.h
- Committer:
- tanahashi
- Date:
- 2019-11-24
- Revision:
- 4:13d220528a23
- Parent:
- 3:9042b3662a14
- Child:
- 5:cf516bc2bdda
File content as of revision 4:13d220528a23:
#ifndef PQMPU9250_H #define PQMPU9250_H #define MPU9250_ADDR_HIGH 0b1101001<<1 #define MPU9250_ADDR_LOW 0b1101000<<1 #define AK8963_ADDR 0b0001100<<1 #define WIA 0x00 #define ST1 0x02 #define HXL 0x03 #define CNTL1 0x0A #define GYRO_CONFIG 0x1B #define ACCEL_CONFIG 0x1C #define INT_PIN_CFG 0x37 #define ACCEL_XOUT_H 0x3B #define GYRO_XOUT_H 0x43 #define PWR_MGMT_1 0x6B #define WHO_AM_I 0x75 #define ACCEL_LSB 0.0000610 #define GYRO_LSB 0.00763 #define MAG_LSB 0.150 typedef enum { AD0_HIGH = MPU9250_ADDR_HIGH, AD0_LOW = MPU9250_ADDR_LOW } AD0_t; typedef enum { _2G = 0b00000000, _4G = 0b00001000, _8G = 0b00010000, _16G = 0b00011000 } AccelConfig_t; typedef enum { _250DPS = 0b00000000, _500DPS = 0b00001000, _1000DPS = 0b00010000, _2000DPS = 0b00011000 } GyroConfig_t; typedef enum { _16B_8HZ = 0b00010010, _16B_100HZ = 0b00010110, _14B_8HZ = 0b00000010, _14B_100HZ = 0b00000100 } MagConfig_t; /** MPU9250 * 9軸センサMPU9250のライブラリ */ class MPU9250 { private: char cmd[2]; char buff[8]; public: I2C *_i2c; int _addr; float accel_LSB; float gyro_LSB; float mag_LSB; float accel_offset[3]; float gyro_offset[3]; float mag_offset[3]; public: /** * コンストラクタ * @param i2c I2Cのインスタンスへの参照 * @param AD0 AD0ピンのH/Lレベル */ MPU9250(I2C &i2c, AD0_t AD0); /** * センサ動作開始 */ void begin(); /** * センサ通信テスト * @return 通信成功の時true */ bool test(); /** * センサ動作開始 */ bool test_AK8963(); /** * センサ設定 * @param accel_config 加速度の測定レンジ * @param gyro_config 角速度の測定レンジ * @param mag_config 地磁気センサの設定 */ void set(AccelConfig_t accel_config, GyroConfig_t gyro_config, MagConfig_t mag_config); /** * 加速度センサ設定 * @param accel_config 角速度センサの測定レンジ * */ void set_accel(AccelConfig_t accel_config); /** * センサ動作開始 */ void set_gyro(GyroConfig_t gyro_config); /** * センサ動作開始 */ void set_mag(MagConfig_t mag_config); /** * センサ動作開始 */ void offset(float *accel, float *gyro, float *mag); /** * センサ動作開始 */ void offset_accel(float *accel); /** * センサ動作開始 */ void offset_gyro(float *gyro); /** * センサ動作開始 */ void offset_mag(float *mag); /** * センサ動作開始 */ void read(float *accel, float *gyro, float *mag); /** * センサ動作開始 */ void read_accel(float *accel); /** * センサ動作開始 */ void read_gyro(float *gyro); /** * センサ動作開始 */ void read_mag(float *mag); }; #endif