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:
tyftyftyf
Date:
Wed Apr 18 20:25:07 2018 +0000
Parent:
28:de24fce0509a
Commit message:
change to I2C 1

Changed in this revision

AK8963.lib Show annotated file Show diff for this revision Revisions of this file
FreeIMU.h Show annotated file Show diff for this revision Revisions of this file
HMC58X3.lib Show annotated file Show diff for this revision Revisions of this file
MPU9250.lib Show annotated file Show diff for this revision Revisions of this file
MS561101BA.lib Show annotated file Show diff for this revision Revisions of this file
diff -r de24fce0509a -r 484a501b8674 AK8963.lib
--- a/AK8963.lib	Thu Mar 29 22:35:45 2018 +0000
+++ b/AK8963.lib	Wed Apr 18 20:25:07 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/tyftyftyf/code/AK8963/#f8ba8df44aab
+https://os.mbed.com/users/tyftyftyf/code/AK8963/#51199a6440be
diff -r de24fce0509a -r 484a501b8674 FreeIMU.h
--- a/FreeIMU.h	Thu Mar 29 22:35:45 2018 +0000
+++ b/FreeIMU.h	Wed Apr 18 20:25:07 2018 +0000
@@ -27,8 +27,8 @@
 #include "mbed.h"
 
 #ifndef I2C_SDA
-  #define I2C_SDA p28
-  #define I2C_SCL p27
+    #define I2C_SDA p9
+    #define I2C_SCL p10
 #endif
 
 // Uncomment the appropriated version of FreeIMU you are using
diff -r de24fce0509a -r 484a501b8674 HMC58X3.lib
--- a/HMC58X3.lib	Thu Mar 29 22:35:45 2018 +0000
+++ b/HMC58X3.lib	Wed Apr 18 20:25:07 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/tyftyftyf/code/HMC58X3/#5279fb447af1
+http://mbed.org/users/tyftyftyf/code/HMC58X3/#ca00fa66673a
diff -r de24fce0509a -r 484a501b8674 MPU9250.lib
--- a/MPU9250.lib	Thu Mar 29 22:35:45 2018 +0000
+++ b/MPU9250.lib	Wed Apr 18 20:25:07 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/tyftyftyf/code/MPU9250/#ae3ee2d811eb
+https://os.mbed.com/users/tyftyftyf/code/MPU9250/#ec9725201195
diff -r de24fce0509a -r 484a501b8674 MS561101BA.lib
--- a/MS561101BA.lib	Thu Mar 29 22:35:45 2018 +0000
+++ b/MS561101BA.lib	Wed Apr 18 20:25:07 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/tyftyftyf/code/MS561101BA/#9f1d38b8d7c3
+http://mbed.org/users/tyftyftyf/code/MS561101BA/#7802dc3ef0a0