Compass calibration - Methods.

What is the best way to calibrate a compass that is already installed (I have it on the boat) by rotating the boat 360 degrees and taking the min / max x and y offsets ranges? Are there any alternatives?

You should always calibrate a compass in its final resting place. For a boat, rotating 360 degrees in place is about the only option.

In general there are much better options, as described in this tutorial.

How is this best done? rotate once? Could it be a few 360 degrees? the question can it be on a slope or must it be horizontally perfect?

Collect as many data points as you think reasonable.

A friend of mine worked on a large research vessel with 500 scientists and crew. He told me that from time to time the captain would calibrate the compass by using the thrusters to rotate the ship in place, through 720 degrees.

jremington:
Collect as many data points as you think reasonable.

A friend of mine worked on a large research vessel with 500 scientists and crew. He told me that from time to time the captain would calibrate the compass by using the thrusters to rotate the ship in place, through 720 degrees.

Thanks for the hints.

Problem with the ship rotating method is that the vertical component (inclination) of the magnetic field is often larger than the horizontal. A rolling ship during calibration will affect the accuracy.

Good information about the Earth magnetic field

Problem with the min-max method is that electronic devices now and then produce an outlyer measurement. This will be automatically selected as the min or max, so the calibration is based on the worst measurement.
Better is to average a number of measurements and take that as a single measuring pont for the min-max method. This is very suitable for a rotating ship.

Alternatively is to apply a circular or elliptical least squares fit to the measurements. The offset is the coordinates of centre and the scale factor the length of the axes.

A 3d elipsoid fit is not suitable for in situ calibration. If you are not working for Marvel, it will be hard to swing and twist the ship around in all directions. :o

Thanks. Im have a question about tilt compensation. It is better to get data from accelerometer or gyroscope (or complementary filter for both use)?

For tilt compensation, an accelerometer is used to measure roll and pitch.

The rate gyro can't measure either, it just helps correct for motion-induced errors in the accelerometer measurement.

Ok, does the accelerometer need to be calibrated to correctly compensate for the tilt? I don't know why, but sometimes compensation can "distort" a compass by 10-20 degrees.

The accelerometers in the latest sensor chips generally do not need calibration. Pololu has a good selection.

sometimes compensation can "distort" a compass by 10-20 degrees.

Tilt compensation, if done correctly, won't distort the compass reading. Something else is wrong.

What if the compass is incorrectly calibrated? Suppose I have a badly calibrated compass. With compensation turned on, it shows e.g. 100 degrees and 90 degree if compensation turned off. Is this a possible scenario? In this case, will the compensation affect the result of bearing the compass?

The obvious solution is to correctly calibrate the magnetometer.

Good luck with your project.

Compass or magnetometer?

If magnetometers:

Find two magnetometers that produce a near exact measurement when placed in the same spot. A matched pair. Mount one magnetometer 180 degrees out of phase with the other and then sum the readings together to get a self compensating/calibrating magnetometer.

It’s very interesting, but I don’t quite understand it. Can you explain how it would work?

Problem with the min-max method is that electronic devices now and then produce an outlyer measurement. This will be automatically selected as the min or max, so the calibration is based on the worst measurement.
Better is to average a number of measurements and take that as a single measuring pont for the min-max method. This is very suitable for a rotating ship.

Can you give some example for this ?

The magnetometer mounted + readings summed with the - mounted magnetometer would cancel each other out, leaving the magnetic deviation. Works pretty good considering the calibration of a magnetometer is only good for the position that the magnetometer was calibrated. Once the physical position calibrated magnetometer is moved the calibration for the previous position is not valid for the new physical position.

Find two magnetometers that produce a near exact measurement when placed in the same spot. A matched pair.

Fascinating idea!

How many magnetometers does one usually have to buy and test, in order to find a "matched pair"?

Good question :slight_smile:

jremington: I have a question, Sorry to bother you with questions. Where can I find examples of calibration, averaging the results of the min / max offsets method?

He spoke about it: femmeverbeek

"Better is to average a number of measurements and take that as a single measuring pont for the min-max method. This is very suitable for a rotating ship."

jremington:
Fascinating idea!

How many magnetometers does one usually have to buy and test, in order to find a "matched pair"?

Out of 5 purchased to test the idea, using LSM9DS1's, I found 4 tested to be close enough to use as matched pairs. I used the ESP32 SPI API, where I was able to have + take a reading, then have - to take a reading, collect +'s reading, collect - reading and sum together.

We used the same principle for rate gyros and accelerometers, by feeding a electronically matched gyro/accelerometer pair the same bias as the navigational gyros/accelerometers, an on going drift rate can be calculated and applied at the time of inertial reads.

The best tutorial for calibration a compass is Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers

Simpler, inferior methods like min/max are described here Accelerometer Calibration II: Simple Methods | Chionotech