Hi guys,

i want to share my results about compensation of  unwanted magnetic effects such as hard-iron, soft-iron and scaling/calibration effects.

As we know that, since earth magnetic field is locally constant , the locus of all data points taken while a 3D magnetic sensor is rotated around every orientation, must be a sphere centered at origin. But in reality, it is generally a arbitrary rotated ellipsoid centered at some offset from origin. Hard-iron effects, scaling errors and soft-iron effects  are reasons for the offset, the ellipsoidal shape and rotation of the ellipsoid around some arbitrary axis, respectively.

Today, i rotated my ardumega card with hand and meanwhile collected raw magnetic data from Diydrones magnetic sensor using logs of AP Mission Planner (after setting magnetic offsets to zero initially). What i found is my sphere was depressed on polar caps in the direction of z axis. I wrote a matlab function (see attachment) to find an ellipsoid least square fit to the raw magnetic data. My results are below (See attachment for details).

3690943506?profile=original

3690943466?profile=original3690943525?profile=original3690943479?profile=original

Output parameters of matlab function (ellipsoid_fit2magnetic_data.m)  are offsets and a transformation matrix (inverse W). After translation of all data points using offsets to the origin and then applying transformation matrix (inverse W) , all magnetic raw data lying on the ellipsoidal surface can be transformed to a sphere centered at origin eliminating hard-iron, soft-iron and scaling effects.

Actually what i described here is not limited with 3D magnetic field sensors , it can be also applied to 3D accelerometers for calculating sensor offsets since gravitational field of earth is also constant locally. I also experienced scale errors for 3D accelerometers before. But data acquisition for compensation of accelerometer hard,soft and scale effects will be difficult unless eliminating inertial accelerations during the recording of accel data with different orientations.

Best all,

O.A

For documentation

http://cache.freescale.com/files/sensors/doc/app_note/AN4246.pdf

 

ellipsoid_fit2magnetic_data.m

magdata.csv

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Great Work,

    I tried your code and seems to be working fine.

    3692509587?profile=original                                 Fig 1. before calibration, (Mx)

    3692509508?profile=original

                                       Fig 2: after calibration

                                

    I am new to compass and took some time to get till here. My only concern is, have you implemented it in hardware and has it worked as it has in the papers? I want to get my compass calibrated soon, do you have any special concerns or suggestion??

  • The problem is that we don't do any real calibration at all.

    It's like you're trying to describe the best way to tune a jet engine to a grease monkey auto mechanic that didn't graduate high school.

    You'd be better off just writing a calibration algorithm and telling us it's mo' better cause it gots the secret sauce. 

  • Nice work!!  I left off in doing this sort of thing many months ago when I ran into snags with the soft iron calibration and then ran into bigger issues that led to ditching a magnetometer for my rover. I never got it really figured out. Glad to see you got this sorted out and can't wait to take a look!

This reply was deleted.

Activity