10DOF FreeIMU port for FreeIMU v4 board and GY-86. This library was modified extensively to specifically suit the Mbed platform. Used threads and interrupts to achieve async mode.
Dependencies: HMC58X3 AK8963 MS561101BA MODI2C MPU9250
Dependents: MTQuadControl FreeIMU_serial FreeIMU_demo
Port of FreeIMU library from Arduino to Mbed
10DOF FreeIMU port for FreeIMU v4 board and GY-86. This library was modified extensively to specifically suit the Mbed platform. Maximum sampling rate of 500hz can be achieved using this library.
Improvements
Sensor fusion algorithm fast initialization
This library implements the ARHS hot start algorithm, meaning that you can get accurate readings seconds after the algorithm is started, much faster than the Arduino version, where outputs slowly converge to the correct value in about a minute.
Caching
Sensors are read at their maximum output rates. Read values are cached hence multiple consecutive queries will not cause multiple reads.
Fully async
Acc & Gyro reads are performed via timer interrupts. Magnetometer and barometer are read by RTOS thread. No interfering with main program logic.
Usage
Declare a global FreeIMU object like the one below. There should only be one FreeIMU instance existing at a time.
#include "mbed.h" #include "FreeIMU.h" FreeIMU imu; int main(){ imu.init(true); }
Then, anywhere in the code, you may call imu.getQ(q) to get the quarternion, where q is an array of 4 floats representing the quarternion structure.
You are recommended to call getQ frequently to keep the filter updated. However, the frequency should not exceed 500hz to avoid redundant calculation. One way to do this is by using the RtosTimer:
void getIMUdata(void const *); //method definition //in main RtosTimer IMUTimer(getIMUdata, osTimerPeriodic, (void *)NULL); IMUTimer.start(2); //1 / 2ms = 500hz //getIMUdata function void getIMUdata(void const *dummy){ imu.getQ(NULL); }
Diff: FreeIMU.h
- Revision:
- 20:a2edd3ced80e
- Parent:
- 18:3f4803a943d3
- Child:
- 28:de24fce0509a
--- a/FreeIMU.h Wed Mar 28 20:26:32 2018 +0000 +++ b/FreeIMU.h Wed Mar 28 21:07:02 2018 +0000 @@ -24,9 +24,11 @@ #ifndef FreeIMU_h #define FreeIMU_h +#include "mbed.h" + #ifndef I2C_SDA -#define I2C_SDA p28 -#define I2C_SCL p27 + #define I2C_SDA p28 + #define I2C_SCL p27 #endif // Uncomment the appropriated version of FreeIMU you are using @@ -68,8 +70,8 @@ #endif -#define HAS_MPU6050() (defined(FREEIMU_v04) || defined(GEN_MPU6050)) -#define HAS_MPU9250() (defined(FREEIMU_v04) || defined(GEN_MPU9250)) +#define HAS_MPU6050() (defined(GEN_MPU6050)) +#define HAS_MPU9250() (defined(GEN_MPU9250)) #define IS_6DOM() (defined(SEN_10121) || defined(GEN_MPU6050)) #define HAS_AXIS_ALIGNED() (defined(FREEIMU_v01) || defined(FREEIMU_v02) || defined(FREEIMU_v03) || defined(FREEIMU_v035) || defined(FREEIMU_v035_MS) || defined(FREEIMU_v035_BMP) || defined(FREEIMU_v04) || defined(SEN_10121) || defined(SEN_10736))