Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

LSM303D tilt compensation problem


Next assault. sixD, have you tried Kris’s IMU as l said in earlier post’s. I know it might be $50 but it will prove one way or the other. He backs his and is the person who shows all codes and fixes everyone else is.
He says ±2, which they best l could get was 7.
Buy one and prove one way or the other.
You shouldn’t need to be going into the .h (apart from looking and learning, not needing to change the code, maybe preferances) unless of course you can understand it all and if this was the case, you wouldn’t need to be asking these questions.



My code is here.

It obviously won’t work for you, because it’s meant for a telescope, and as you said, they don’t move like boats.

My point is, instead of the code you’re using (which has so many trigonometric functions) you could try Pololu’s driver.

It has a “heading” method which according to the documentation:

float LSM303::heading(vector from)

“Returns the angular difference in the horizontal plane between the ‘from’ vector and north, in degrees”

Maybe you could try it.


Hi Jim, by the look of things you aren’t willing to show the code you get the great results of zero tilt error with???
l am very keen to have a look and you could help a lot of people with it, so please post and help the IMU community.
Regards Kevin


I’ve been using RTIMULib, which has a decent calibration routine built in, and have no need to revisit code for the LSM303D. I imagine that it wouldn’t be difficult to modify RTIMULib to use that sensor, though.

My efforts were described here: State of the art AHRS for $25 and I highly recommend this software.

Of course, the accuracy of any IMU depends on doing the very best you can to calibrate both the magnetometer and the accelerometer, and in the latest posts, I don’t see evidence that you folks have really accomplished that. I would like to see before and after calibration plots, showing nice circles (not ellipses) or spheres perfectly centered on the origin.


Thanks Jim, by the sounds of it you are using Rtimulib2 with soft and hard iron correction.
Using Magneto l have centred circles on the Mag and Accel and as l said it only improved tilt error correction by 1-2 degrees to about ±10 of error (at worst).
Also my guru Jack, devised an even more accurate means of axis measurement (data thru a whole sphere) that we put thru Magneto with no better results. His V3 went from ±7(max/min) to about ±5(magneto), he is in the Northern Hemisphere.
Regards Kevin