Thread_LPC

Dependents:   Thread_LPC

Embed: (wiki syntax)

« Back to documentation index

mpu9250_spi Class Reference

mpu9250_spi Class Reference

IMU class. More...

#include <MPU9250.h>

Public Member Functions

 mpu9250_spi (PinName mosi, PinName miso, PinName sck, PinName ncs)
 Create mpu9250_spi class instance.
unsigned int WriteReg (uint8_t WriteAddr, uint8_t WriteData)
 Writes one byte to a register address.
unsigned int ReadReg (uint8_t WriteAddr, uint8_t WriteData)
 Reads one byte from a register address.
void ReadRegs (uint8_t ReadAddr, uint8_t *ReadBuf, unsigned int Bytes)
 Reads multiple bytes from a register address.
bool init (int sample_rate_div, int low_pass_filter)
 Initializes the IMU.
void read_temp ()
 Reads tempreture reading.
void read_acc ()
 Reads accelerometer reading.
void read_rot ()
 Reads gyroscope reading.
unsigned int set_gyro_scale (int scale)
 Sets gyroscope scale.
unsigned int set_acc_scale (int scale)
 Sets accelerometer scale.
void calib_acc ()
 Calibrates accelerometer.
void AK8963_calib_Magnetometer ()
 Calibrates magnetometer.
void select ()
 Selects spi slave pin.
void deselect ()
 Deselects spi slave pin.
unsigned int whoami ()
 Returns the mpu9250 I2C address.
uint8_t AK8963_whoami ()
 Returns the magnetormeter I2C address.
void AK8963_read_Magnetometer ()
 Reads magnetometer reading.
void read_all ()
 Reads all readings from all sensors.
void calibrateMPU9250 ()
 Calibrates mpu9250 and calculates accelerometer and gyroscope bias.
void MadgwickQuaternionUpdate (float ax, float ay, float az, float gx, float gy, float gz, float mx, float my, float mz, float deltat, float beta)
 Calculates quaternions based on Madgwick filter from accelerometer, gyroscope and magnetometer readings.
void MadgwickAHRSupdateIMU (float ax, float ay, float az, float gx, float gy, float gz, float deltat, float beta)
 Calculates quaternions based on Madgwick filter from accelerometer and gyroscope readings.
float invSqrt (float x)
 Used in Madgwick filter.
float euler_angle (int angle)
 Calculates euler angle.

Detailed Description

IMU class.

Used to communicate with IMU.

Definition at line 15 of file MPU9250.h.


Constructor & Destructor Documentation

mpu9250_spi ( PinName  mosi,
PinName  miso,
PinName  sck,
PinName  ncs 
)

Create mpu9250_spi class instance.

Parameters:
mosiSPI MOSI pin for encoder
misoSPI MISO pin for encoder
sckSPI SCK pin for encoder
ncsSPI CS pin for encoder

Definition at line 8 of file MPU9250.cpp.


Member Function Documentation

void AK8963_calib_Magnetometer (  )

Calibrates magnetometer.

Definition at line 309 of file MPU9250.cpp.

void AK8963_read_Magnetometer (  )

Reads magnetometer reading.

Definition at line 330 of file MPU9250.cpp.

uint8_t AK8963_whoami (  )

Returns the magnetormeter I2C address.

Returns:
I2C adress of magnetometer

Definition at line 294 of file MPU9250.cpp.

void calib_acc (  )

Calibrates accelerometer.

Definition at line 277 of file MPU9250.cpp.

void calibrateMPU9250 (  )

Calibrates mpu9250 and calculates accelerometer and gyroscope bias.

Definition at line 407 of file MPU9250.cpp.

void deselect (  )

Deselects spi slave pin.

Definition at line 398 of file MPU9250.cpp.

float euler_angle ( int  angle )

Calculates euler angle.

Parameters:
angle0=Roll, 1=Pitch, 2=Yaw
Returns:
Euler angle

Definition at line 738 of file MPU9250.cpp.

bool init ( int  sample_rate_div,
int  low_pass_filter 
)

Initializes the IMU.

Parameters:
sample_rate_divsample rate divider (raging from 0 to 255)
low_pass_filterlow pass filter value; suitable values are: BITS_DLPF_CFG_256HZ_NOLPF2 BITS_DLPF_CFG_188HZ BITS_DLPF_CFG_98HZ BITS_DLPF_CFG_42HZ BITS_DLPF_CFG_20HZ BITS_DLPF_CFG_10HZ BITS_DLPF_CFG_5HZ BITS_DLPF_CFG_2100HZ_NOLPF
Returns:
1 if an error occurred

Definition at line 52 of file MPU9250.cpp.

float invSqrt ( float  x )

Used in Madgwick filter.

Calculates inverse squared value.

Parameters:
xinput value
Returns:
inverse squared

Definition at line 727 of file MPU9250.cpp.

void MadgwickAHRSupdateIMU ( float  ax,
float  ay,
float  az,
float  gx,
float  gy,
float  gz,
float  deltat,
float  beta 
)

Calculates quaternions based on Madgwick filter from accelerometer and gyroscope readings.

Parameters:
axAccelermoter x reading
ayAccelermoter y reading
azAccelermoter z reading
gxGyroscope x reading
gyGyroscope y reading
gzGyroscope z reading
deltatTime diffference since last calculation
betaIntegration gain

Definition at line 658 of file MPU9250.cpp.

void MadgwickQuaternionUpdate ( float  ax,
float  ay,
float  az,
float  gx,
float  gy,
float  gz,
float  mx,
float  my,
float  mz,
float  deltat,
float  beta 
)

Calculates quaternions based on Madgwick filter from accelerometer, gyroscope and magnetometer readings.

Parameters:
axAccelermoter x reading
ayAccelermoter y reading
azAccelermoter z reading
gxGyroscope x reading
gyGyroscope y reading
gzGyroscope z reading
mxMagnetometer x reading
myMagnetometer y reading
mzMagnetometer z reading
deltatTime diffference since last calculation
betaIntegration gain

Definition at line 556 of file MPU9250.cpp.

void read_acc (  )

Reads accelerometer reading.

Definition at line 214 of file MPU9250.cpp.

void read_all (  )

Reads all readings from all sensors.

Definition at line 350 of file MPU9250.cpp.

void read_rot (  )

Reads gyroscope reading.

Definition at line 236 of file MPU9250.cpp.

void read_temp (  )

Reads tempreture reading.

Definition at line 256 of file MPU9250.cpp.

unsigned int ReadReg ( uint8_t  WriteAddr,
uint8_t  WriteData 
)

Reads one byte from a register address.

Parameters:
WriteAddrRegister Address
WriteDataData
Returns:
temp_data recieved from SPI

Definition at line 20 of file MPU9250.cpp.

void ReadRegs ( uint8_t  ReadAddr,
uint8_t *  ReadBuf,
unsigned int  Bytes 
)

Reads multiple bytes from a register address.

Parameters:
ReadAddrRegister Address
ReadBufPointer to an array where data will be written
BytesNumber of bytes to read

Definition at line 24 of file MPU9250.cpp.

void select (  )

Selects spi slave pin.

Definition at line 393 of file MPU9250.cpp.

unsigned int set_acc_scale ( int  scale )

Sets accelerometer scale.

Parameters:
scaleAcce scale range. Suitable Values: {BITS_FS_2G, BITS_FS_4G, BITS_FS_8G, BITS_FS_16G}
Returns:
the scale set

Definition at line 107 of file MPU9250.cpp.

unsigned int set_gyro_scale ( int  scale )

Sets gyroscope scale.

Parameters:
scaleGyro scale range. Suitable Values: {BITS_FS_250DPS, BITS_FS_500DPS, BITS_FS_1000DPS, BITS_FS_2000DPS}
Returns:
the scale set

Definition at line 156 of file MPU9250.cpp.

unsigned int whoami (  )

Returns the mpu9250 I2C address.

Returns:
I2C adress of mpu9250

Definition at line 199 of file MPU9250.cpp.

unsigned int WriteReg ( uint8_t  WriteAddr,
uint8_t  WriteData 
)

Writes one byte to a register address.

Parameters:
WriteAddrRegister Address
WriteDataData
Returns:
temp_data recieved from SPI

Definition at line 10 of file MPU9250.cpp.