Never actually tested in practise

This library has only been 'hand tested', it never was actually included in a quadcopter. It is now published so it might help someone, but please verify it works for you before you crash your setup (that is of course for every library you use). It is a while ago I made this, so everything that follows might be slightly different than I remember :D.

Inputs are SI units (probably), so gyro data should be in rad/s. Magnetometer and accelerometer only uses normalized vectors. You will require the following library which isn't included in this one: http://mbed.org/users/BlazeX/code/GTMath/. I am fairly certain things like normalizing a vector twice happens currently, so it can be more efficient.

Basic functionality

The library doesn't use quaternions, since they are hard, but instead two 3D vectors. Those last 2 floats aren't going to fill your memory. One vector is the in the length of the aircraft/device/etc ('heading'), the other one points up ('top'). Together they define the angle of your craft.

The currently measured vectors by the accelerometer and magnetometer are defined. The top simply calculated from the accelerometer data. For the heading the magnetometer data is used, which is moved to be at 90 degrees from the top (this is required since unless you live at the equator that won't be the case). This directly makes sure they have the 90 degree angle between them they are supposed to have.

At the same time the gyroscope offset (later more) is removed from the gyroscope data, and that is used to rotate the old heading and top vectors to new values according to your gyroscope data.

We calculate the difference between the gyroscope measurements and the accelero/magneto measurements. We call this the offset of the gyroscope. Now with a certain weight factor we combine the two measurement types into a final result, which is also used for the next gyroscope measurement. This already cancels part of the gyroscope drift.

The second part is that we average out the gyroscope offset measurements, and the result of that is used to compensate new gyroscope measurements.

Committer:
Sissors
Date:
Wed Jul 11 12:26:44 2012 +0000
Revision:
0:4dc7e56179ff
Child:
1:51c902d63dda
[mbed] converted /Quadrocopter/IMUCalc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:4dc7e56179ff 1 /*Seriously no one cares about copyright stuff
Sissors 0:4dc7e56179ff 2
Sissors 0:4dc7e56179ff 3 But if you really want the license: If you make lots of money with my code, send me money, ty
Sissors 0:4dc7e56179ff 4
Sissors 0:4dc7e56179ff 5 Now usefull stuff*/
Sissors 0:4dc7e56179ff 6
Sissors 0:4dc7e56179ff 7
Sissors 0:4dc7e56179ff 8 #ifndef IMUCALC_H
Sissors 0:4dc7e56179ff 9 #define IMUCALC_H
Sissors 0:4dc7e56179ff 10
Sissors 0:4dc7e56179ff 11 /**
Sissors 0:4dc7e56179ff 12 * Includes
Sissors 0:4dc7e56179ff 13 */
Sissors 0:4dc7e56179ff 14 #include "mbed.h"
Sissors 0:4dc7e56179ff 15 #include "math.h"
Sissors 0:4dc7e56179ff 16 #include "GTMath.h"
Sissors 0:4dc7e56179ff 17
Sissors 0:4dc7e56179ff 18 #ifndef M_PI
Sissors 0:4dc7e56179ff 19 #define M_PI 3.14159265358979323846
Sissors 0:4dc7e56179ff 20 #endif
Sissors 0:4dc7e56179ff 21
Sissors 0:4dc7e56179ff 22 class IMUCalc {
Sissors 0:4dc7e56179ff 23 public:
Sissors 0:4dc7e56179ff 24
Sissors 0:4dc7e56179ff 25
Sissors 0:4dc7e56179ff 26
Sissors 0:4dc7e56179ff 27
Sissors 0:4dc7e56179ff 28 //private:
Sissors 0:4dc7e56179ff 29
Sissors 0:4dc7e56179ff 30 /**
Sissors 0:4dc7e56179ff 31 * Calculates the angle between two vectors
Sissors 0:4dc7e56179ff 32 *
Sissors 0:4dc7e56179ff 33 * @param vectorA - first vector
Sissors 0:4dc7e56179ff 34 * @param vectorB - second vector
Sissors 0:4dc7e56179ff 35 * @param return - angle between the two vectors
Sissors 0:4dc7e56179ff 36 */
Sissors 0:4dc7e56179ff 37 static Vector3 angleBetween(Vector3 vectorA, Vector3 VectorB);
Sissors 0:4dc7e56179ff 38
Sissors 0:4dc7e56179ff 39
Sissors 0:4dc7e56179ff 40 };
Sissors 0:4dc7e56179ff 41
Sissors 0:4dc7e56179ff 42 #endif