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);
}

Files at this revision

API Documentation at this revision

Comitter:
joe4465
Date:
Thu Sep 18 15:47:30 2014 +0000
Parent:
14:2e61e49cc3f5
Child:
16:ec4300068695
Commit message:
Moved _sampling into header file under private

Changed in this revision

FreeIMU.cpp Show annotated file Show diff for this revision Revisions of this file
MPU6050.lib Show annotated file Show diff for this revision Revisions of this file
--- a/FreeIMU.cpp	Thu Sep 18 08:45:06 2014 +0000
+++ b/FreeIMU.cpp	Thu Sep 18 15:47:30 2014 +0000
@@ -420,12 +420,11 @@
     }
 }
 
-//XYZ
 void FreeIMU::getRate(float * r)
 {    
-    r[0] = val[5]; //Yaw
-    r[1] = val[3]; //Pitch
-    r[2] = val[4]; //Roll
+    r[0] = val[3];
+    r[1] = val[4];
+    r[2] = val[5];
 }
 
 const float def_sea_press = 1013.25;
--- a/MPU6050.lib	Thu Sep 18 08:45:06 2014 +0000
+++ b/MPU6050.lib	Thu Sep 18 15:47:30 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/joe4465/code/MPU6050/#658dd2bbd426
+http://mbed.org/users/joe4465/code/MPU6050/#8abc68eec50c