# Testing FreeIMU Orientation Sensing after Accelerometer and Magnetometer Calibration

Submitted by fabio on Thu, 2012-11-01 15:50.

Testing the FreeIMU framework orientation sensing after using the new FreeIMU calibration GUI to calibrate Accelerometer and Magnetometer.

As you should see, this is pretty accurate and drift free estimation.

## The "yaw" is not the same as in 3D drawing.

In the video, in the euler angle, Yaw is not the same as in 3D drawing.

How is it possible?

Or the graphic is orientated with the quaternions and not with euler angles.

## Nice job Fabio! I've spent

Nice job Fabio!

I've spent couple hours now trying to calibrate the board. It's definitely better with the calibration, but unfortunately I can't seem to be able to get consistent measurements from one calibration to another. Acceleration offsets vary by possible 300 units all the time.

I rotated the device around all axes, got the circles in the calibration app like you did.

Any tips for how to take the measurements? Also, may I suggest we save the temperature during calibration as well?

## The task is to get the

The task is to get the biggest circles, not only circles. That's likely why you get varying results. For the accelerometer, you can make three circles rotating the board perpendicular to the ground.

Of course, any vibration influence the accelerometer, so you will have to be very steady when you do it.

## One of the things I noticed

One of the things I noticed is that the scale numbers are different positive vs negative. More on the Z axis of the accelerometer. For ex. I get ~15500 on Z when I hold the device up, I get ~17200 when I flip it the other way. Have you seen this? Does this mean that you need to add two scales say acc_scale_z_positive, acc_scale_z_negative? I don't think the offset can help much here.

Pretty weird, for the X axes for ex I get consistent ~16300 each side.

## Calibration algorithm

Fabio,

I'm trying to port your calibration algorithm to C. I'm not an expert when it comes to data fitting algorithms. Clearly you know what you're doing.

Would you mind commenting on what the calibration algorithm does? As always, your help is much appreciated.

def calibrate(x, y, z):

H = numpy.array([x, y, z, -y**2, -z**2, numpy.ones([len(x), 1])])

H = numpy.transpose(H)

w = x**2

(X, residues, rank, shape) = linalg.lstsq(H, w)

OSx = X[0] / 2

OSy = X[1] / (2 * X[3])

OSz = X[2] / (2 * X[4])

A = X[5] + OSx**2 + X[3] * OSy**2 + X[4] * OSz**2

B = A / X[3]

C = A / X[4]

SCx = numpy.sqrt(A)

SCy = numpy.sqrt(B)

SCz = numpy.sqrt(C)

# type conversion from numpy.float64 to standard python floats

offsets = [OSx, OSy, OSz]

scale = [SCx, SCy, SCz]

offsets = map(numpy.asscalar, offsets)

scale = map(numpy.asscalar, scale)

return (offsets, scale)

## And to be more precise. I

And to be more precise. I understand what linear regression is. I'm simply confused about how you compute the offsets and the scales. Once I translate this into C, I can integrate it back into FreeIMU so you can have a built in calibration mode.

Thank you Fabio!

## Google for AN3192 by ST

Google for AN3192 by ST Microsistems.. this is where this algorithm is explained.

Have a look at the python/C implementations of the various functions called in the calibration script for the practical implementations.

I don't think you will be able to do something like this in C on a microcontroller.. moreover, once I implement bias/scaling thermal compensation, the idea is that you will need to do the calibration only once, so I wouldn't see the point of embedding this on the microcontroller firmware.

Please elaborate if you have different use cases.

## It's the thermal compensation

It's the thermal compensation I was concerned with. So I was going to have this exposed as a mode on the hardware, such that you could recalibrate the device if needed.

Also, from what I understand MEMS based devices will report different bias/scale in time due to aging, so re-calibration will be required.

Did you see my post about positive scale being different then the negative scale? Is this common, are you seeing the same?

## Very nice. I was watching

Very nice. I was watching your yaw drift slowly...106...105...104. If you let it keep going, would the drift go all the way around the circle? Or does the drifting stop at some point and then drift back in the other direction?

## No, if would stop after a

No, if would stop after a couple of degs and then get back into the right position.

## Little drift

Hello Fabio,

Nice video. I notice a little bit of drift on the yaw axis. It is hardly noticable so won't be a problem inpraxis I guess.

What I don't understand is how drift on the yaw axis is created.

The magnetometer should give a stable output, using the earth magnetic field, right? Don't suppose the earth magnetic field chnges in such short time :)

Then how is it possible that it drifts? Is this caused by the sensor fusion?

## Problems

I suggest you google hard iron and soft iron effects as they are the ones that cause the drift. You can find futher info here:

http://www.google.com.ar/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rj...

## Post new comment