Some pointers to take into consideration when calibrating magnetometers.
A magnetometer is a type of sensor that measures the strength and direction of the local magnetic field. The magnetic field measured will be a combination of both the earth’s magnetic field and any magnetic field created by nearby objects. The magnetic field is measured in the sensor reference frame.
Magnetic measurements will be subjected to distortion. These distortions are considered to fall in one of two categories; hard or soft iron. Hard iron distortions are created by objects that produce a magnetic field. A speaker or piece of magnetized iron for example will cause a hard iron distortion. If the piece of magnetic material is physically attached to the same reference frame as the sensor, then this type of hard iron distortion will cause a permanent bias in the sensor output. Soft iron distortions are considered deflections or alterations in the existing magnetic field. These distortions will stretch or distort the magnetic field depending upon which direction the field acts relative to the sensor. This type of distortion is commonly caused by metals such as nickel and iron. In most cases hard iron distortions will have a much larger contribution to the total uncorrected error than soft iron.