IZU2020 / PQMPU9250

Dependents:   IZU2020_AVIONICS IZU2020_AVIONICS

Embed: (wiki syntax)

« Back to documentation index

MPU9250 Class Reference

MPU9250 Class Reference

9軸センサMPU9250のライブラリ More...

#include <PQMPU9250.h>

Public Member Functions

 MPU9250 (I2C &i2c, AD0_t AD0)
void begin ()
 センサ動作開始
bool test ()
 センサ通信テスト
bool test_AK8963 ()
 磁気センサAK8963通信テスト
void set (AccelConfig_t accel_config, GyroConfig_t gyro_config, MagConfig_t mag_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)
 磁気測定値の読み取り

Detailed Description

9軸センサMPU9250のライブラリ

#include "mbed.h"
#include "PQMPU9250.h"

Serial pc(USBTX, USBRX, 115200);
I2C i2c(p9, p10);

MPU9250 mpu(i2c, MPU9250::AD0_HIGH);

float accel_offset[] = {0, 0, 0};
float gyro_offset[] = {0, 0, 0};
float mag_offset[] = {0, 0, 0};
float accel[3];
float gyro[3];
float mag[3];

int main() {
    mpu.begin();
    mpu.set(_2G, _250DPS, _16B_8HZ);
    mpu.offset(accel_offset, gyro_offset, mag_offset);
    if(!mpu.test()){
        pc.printf("[  FAIL  ] MPU9250 cannot be reached.\r\n");
    }
    if(!mpu.test_AK8963()){
        pc.printf("[  FAIL  ] AK8963 cannot be reached.\r\n");
    }
    while(1) {
        mpu.read(accel, gyro, mag);
        pc.printf("%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\r\n", accel[0], accel[1], accel[2], gyro[0], gyro[1], gyro[2], mag[0], mag[1], mag[2]);
    }
}

Definition at line 57 of file PQMPU9250.h.


Constructor & Destructor Documentation

MPU9250 ( I2C &  i2c,
AD0_t  AD0 
)
Parameters:
i2cI2Cのインスタンスへの参照
AD0AD0ピンのH/Lレベル

Definition at line 4 of file PQMPU9250.cpp.


Member Function Documentation

void begin (  )

センサ動作開始

Definition at line 11 of file PQMPU9250.cpp.

void offset ( float *  accel,
float *  gyro,
float *  mag 
)

ゼロ点補正

Parameters:
accel加速度のオフセット配列
gyro角速度のオフセット配列
mag磁気のオフセット配列

Definition at line 93 of file PQMPU9250.cpp.

void offset_accel ( float *  accel )

加速度のゼロ点補正

Parameters:
accel加速度のオフセット配列

Definition at line 100 of file PQMPU9250.cpp.

void offset_gyro ( float *  gyro )

角速度のゼロ点補正

Parameters:
gyro角速度のオフセット配列

Definition at line 107 of file PQMPU9250.cpp.

void offset_mag ( float *  mag )

磁気のゼロ点補正

Parameters:
mag磁気のオフセット配列

Definition at line 114 of file PQMPU9250.cpp.

void read ( float *  accel,
float *  gyro,
float *  mag 
)

測定値の読み取り

Parameters:
accel加速度を格納する配列
gyro角速度を格納する配列
mag磁気を格納する配列

Definition at line 121 of file PQMPU9250.cpp.

void read_accel ( float *  accel )

加速度測定値の読み取り

Parameters:
accel加速度を格納する配列

Definition at line 128 of file PQMPU9250.cpp.

void read_gyro ( float *  gyro )

角速度測定値の読み取り

Parameters:
gyro角速度を格納する配列

Definition at line 138 of file PQMPU9250.cpp.

void read_mag ( float *  mag )

磁気測定値の読み取り

Parameters:
mag磁気を格納する配列

Definition at line 148 of file PQMPU9250.cpp.

void set ( AccelConfig_t  accel_config,
GyroConfig_t  gyro_config,
MagConfig_t  mag_config 
)

センサ設定

Parameters:
accel_config加速度の測定レンジ
gyro_config角速度の測定レンジ
mag_config磁気センサの分解能/データレート

Definition at line 46 of file PQMPU9250.cpp.

void set_accel ( AccelConfig_t  accel_config )

加速度センサ設定

Parameters:
accel_config角速度センサの測定レンジ

Definition at line 53 of file PQMPU9250.cpp.

void set_gyro ( GyroConfig_t  gyro_config )

角速度センサ設定

Parameters:
gyro_config角速度の測定レンジ

Definition at line 69 of file PQMPU9250.cpp.

void set_mag ( MagConfig_t  mag_config )

磁気センサ設定

Parameters:
mag_config磁気センサの分解能/データレート

Definition at line 85 of file PQMPU9250.cpp.

bool test (  )

センサ通信テスト

Return values:
true通信成功
false通信失敗

Definition at line 22 of file PQMPU9250.cpp.

bool test_AK8963 (  )

磁気センサAK8963通信テスト

Return values:
true通信成功
false通信失敗

Definition at line 34 of file PQMPU9250.cpp.