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);
}
Committer:
tyftyftyf
Date:
Wed Apr 18 20:25:07 2018 +0000
Revision:
29:484a501b8674
Parent:
28:de24fce0509a
change to I2C 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tyftyftyf 0:21840c01d3d7 1
tyftyftyf 0:21840c01d3d7 2 /**
tyftyftyf 0:21840c01d3d7 3 * FreeIMU calibration header. Automatically generated by FreeIMU_GUI.
tyftyftyf 0:21840c01d3d7 4 * Do not edit manually unless you know what you are doing.
tyftyftyf 0:21840c01d3d7 5 */
tyftyftyf 0:21840c01d3d7 6
tyftyftyf 0:21840c01d3d7 7
tyftyftyf 0:21840c01d3d7 8 #define CALIBRATION_H
tyftyftyf 0:21840c01d3d7 9
tyftyftyf 28:de24fce0509a 10 const int acc_off_x = 584;
tyftyftyf 28:de24fce0509a 11 const int acc_off_y = 721;
tyftyftyf 28:de24fce0509a 12 const int acc_off_z = -175;
tyftyftyf 28:de24fce0509a 13 const float acc_scale_x = 14968.063284;
tyftyftyf 28:de24fce0509a 14 const float acc_scale_y = 16994.191435;
tyftyftyf 28:de24fce0509a 15 const float acc_scale_z = 17252.294385;
tyftyftyf 0:21840c01d3d7 16
tyftyftyf 28:de24fce0509a 17 const int magn_off_x = 154;
tyftyftyf 28:de24fce0509a 18 const int magn_off_y = 163;
tyftyftyf 28:de24fce0509a 19 const int magn_off_z = 28;
tyftyftyf 28:de24fce0509a 20 const float magn_scale_x = 207.523911;
tyftyftyf 28:de24fce0509a 21 const float magn_scale_y = 215.747581;
tyftyftyf 28:de24fce0509a 22 const float magn_scale_z = 233.643447;