Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otMPU9250 Class Reference
[MPU9250 - Inertial Measurement UnitMPU9250 - Inertial Measurement Unit]

Library for the management of the IMU MPU9250. More...

#include <otMPU9250.h>


Public Types

enum  Ascale { AFS_2G = 0, AFS_4G, AFS_8G, AFS_16G }
enum  Gscale { GFS_250DPS = 0, GFS_500DPS, GFS_1000DPS, GFS_2000DPS }
enum  Mscale { MFS_14BITS = 0, MFS_16BITS }

Public Member Functions

 otMPU9250 ()
bool init (U8 da=MPU9250_ADDRESS)
bool check ()
bool magnetometerCheck ()
void close ()
void reset ()
void selfTest (F32 *destination)
void accelGyroCalibration ()
void setRange (U8 accRange, U8 gyrRange, U8 magRange)
void imuInit ()
void magnetometerInit ()
void magnetometerCalibration ()
bool ready ()
void accelerometer (F32 &ax, F32 &ay, F32 &az)
void gyroscope (F32 &gx, F32 &gy, F32 &gz)
void accelerometerGyroscope (F32 &ax, F32 &ay, F32 &az, F32 &gx, F32 &gy, F32 &gz)
bool magnetometer (F32 &mx, F32 &my, F32 &mz)
void madgwickQuaternionUpdate (F32 ax, F32 ay, F32 az, F32 gx, F32 gy, F32 gz, F32 mx, F32 my, F32 mz, F32 deltat)
void mahonyQuaternionUpdate (F32 ax, F32 ay, F32 az, F32 gx, F32 gy, F32 gz, F32 mx, F32 my, F32 mz, F32 deltat)
void taitBryanAngles (F32 &yaw, F32 &pitch, F32 &roll)
F32 temperature (float offset=11.0f)

Data Fields

imuDatad


Detailed Description


Member Enumeration Documentation

enum otMPU9250::Ascale
 

Enumeration values:
AFS_2G  Accelerometer 2g full scale.
AFS_4G  Accelerometer 4g full scale.
AFS_8G  Accelerometer 8g full scale.
AFS_16G  Accelerometer 16g full scale.

enum otMPU9250::Gscale
 

Enumeration values:
GFS_250DPS  Gyroscope range 250 degree/s.
GFS_500DPS  Gyroscope range 500 degree/s.
GFS_1000DPS  Gyroscope range 1000 degree/s.
GFS_2000DPS  Gyroscope range 2000 degree/s.

enum otMPU9250::Mscale
 

Enumeration values:
MFS_14BITS  Magnetometer 0.6 mG per LSB.
MFS_16BITS  Magnetometer 0.15 mG per LSB.


Constructor & Destructor Documentation

otMPU9250.otMPU9250  ) 
 


Member Function Documentation

void otMPU9250.accelerometer F32 ax,
F32 ay,
F32 az
 

Read current value from accelerometer for all axes

Parameters:
ax Accelerometer value on X axis
ay Accelerometer value on Y axis
az Accelerometer value on Z axis

void otMPU9250.accelerometerGyroscope F32 ax,
F32 ay,
F32 az,
F32 gx,
F32 gy,
F32 gz
 

Read current value from accelerometer and gyroscope for all axes

Parameters:
ax Accelerometer value on X axis
ay Accelerometer value on Y axis
az Accelerometer value on Z axis
gx Gyroscope value on X axis
gy Gyroscope value on Y axis
gz Gyroscope value on Z axis

void otMPU9250.accelGyroCalibration  ) 
 

Function which accumulates gyro and accelerometer data after device initialization. It calculates the average of the at-rest readings and then loads the resulting offsets into accelerometer and gyro bias registers.

bool otMPU9250.check  ) 
 

Return true if the accelerometer and the gyroscope is present

void otMPU9250.close  ) 
 

Free all allocated data by this class

void otMPU9250.gyroscope F32 gx,
F32 gy,
F32 gz
 

Read current value from gyroscope for all axes

Parameters:
gx Gyroscope value on X axis
gy Gyroscope value on Y axis
gz Gyroscope value on Z axis

void otMPU9250.imuInit  ) 
 

Configure gyroscope, accelerometer and Thermometer.

bool otMPU9250.init U8  da = MPU9250_ADDRESS  ) 
 

Init class data structure

void otMPU9250.madgwickQuaternionUpdate F32  ax,
F32  ay,
F32  az,
F32  gx,
F32  gy,
F32  gz,
F32  mx,
F32  my,
F32  mz,
F32  deltat
 

Implementation of Sebastian Madgwick's "...efficient orientation filter for... inertial/magnetic sensor arrays" (see http://www.x-io.co.uk/category/open-source/ for examples and more details) which fuses acceleration, rotation rate, and magnetic moments to produce a quaternion-based estimate of absolute device orientation -- which can be converted to yaw, pitch, and roll. Useful for stabilizing quadcopters, etc. The performance of the orientation filter is at least as good as conventional Kalman-based filtering algorithms but is much less computationally intensive---it can be performed on a 3.3 V Pro Mini operating at 8 MHz!

Parameters:
ax Accelerometer value on X axis
ay Accelerometer value on Y axis
az Accelerometer value on Z axis
gx Gyroscope value on X axis
gy Gyroscope value on Y axis
gz Gyroscope value on Z axis
mx Magnetometer value on X axis
my Magnetometer value on Y axis
mz Magnetometer value on Z axis
deltat Integration time

bool otMPU9250.magnetometer F32 mx,
F32 my,
F32 mz
 

Read current value from magnetometer for all axes

Parameters:
mx Magnetometer value on X axis
my Magnetometer value on Y axis
mz Magnetometer value on Z axis
Returns:
True if new data is available

void otMPU9250.magnetometerCalibration  ) 
 

Magnetometer calibration

bool otMPU9250.magnetometerCheck  ) 
 

Return if the magnetometer is present

void otMPU9250.magnetometerInit  ) 
 

Configure the magnetometer for continuous read and highest resolution

void otMPU9250.mahonyQuaternionUpdate F32  ax,
F32  ay,
F32  az,
F32  gx,
F32  gy,
F32  gz,
F32  mx,
F32  my,
F32  mz,
F32  deltat
 

Similar to Madgwick scheme but uses proportional and integral filtering on the error between estimated reference vectors and measured ones.

Parameters:
ax Accelerometer value on X axis
ay Accelerometer value on Y axis
az Accelerometer value on Z axis
gx Gyroscope value on X axis
gy Gyroscope value on Y axis
gz Gyroscope value on Z axis
mx Magnetometer value on X axis
my Magnetometer value on Y axis
mz Magnetometer value on Z axis
deltat Integration time

bool otMPU9250.ready  ) 
 

Return true if a new measure is available

void otMPU9250.reset  ) 
 

Reset the accelerometer and the gyroscope

void otMPU9250.selfTest F32 destination  ) 
 

Should return percent deviation from factory trim values, +/- 14 or less deviation is a pass

Parameters:
destination Holds results of gyro and accelerometer self test

void otMPU9250.setRange U8  accRange,
U8  gyrRange,
U8  magRange
 

Specify the range for each measure of the IMU

Parameters:
accRange Accelerometer range see Ascale
gyrRange Gyroscope range see Gscale
magRange Magnetometer range see Mscale

void otMPU9250.taitBryanAngles F32 yaw,
F32 pitch,
F32 roll
 

Define output variables from updated quaternion---these are Tait-Bryan angles, commonly used in aircraft orientation. In this coordinate system, the positive z-axis is down toward Earth. Yaw is the angle between Sensor x-axis and Earth magnetic North (or true North if corrected for local declination, looking down on the sensor positive yaw is counterclockwise. Pitch is angle between sensor x-axis and Earth ground plane, toward the Earth is positive, up toward the sky is negative. Roll is angle between sensor y-axis and Earth ground plane, y-axis up is positive roll. These arise from the definition of the homogeneous rotation matrix constructed from quaternions. Tait-Bryan angles as well as Euler angles are non-commutative; that is, the get the correct orientation the rotations must be applied in the correct order which for this configuration is yaw, pitch, and then roll. For more see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles which has additional links.

Parameters:
yaw Return yaw
pitch Return pitch
roll Return roll

F32 otMPU9250.temperature float  offset = 11.0f  ) 
 

IMU temperature as celsius

Parameters:
offset Offset value for calibrarion
Returns:
Temperature value as celsius. 0 Kelvin = -273.15 Celsius = -459.67 Fahrenheit


Field Documentation

imuData* otMPU9250.d
 


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-25 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0