Drift-free attitude and heading estimation with the new FreeIMU library calibration routine

Submitted by fabio on Tue, 2012-07-31 15:15.

The problem of missing calibration routines for the FreeIMU has been bothering me for a long time.. I was aware of many approaches to the problem but simply never been able to work on it.

Thanks to the help of Andrea and Pasquale Cirillo which provided me with some calibration code based upon the "infamous" AN3192 from ST Microsystems, I've been able to embed everything into a nice calibration procedure for the FreeIMU library.

The results are very promising, as you should see from the video below. Code is available on the FreeIMU repository and will be published in the next version of the FreeIMU library.

Posted in:

Can the Calibration GUI be set up to work on the Sparkfun IMU

Submitted by Brad P. (not verified) on Mon, 2013-11-18 18:24.

I am using the Sparkfun IMU Digital Combo Board - 6 Degrees of Freedom ITG3200/ADXL345 SEN-10121 and I am trying to slow down, eliminate, or reduced the drift in the sensor. I have the Arduino and process codes working which I downloaded the on chip version off of http://www.varesano.net/blog/fabio/my-first-6-dof-imu-sensors-fusion-imp.... The FreeIMU-GUI in the library however is not working. I can launch the .bat file and the GUI opens, but when I connect the COM3 (Windows 7) it says it is awaiting Arduino reset and freezes. Is the GUI not applicable to this board or is there another way I can calibrate this board? I am brand new to Arduino and coding in general this semester, so I equate my knowledge to a blind man trying to run a marathon. Please Help.

did u solve that problem ? ..

Submitted by mahmoud (not verified) on Fri, 2014-02-28 19:06.

did u solve that problem ? .. i have the same problem with MPU-6050 it freezes

It works on windows

Submitted by JG (not verified) on Fri, 2012-11-02 13:48.

It works on windows,thanks a lot!!!! but everytime i commented your website says: "Your submission has triggered the spam filter and will not be accepted."

here it is not working on

Submitted by legacy (not verified) on Tue, 2012-11-06 14:15.

here it is not working on windows, i am not able to install the package because it says there are files missing in the python stuff

what have you installed ?

Did you downloaded the

Submitted by JG (not verified) on Tue, 2012-11-06 14:28.

Did you downloaded the windows version? Run the freeimu.bat .

offcourse, i downloaded the

Submitted by legacy (not verified) on Tue, 2012-11-06 18:23.

offcourse, i downloaded the windows package

when i run the .bat it say python is missing of the QT library and it stops

also in the folder of python i can't install python because it says it is missing of files

it smell like something missing that need to be install before using the package you have put on here

so, what have i to pre-install in order to use your package ?

Python 2.7 and PyQT v4.9.5

Submitted by JG (not verified) on Wed, 2012-11-07 06:58.

Python 2.7 and PyQT v4.9.5 have been installed on my windows.You should download them on their offical website,try it.

Actually, the windows program

Submitted by fabio on Wed, 2012-11-07 09:32.

Actually, the windows program downloadable from here should be runnable without downloading any external dependency. You shouold extract the archive and simply run the freeimu.bat.

If that won't work, please note the error it gives you and I'll try to help.

Fabio, i downloaded the

Submitted by legacy (not verified) on Wed, 2012-11-07 10:46.

Fabio, i downloaded the windows package from your link, running freeimu.bat says PyQT is missing, i have also seen the "python" folder with python-2.7.2 installer .exe, but if i invoked it says that "python/lib/test/*" is missing, so the installer stops without installing nothing.
Now I am downloading manually python and PyQT from their websites.

other missing pkg

Submitted by legacy (not verified) on Wed, 2012-11-07 11:40.

it also seems to me that i need to install pyqtgraph
so
- python-2.7.2, http://www.python.it/download/
- pyqt, http://www.riverbankcomputing.co.uk/software/pyqt/download
- pyqtgraph, http://luke.campagnola.me/code/pyqtgraph/

other packages are required

Submitted by legacy (not verified) on Wed, 2012-11-07 15:34.

they should be

- numpy
- scipy
- pyopenGL
- pyserial

OpenGL is a pain in the ass for old Windows XP Machines, your app is requiring OpenGL 2.2 while my T23 laptop has no video driver with nothing more updated than openGL 1.1, so so driver no party =(

my first laptop is an Apple Air with MacOSX lion, i have bought a T23 pentium3 laptop because on Apple VirtualBOX suxs a lot about usb virtualization, and also because i need Labview and Matlab running on a native hw instead of running inside a virtual machine

btw your App needs pyOpenGL which needs openGL v2.2 in driver support, i am only able to run your App inside the virtualmachine, which is working good with OpenGL but which has no success about USB-serial virtualization, so i can't connect my IMU board =(

is To build PyOpenGL on Win32

Submitted by legacy (not verified) on Wed, 2012-11-07 17:19.

is To build PyOpenGL on Win32 linked against the Mesa DLLs

building the Mesa package as instructed in the Mesa documentation, then

copy the .lib files to a location on your LIB path
copy the .dll files to your system directory

no time to test it, a lot of trouble with macOSX, too =(

the precise error i got

Submitted by legacy (not verified) on Wed, 2012-11-07 17:50.

Traceback (most recent call last):
File "FreeIMU_GUI\cal_gui.py", line 356, in
window = FreeIMUCal()
File "FreeIMU_GUI\cal_gui.py", line 96, in __init__
self.acc3D.addItem(self.sp)
File "D:\idp\gnu\python.v27\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 42, in addItem
self.checkOpenGLVersion('Error while adding item %s to GLViewWidget.' % str(item))
File "D:\idp\gnu\python.v27\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 266, in checkOpenGLVersion
raise Exception(msg + " The original exception is printed above; however, pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is %s. Installing updated display drivers may resolve this issue." % ver)
Exception: Error while adding item to GLViewWidget. The original exception is printed above; however, pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is 1.1. Installing updated display drivers may resolve this issue.

-----------------

pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is 1.1. Installing updated display drivers may resolve this issue.

-----------------

has this blog a way to edit text ? in the previous post it has lost the title, which was "the only solution is", a forum should be nicer

FreeIMU Community website

Submitted by fabio on Wed, 2012-11-21 10:27.

FreeIMU Community website online at http://freeimu.varesano.net/
Hope to see you there.

have you seen this arm-IMU project ?

Submitted by legacy (not verified) on Fri, 2012-11-02 10:05.

@fabio, have you seen this project ?

it's an IMU with arm MPU and comes with factory-calibrated to remove soft and hard iron distortions present in the enclosure. When integrated into the end-user system, additional calibration may be necessary to correct other magnetic field distortions. Magnetometer calibration can be performed using the CH Robotics Serial Interface software.

http://www.pololu.com/catalog/product/1255

@matteo well, typical IMU

Submitted by legacy (not verified) on Fri, 2012-11-02 09:55.

@matteo

well, typical IMU applications are

- UAV navigation
- Odometry
- Motion tracking
- General motion sensing
- Platform stabilization
- Image stabilization
- Enhanced GPS navigation

Where is the Calibration Procedure

Submitted by Al Testani (not verified) on Thu, 2012-10-18 02:19.

I have installed Octave on my Windows XP machine but cannot find the the calibration procedure. May I have the link, please?

Thanks

The current code is available

Submitted by fabio on Thu, 2012-10-18 10:24.

The current code is available on the FreeIMU repository in libraries/FreeIMU/calibration/ .. there is a file called calibrate.py which you will need to run with Python. This is not really a user friendly procedure.. a better program is being developed right now.

Code won't run correctly on Windows

Submitted by Al Testani (not verified) on Thu, 2012-10-18 18:57.

I have been trying to derive a calibration file (on Windows XP) for the last 4 hours and cannot.

I tried Ned's suggestions and files below with no success. I can get the accn.txt and magn.txt files created but the Python script bombs out calling Octave. I have been unsuccessful running the AccMagnCalib.m file directly in the Octave shell as it complains of undefined variables even though they are actually part of the arg-list of functions.

Initially the errors were in SpherePlot so I commented out (same as Ned did) and eventually deleted the definition and calls to that function. Then Octave complained that the variable data was undefined where it is referenced in Ellipsoid_to_Sphere. Thinking this may be some conflict with the data = dlmread(... calls I changed the prototype and body of Ellipsoid_to_Sphere to use xdata, restarted Octave, and the error now said xdata was undefined!

I never heard of Octave until this week and am surely not fluent in writing code for it BUT these errors seem to defy normal programming standards.

Any advice on what I am doing wrong?

Thanks

Al

me, too, octave script is not

Submitted by Anonymous (not verified) on Thu, 2012-11-15 14:37.

me, too, octave script is not working at all, please fix !!!

script issue with octave on mac, too

Submitted by Anonymous (not verified) on Thu, 2012-11-15 14:41.

yep i have emerged octave on mac-ports and the octane script is now working, too

PROBLEM CALIBRATING ACCELEROMETER need help plz

Submitted by Anonymous (not verified) on Mon, 2012-10-01 18:23.

Hello,
i don't understand how you calibrated the Accelerometer .
this is the link to the ST AN3192
http://www.pololu.com/file/download/LSM303DLH-compass-app-note.pdf?file_...
They used in the end a least square method
here is my script with Matlab and my data
http://www.mediafire.com/?58uuybyddewn2s4

I always get this from matlab
Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN.
w matrix produce NAN
PLZ HELP ME
THX

More Resources for Calibration

Submitted by Michael (not verified) on Wed, 2012-11-21 23:49.

Glad you found a solution. If you ever need more help or documentation the CH Robotics site is full of helpful resources like
UM6 Datasheet

AN1002 – Reprogramming the Firmware on the UM6
AN1003 – Getting Started with the UM6 Orientation Sensor
AN1005 – Understanding Euler Angles
AN1006 – Understanding Quaternions
AN1007 – Estimating Position and Velocity Using Accelerometers
AN1008 – Sensors used for Orientation Estimation

http://www.chrobotics.com/shop/orientation-sensor-um6

Happy Building!

i founded NAN in the DATA

Submitted by Anonymous (not verified) on Mon, 2012-10-01 18:43.

i founded NAN in the DATA that is the Problem

Use AccMagnCalib.m to

Submitted by fabio on Mon, 2012-10-01 18:42.

Use AccMagnCalib.m to calibrate both the accelerometer and magnetometer. Make circles over the three planes.

Current procedure is not the best.. I'm looking into alternatives..

AccMagnCalib.m I dont

Submitted by Anonymous (not verified) on Mon, 2012-10-01 18:45.

AccMagnCalib.m
I dont understand it for the Accelerometer Part
you are using the method of calibration of the magnetometer on the accelerometer DATA ???!!!

Yes, I use the ellipsoid to

Submitted by fabio on Mon, 2012-10-01 22:44.

Yes, I use the ellipsoid to sphere calibration both for the magnetometer and the accelerometer. The accelerometer calibration as explained in the ST document is very prone to errors: placing the acc in the 6 known position was a pain in the ass for me in most of my prototypes moreover it means more heavy math for translating raw into calibrated data.. so, I'm going with the same approach for both. Works pretty fine here.

can't run Serial example

Submitted by Anonymous (not verified) on Sun, 2012-09-23 20:11.

Hello, I've been trying to run the calibration routine and I'm requested to run the serial example, but it won't compile. The problem is in the sprintf line, as DEVElOPER, FREQ, LIB VERSION and LIB, don't seem to exist (are not declared), below the conflicting part of the code:

if(cmd=='v') {
sprintf(str, "FreeIMU library by %s, FREQ:%s, LIB_VERSION: %s, IMU: %s", FREEIMU_DEVELOPER, FREEIMU_FREQ, FREEIMU_LIB_VERSION, FREEIMU_ID);
Serial.print(str);
Serial.print('\n');
}

i've tried comenting the sprintf line, but then the calibration routine stops working. Has anyone had this problem before? Am I doing something wrong?
Thanks

You are probably not using an

Submitted by fabio on Sun, 2012-09-23 23:33.

You are probably not using an updated FreeIMU library code. You have to run the calibration routine with the FreeIMU library version that you find on the repository, not an older one you have around.

Hope this helps, let us know how it goes.

Thanks!

Submitted by Anonymous (not verified) on Fri, 2012-09-28 20:09.

The Serial example now compiles and it has been succesfully uploaded to the Arduino. The problem now, is that when I run calibration.py it gets stuck at "FreeIMU library version informations:"
Do you know what is happening?
thanks in advance

See the comments below..

Submitted by fabio on Fri, 2012-09-28 22:55.

See the comments below.. people have reported that some delay is needed in the code.. there are some examples below..

I can't find any of them

Submitted by Anonymous (not verified) on Mon, 2012-10-01 06:10.

I'm sorry, but I've been cheking the comments and I still can't find anyone with my same issue. If there is, could you please tell me so I can read it?
Else, could you tell me about that issue?
Thanks in advance

See Ned comment below.

Submitted by fabio on Mon, 2012-10-01 14:44.

See Ned comment below.

Calibration Question

Submitted by Ned (not verified) on Sat, 2012-09-15 19:10.

The calibration instructions say to rotate the board to define a complete sphere. Does this mean rotate the board about a fixed point on say one of the chips, or slide the board around the surface of a large sphere? Did you use something to hold the board steady while rotating it, or just do all this by hand? Sorry if these are obvious answers, but I don't understand what goes on mathematically to calibrate the board.

Also, just to let you know, I got the entire calibration procedure working on windows. I only had to mess with octave environment variables, disable the sphere plot (which was for some reason crashing octave), and insert a delay in the python script before reading the version number.

Hello Ned, the sphere has to

Submitted by fabio on Sun, 2012-09-16 07:55.

Hello Ned, the sphere has to be made using the IMU as center of rotation. I don't use anything to hold the IMU, just my hands.. if you are careful enough and move very slowly, you should get good results.

I'm happy to see success also using Windows.. I don't use Windows at all so I hoped to see someone testing this on Win. I'd like to get the modified scripts you use on windows so I can incorporate the changes in next versions of the library. Can you share them?

Here is the zipped

Submitted by Ned (not verified) on Mon, 2012-09-17 05:38.

Here is the zipped Calibrations folder with my changes:
http://www.mediafire.com/?7j880r5t711zmpw
In Calibrate.pyw, I added time.sleep(2) before reading the serial data. Before that, the python script would just stop there.
In AccMagnCalib.m, I just had to comment out the SpherePlot. For some reason, it was crashing octave. The edits were sort of minimal because I have only a rough idea of what I am doing, heh. I also had to add a windows environment variable for octave to get it working correctly. Aside from those changes though, I think everything else is still the same.

I'm still trying to figure out a few other things. Is FreeIMU_calibrated the only sketch that accounts for the new calibration? I'm trying to get the processing cube rendering working with the calibrated code (as you did in your video), but the FreeIMU_Calibrated serial output looks like it's x,y,z values for the acceleration, magnetometer, and gyro, which (I think) is not what the processing sketch expects as input. Is there a way to get pitch roll and yaw output using the calibrated code? I'm not very experienced with arduino sketches or python, but I'm trying to figure it out. Thanks a lot for the help!

Once the calibration

Submitted by fabio on Tue, 2012-09-18 10:27.

Once the calibration procedure is complete, the library will use calibrated readings for anything (quaternion, yawpitchroll, etc..) except for the raw outputs.

To my understanding

Submitted by Not Fabio (not verified) on Tue, 2012-09-18 04:23.

You simply compile the regular examples(Quaternion for the processing cube), FreeIMU.h contains,
#include "calibration/calibration.h"
so you don't need to do anything special, just compile Quaternion as you usually would.

PS
This may sound as a silly request, but could anyone upload a video of how they're making a sphere with the board? I'm pretty sure I'm doing something wrong.
When I put it on a table, the Z axis should point up or down?

A calibration routine using numpy

Submitted by nrp (not verified) on Sat, 2012-09-01 19:31.

For an IMU project that I'm working on, I wrote a similar magnetometer hard iron calibration script which uses numpy's linalg module instead of octave or Matlab. It is set up to communicate with my module, but it is pretty simple to modify to communicate with other boards. The source.

Hello Nirav, thanks for

Submitted by fabio on Sat, 2012-09-08 22:55.

Hello Nirav, thanks for posting this and for sharing your code. Numpy was exactly the way I wanted to have the matlab code evolve.. would you mind if I use the code in future versions of my FreeIMU library? Properly credited of course.

Btw, I'd be interested in hearing more about your IMU project.. are you using the new 9axis sensor by ST? Looks so to me by the pictures on your blog. If so, what do you think about it?

Feel free to use it. The

Submitted by nrp (not verified) on Sat, 2012-09-08 23:03.

Feel free to use it. The license is BSD.

I haven't been able to get the LSM333D out of ST yet. I'm just using the LSM303DLHC and the L3GD20, but I do plan on switching to the LSM333D as soon as it is available. Last I heard from ST, it does exist, but in extremely limited quantities.

Yeah.. I know people already

Submitted by fabio on Sat, 2012-09-08 23:10.

Yeah.. I know people already using it.. but under NDAs or something..

Meanwhile, MPU9150 easily available in China..

It took me a while to get

Submitted by John Pattillo (not verified) on Thu, 2012-08-30 19:32.

It took me a while to get octave installed on my macbook, but I finally got this all working. My smart skeleton IMUs are much more stable now. I had to modify the serial sketch to use the acc library since I'm using ADLX345's on most of my IMUs. I've posted that part of the code below. I see from calibrate.py that the gyro values are not needed, but I went ahead and called the gyro library so that I wouldn't have to make any changes to the array structure. Thanks again - John

Whoops! here's the code

Submitted by John Pattillo (not verified) on Thu, 2012-08-30 19:43.
else if(cmd=='b') {
      uint8_t count = serial_busy_wait();
      for(uint8_t i=0; i<count; i++) {
        my3IMU.acc.readAccel(&raw_values[0], &raw_values[1], &raw_values[2]);
        writeArr(raw_values, 3, sizeof(int)); // writes accelerometer values
        my3IMU.gyro.readGyroRaw(&raw_values[0], &raw_values[1], &raw_values[2]);
        writeArr(raw_values, 3, sizeof(int)); //writes gyro values
        my3IMU.magn.getValues(&raw_values[0], &raw_values[1], &raw_values[2]);
        writeArr(raw_values, 3, sizeof(int));
        Serial.println();
      }
    }

Hello, Fabio! Did you see

Submitted by Ivan (not verified) on Sat, 2012-08-18 08:31.

Hello, Fabio! Did you see that: http://www.vectornav.com/purchase
1300$ !!!!
May be you know, why its so expressive...However, this AHRS sensor looks very good, stable and its data look very clear...

Nice work I have been waiting

Submitted by arto (not verified) on Mon, 2012-08-13 22:37.

Nice work

I have been waiting for this. Do you have any estimate when the next version of the FreeIMU library will be published?

You can already try it from

Submitted by fabio on Tue, 2012-08-14 00:44.

You can already try it from the repository above... probably it will be released somewhere at the end of September.

Library

Submitted by Anonymous (not verified) on Fri, 2012-08-10 14:29.

congratulations, those are really good readings.
I'm asking to my self if I can use the new stuff, I mean replacing the old library with the new one (i.e. is the new calibration routine built in in a new version of the library?).
Thanks in advance.

Of course you can.. you just

Submitted by fabio on Fri, 2012-08-10 18:31.

Of course you can.. you just have to get it from the repository.. Then you'll have to run the calibration for your board and you'll be ready to go.

How do I calibrate the board?

Submitted by Anonymous (not verified) on Tue, 2012-08-14 04:58.

I'm not familiar with launchpad and I couldn't find any instruction, only managed to get the latest files.

How do I calibrate the board? Do I need to do anything special?
I noticed the FreeIMU_calibrated example but couldn't really understand what to do with it.
I tried just running quaternion with the processing 3D cube and I think I'm getting better results but there is still some drift(mainly yaw of course).

Thank you.