エラー判定用 '\0' + クォータニオンのfloat型4成分,合計17byteのデータをひたすらバイナリ形式で送り続ける.最初のバイトが '\0' でなかったらズレているので,適当なバイト数見送って先頭が '\0' になるよう合わせること.
MPU9250 Class Reference
#include <MPU9250.h>
Public Member Functions | |
MPU9250 (PinName sda, PinName scl) | |
Constructor. | |
bool | testConnection (void) |
Tests the I2C connection by reading the WHO_AM_I register. | |
void | setBW (char BW) |
Sets the bandwidth of the digital low-pass filter. | |
void | setI2CBypass (bool state) |
Sets the auxiliary I2C bus in bypass mode to read the sensors behind the MPU9250 (useful for eval board, otherwise just connect them to primary I2C bus) | |
void | setAcceleroRange (char range) |
Sets the Accelero full-scale range. | |
int | getAcceleroRawX (void) |
Reads the accelero x-axis. | |
int | getAcceleroRawY (void) |
Reads the accelero y-axis. | |
int | getAcceleroRawZ (void) |
Reads the accelero z-axis. | |
void | getAcceleroRaw (int *data) |
Reads all accelero data. | |
void | getAccelero (float *data) |
Reads all accelero data, gives the acceleration in m/s2. | |
void | setGyroRange (char range) |
Sets the Gyro full-scale range. | |
int | getGyroRawX (void) |
Reads the gyro x-axis. | |
int | getGyroRawY (void) |
Reads the gyro y-axis. | |
int | getGyroRawZ (void) |
Reads the gyro z-axis. | |
void | getGyroRaw (int *data) |
Reads all gyro data. | |
void | getGyro (float *data) |
Reads all gyro data, gives the gyro in rad/s. | |
int | getTempRaw (void) |
Reads temperature data. | |
float | getTemp (void) |
Returns current temperature. | |
void | setSleepMode (bool state) |
Sets the sleep mode of the MPU9250. | |
void | write (char address, char data) |
Writes data to the device, could be private, but public is handy so you can transmit directly to the MPU. | |
char | read (char adress) |
Read data from the device, could be private, but public is handy so you can transmit directly to the MPU. | |
void | read (char adress, char *data, int length) |
Read multtiple regigsters from the device, more efficient than using multiple normal reads. | |
void | getAcceleroAngle (float *data) |
function for calculating the angle from the accelerometer. | |
void | getOffset (float *accOffset, float *gyroOffset, int sampleSize) |
function which allows to produce the offset values for gyro and accelerometer. | |
void | computeAngle (float *angle, float *accOffset, float *gyroOffset, float interval) |
function for computing the angle, when accelerometer angle offset and gyro offset are both known. | |
void | enableInt (void) |
function, which enables interrupts on MPU9250 INT pin | |
void | disableInt (void) |
disables interrupts | |
void | setAlpha (float val) |
function which sets the alpha value - constant for the complementary filter. | |
void | read (char address, char subaddress, char *data, int length) |
Daqn added read bytes on specific address and subaddress. | |
int | getMagnetoRawX (void) |
Daqn added Sets the Magneto full-scale range. | |
int | getMagnetoRawY (void) |
Daqn added Reads the magnetometer y-axis. | |
int | getMagnetoRawZ (void) |
Daqn added Reads the magnetometer z-axis. | |
void | getMagnetoRaw (int *data) |
Daqn added Reads all magnetometer data. | |
void | getMagneto (float *data) |
Daqn added Reads all magnetometer data, gives the magnetometer in [[[TBD]]]. |
Detailed Description
MPU9250 IMU library.
Example:
Later, maybe
Definition at line 128 of file MPU9250.h.
Constructor & Destructor Documentation
MPU9250 | ( | PinName | sda, |
PinName | scl | ||
) |
Constructor.
Daqn change log 2018/02/16 : Replace words "MPU6050" with "MPU9250".
Sleep mode of MPU9250 is immediatly disabled
- Parameters:
-
sda - mbed pin to use for the SDA I2C line. scl - mbed pin to use for the SCL I2C line.
2018/02/16 : L57, flip T/F by adding "!". 2018/02/21 : L Includes
Definition at line 12 of file MPU9250.cpp.
Member Function Documentation
void computeAngle | ( | float * | angle, |
float * | accOffset, | ||
float * | gyroOffset, | ||
float | interval | ||
) |
function for computing the angle, when accelerometer angle offset and gyro offset are both known.
function for computing angles for roll, pitch anf yaw
we also need to know how much time passed from previous calculation to now it produces the angle in degrees. However angles are produced from -90.0 to 90.0 degrees if anyone need smth different, they can update this library...
- Parameters:
-
angle - calculated accurate angle from complemetary filter accOffset - offset in angle for the accelerometer gyroOffset - offset in rad/s for the gyroscope interval - time before previous angle calculation and now
Definition at line 349 of file MPU9250.cpp.
void disableInt | ( | void | ) |
disables interrupts
function for disbling interrupts on MPU9250 INT pin, when the data is ready to take
Definition at line 383 of file MPU9250.cpp.
void enableInt | ( | void | ) |
function, which enables interrupts on MPU9250 INT pin
function for enabling interrupts on MPU9250 INT pin, when the data is ready to take
Definition at line 375 of file MPU9250.cpp.
void getAccelero | ( | float * | data ) |
Reads all accelero data, gives the acceleration in m/s2.
Function uses the last setup value of the full scale range, if you manually set in another range, this won't work.
- Parameters:
-
data - pointer to float array with length three: data[0] = X, data[1] = Y, data[2] = Z
Definition at line 127 of file MPU9250.cpp.
void getAcceleroAngle | ( | float * | data ) |
function for calculating the angle from the accelerometer.
Additional function added by Montvydas Klumbys, which will allow easy offset, angle calculation and much more.
it takes 3 values which correspond acceleration in X, Y and Z direction and calculates angles in degrees for pitch, roll and one more direction.. (NOT YAW!)
- Parameters:
-
data - angle calculated using only accelerometer
function for getting angles in degrees from accelerometer
Definition at line 314 of file MPU9250.cpp.
void getAcceleroRaw | ( | int * | data ) |
Reads all accelero data.
- Parameters:
-
data - pointer to signed integer array with length three: data[0] = X, data[1] = Y, data[2] = Z
Definition at line 119 of file MPU9250.cpp.
int getAcceleroRawX | ( | void | ) |
Reads the accelero x-axis.
- Returns:
- 16-bit signed integer x-axis accelero data
Definition at line 95 of file MPU9250.cpp.
int getAcceleroRawY | ( | void | ) |
Reads the accelero y-axis.
- Returns:
- 16-bit signed integer y-axis accelero data
Definition at line 103 of file MPU9250.cpp.
int getAcceleroRawZ | ( | void | ) |
Reads the accelero z-axis.
- Returns:
- 16-bit signed integer z-axis accelero data
Definition at line 111 of file MPU9250.cpp.
void getGyro | ( | float * | data ) |
Reads all gyro data, gives the gyro in rad/s.
Function uses the last setup value of the full scale range, if you manually set in another range, this won't work.
- Parameters:
-
data - pointer to float array with length three: data[0] = X, data[1] = Y, data[2] = Z
Definition at line 202 of file MPU9250.cpp.
void getGyroRaw | ( | int * | data ) |
Reads all gyro data.
- Parameters:
-
data - pointer to signed integer array with length three: data[0] = X, data[1] = Y, data[2] = Z
Definition at line 194 of file MPU9250.cpp.
int getGyroRawX | ( | void | ) |
Reads the gyro x-axis.
- Returns:
- 16-bit signed integer x-axis gyro data
Definition at line 170 of file MPU9250.cpp.
int getGyroRawY | ( | void | ) |
Reads the gyro y-axis.
- Returns:
- 16-bit signed integer y-axis gyro data
Definition at line 178 of file MPU9250.cpp.
int getGyroRawZ | ( | void | ) |
Reads the gyro z-axis.
- Returns:
- 16-bit signed integer z-axis gyro data
Definition at line 186 of file MPU9250.cpp.
void getMagneto | ( | float * | data ) |
Daqn added Reads all magnetometer data, gives the magnetometer in [[[TBD]]].
Function uses the last setup value of the full scale range, if you manually set in another range, this won't work.
- Parameters:
-
data - pointer to float array with length three: data[0] = X, data[1] = Y, data[2] = Z
Definition at line 303 of file MPU9250.cpp.
void getMagnetoRaw | ( | int * | data ) |
Daqn added Reads all magnetometer data.
- Parameters:
-
data - pointer to signed integer array with length three: data[0] = X, data[1] = Y, data[2] = Z
Definition at line 295 of file MPU9250.cpp.
int getMagnetoRawX | ( | void | ) |
Daqn added Sets the Magneto full-scale range.
Macros: MPU9250_MAGNETO_RANGE_250 - MPU9250_MAGNETO_RANGE_500 - MPU9250_MAGNETO_RANGE_1000 - MPU9250_MAGNETO_RANGE_2000
- Parameters:
-
range - The two bits that set the full-scale range (use the predefined macros) Daqn added Reads the magnetometer x-axis.
- Returns:
- 16-bit signed integer x-axis magnetometer data
Definition at line 268 of file MPU9250.cpp.
int getMagnetoRawY | ( | void | ) |
Daqn added Reads the magnetometer y-axis.
- Returns:
- 16-bit signed integer y-axis magnetometer data
Definition at line 277 of file MPU9250.cpp.
int getMagnetoRawZ | ( | void | ) |
Daqn added Reads the magnetometer z-axis.
- Returns:
- 16-bit signed integer z-axis magnetometer data
Definition at line 286 of file MPU9250.cpp.
void getOffset | ( | float * | accOffset, |
float * | gyroOffset, | ||
int | sampleSize | ||
) |
function which allows to produce the offset values for gyro and accelerometer.
function for getting offset values for the gyro & accelerometer
offset for gyro is simply a value, which needs to be substracted from original gyro rad/sec speed but offset for accelerometer is calculated in angles... later on might change that function simply takes the number of samples to be taken and calculated the average
- Parameters:
-
accOffset - accelerometer offset in angle gyroOffset - gyroscope offset in rad/s sampleSize - number of samples to be taken for calculating offsets
Definition at line 327 of file MPU9250.cpp.
float getTemp | ( | void | ) |
Returns current temperature.
- Returns:
- float with the current temperature
Definition at line 237 of file MPU9250.cpp.
int getTempRaw | ( | void | ) |
Reads temperature data.
- Returns:
- 16 bit signed integer with the raw temperature register value
Definition at line 229 of file MPU9250.cpp.
void read | ( | char | address, |
char | subaddress, | ||
char * | data, | ||
int | length | ||
) |
Daqn added read bytes on specific address and subaddress.
- Parameters:
-
adress - register address to write to subadress - register address to write to length - number of bytes to read data - pointer where the data needs to be written to
Definition at line 248 of file MPU9250.cpp.
char read | ( | char | adress ) |
Read data from the device, could be private, but public is handy so you can transmit directly to the MPU.
- Parameters:
-
adress - register address to write to
- Returns:
- - data from the register specified by RA
Definition at line 33 of file MPU9250.cpp.
void read | ( | char | adress, |
char * | data, | ||
int | length | ||
) |
Read multtiple regigsters from the device, more efficient than using multiple normal reads.
- Parameters:
-
adress - register address to write to length - number of bytes to read data - pointer where the data needs to be written to
Definition at line 40 of file MPU9250.cpp.
void setAcceleroRange | ( | char | range ) |
Sets the Accelero full-scale range.
Macros: MPU9250_ACCELERO_RANGE_2G - MPU9250_ACCELERO_RANGE_4G - MPU9250_ACCELERO_RANGE_8G - MPU9250_ACCELERO_RANGE_16G
- Parameters:
-
range - The two bits that set the full-scale range (use the predefined macros)
Definition at line 84 of file MPU9250.cpp.
void setAlpha | ( | float | val ) |
function which sets the alpha value - constant for the complementary filter.
function for setting a different Alpha value, which is used in complemetary filter calculations
default alpha = 0.97
- Parameters:
-
val - value the alpha (complementary filter constant) should be set to
Definition at line 370 of file MPU9250.cpp.
void setBW | ( | char | BW ) |
Sets the bandwidth of the digital low-pass filter.
Macros: MPU9250_BW_256 - MPU9250_BW_188 - MPU9250_BW_98 - MPU9250_BW_42 - MPU9250_BW_20 - MPU9250_BW_10 - MPU9250_BW_5 Last number is the gyro's BW in Hz (accelero BW is virtually identical)
- Parameters:
-
BW - The three bits that set the bandwidth (use the predefined macros)
Definition at line 61 of file MPU9250.cpp.
void setGyroRange | ( | char | range ) |
Sets the Gyro full-scale range.
Macros: MPU9250_GYRO_RANGE_250 - MPU9250_GYRO_RANGE_500 - MPU9250_GYRO_RANGE_1000 - MPU9250_GYRO_RANGE_2000
- Parameters:
-
range - The two bits that set the full-scale range (use the predefined macros)
Definition at line 160 of file MPU9250.cpp.
void setI2CBypass | ( | bool | state ) |
Sets the auxiliary I2C bus in bypass mode to read the sensors behind the MPU9250 (useful for eval board, otherwise just connect them to primary I2C bus)
- Parameters:
-
state - Enables/disables the I2C bypass mode
Definition at line 70 of file MPU9250.cpp.
void setSleepMode | ( | bool | state ) |
Sets the sleep mode of the MPU9250.
- Parameters:
-
state - true for sleeping, false for wake up
Definition at line 45 of file MPU9250.cpp.
bool testConnection | ( | void | ) |
Tests the I2C connection by reading the WHO_AM_I register.
- Returns:
- True for a working connection, false for an error
Definition at line 55 of file MPU9250.cpp.
void write | ( | char | address, |
char | data | ||
) |
Writes data to the device, could be private, but public is handy so you can transmit directly to the MPU.
- Parameters:
-
adress - register address to write to data - data to write
Definition at line 25 of file MPU9250.cpp.
Generated on Tue Jul 12 2022 21:52:16 by 1.7.2