Calibrating magnitometer in a 125 pound boat

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dlwhitman
 
Posts: 14
Joined: Sun Dec 27, 2020 11:09 pm

Calibrating magnitometer in a 125 pound boat

Post by dlwhitman »

Last year, I purchased a Adafruit LSM6DSOX + LIS3MDL - Precision 9 DoF IMU. I successfully calibrated this part (by itself) using Motion Cal, and have been using the part happily since then. I just installed it into a 6 foot 125 pound fiberglass boat, and it seems to be working perfectly. As expected, it does "loose its mind" when I set hand tools on the deck above it.

Do I really need to re-calibrate this part installed in the boat? This would be an awkward procedure, one I don't want to explain to my neighbors. The LIS3MDL is 9 inches from any steel, iron, or current carrying conductors.

Your thoughts?

Doug

User avatar
sj_remington
 
Posts: 998
Joined: Mon Jul 27, 2020 4:51 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by sj_remington »

If the magnetometer accurately points due (or magnetic) NESW when the boat is pointing NESW, you are in great shape!

If not, a friend who worked on a large ocean floor survey vessel (with drilling rig), housing a hundred or so researchers and crew, described how the captain did the compass calibration: use the side thrusters to turn the vessel 720 degrees, while measuring the compass offsets. Apply corrections and continue on.

User avatar
dlwhitman
 
Posts: 14
Joined: Sun Dec 27, 2020 11:09 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by dlwhitman »

Yes, but the captain started with a much better compass than mine, and he didn't need to turn his ship upside down.

User avatar
sj_remington
 
Posts: 998
Joined: Mon Jul 27, 2020 4:51 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by sj_remington »

The quality of the compass has nothing to do with the nature of the interfering magnetic fields, and I doubt the need to turn the boat upside down.

Try the procedure first, then decide if drastic measures are required.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by adafruit_support_mike »

Another common way to calibrate magnetic sensors is to put electromagnets near them in known locations. You don't need anything huge, just open coils with enough current to create a field the sensor can detect.

The simplest arrangment would involve three electromagnets, each controlled at both ends by an H-bridge, located on the sensor's X, Y, and Z axes. The test for each axis would be to run current through the coil one direction, take a reading, then reverse the current through the coil, and take another reading.

You can build the whole system and test it in a location with no magnetic interference, and characterize the readings you get in each direction along each axis.

Once you have that baseline, the difference between the expected readings and the actual readings in a different location can only be the amount of distortion acting on the sensor in that location. The distortion along each axis can be broken down into a scaling constant (caused by soft iron interference) and an offset (caused by hard iron interference).

The whole test and calibration would take less than a second.

User avatar
dlwhitman
 
Posts: 14
Joined: Sun Dec 27, 2020 11:09 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by dlwhitman »

sj_remington wrote: Sat Nov 19, 2022 7:19 pm The quality of the compass has nothing to do with the nature of the interfering magnetic fields, and I doubt the need to turn the boat upside down.
When I bought the compass for my boat, I could use it out of the box, and it was accurate enough to find my way. That makes it a better compass. The standard procedure for compensating a boat compass involves adjusting small magnets that are mounted near, or inside the compass. Additionally, any uncompensated inaccuracies can be corrected with a deviation card, basically a look up table that takes the compass reading as an index and yields the corrected magnetic heading.

Doug

User avatar
dlwhitman
 
Posts: 14
Joined: Sun Dec 27, 2020 11:09 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by dlwhitman »

I don't think I have gotten an answer to my original question, at least not one I understand. Let me ask it another way: When conducting the MotionCal test, and moving the compass around in circles, should the compass be firmly attached to all of the nearby structures (a helicopter for example), so that these structures also go around in circles, or should the compass alone be moved around near the place it is to be mounted?

Doug

User avatar
sj_remington
 
Posts: 998
Joined: Mon Jul 27, 2020 4:51 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by sj_remington »

The standard 2D magnetometer calibration approach, for a mounted electronic compass that does not have adjustable compensation magnets and/or a deviation card, is to rotate the mount (boat, etc.) in a circle, while recording the magnetometer (X, Y) output values. See https://www.vectornav.com/resources/ine ... alibration

If the points from the magnetometer output do not fall on a centered circle when plotted, corrections can be calculated that will remove the offsets and also correct for an elliptical shape. I showed in detail how to do that here: https://forum.sparkfun.com/viewtopic.php?t=36399

The MATLAB code will run on open source GNU Octave. After those corrections are applied, the mounted compass will be fine for boating, or any other mode of approximately level transportation.

In 3D, the equivalent approach is described here: https://www.mathworks.com/help/fusion/u ... ation.html Or use the 3D Arduino and PC C code described here: https://forum.pololu.com/t/correcting-t ... eter/14315 But that is required primarily for tilt-compensated compasses, which include an accelerometer.

User avatar
dlwhitman
 
Posts: 14
Joined: Sun Dec 27, 2020 11:09 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by dlwhitman »

SJ,

Lots of good information here. Thanks. Before I go down the math rabbit hole, I want to make sure I have a good intuitive understanding. My experience sailing adult sized sailboats, leads me to realize that in this modern GPS enabled world, compass accuracy is not nearly as important as it was 100 years ago.

So far, this is my understanding: There are anomalies present on the magnetometer chip and circuit board; they may be very small, but they are very close to the sensor. Mostly, it is these anomalies that MotionCal corrects. It is important that these corrections be done out-of-doors as far from magnetic materials as possible. If it is possible to perform this calibration with the magnetometer installed in its apparatus, so much the better, otherwise there is tweaking to be done later. I am using AHRS, and find it to be amazing, but the output data cannot be more accurate than the magnetometer, gyro, and accelerometer input data (garbage-in-garbage-out). Next, the magnitometer is installed in its vehicle and tested. If it is "good enough", great. Otherwise, further adjustment is needed, either by tweaking the soft and hard iron matrix constants, or by creating a magnetic deviation lookup table. I find the spherical visualization to be quite helpful in understanding what is going on. When the boat is in calm water, the sphere is cut at the z=0 plane. When it is heeled over, some other, less horizontal plane. If the sphere remains spherical, results should be reliable. I am in North America, and was surprised to find the z component was much larger than either the x or y component. I tried reducing or eliminating the z value, and AHRS did not like it at all. I suppose this changes the shape of the sphere.

Am I on the right track? Comments?

Doug

User avatar
sj_remington
 
Posts: 998
Joined: Mon Jul 27, 2020 4:51 pm

Re: Calibrating magnitometer in a 125 pound boat

Post by sj_remington »

You are on the right track, except that MotionCal can correct for major anomalies, too, like having an iron plate within a couple of meters of the sensor, a steel bolt within a few cm, or DC current-carrying cable nearby.

That is why the magnetometer should, if at all possible, be calibrated in its final resting place, using the 3D method. As you point out, rotating a boat through a 3D sphere is impractical, which is why people use the 2D method in such a situation.

Tilt compensation using an accelerometer works very well to counteract errors during heeling, but generally requires 3D calibration of the magnetometer. If you are using 2D calibration and the heeling is short term, no problem -- just take a reading later, when level.

Finally, note that AHRS algorithms make use of vector measurements of the Earth's magnetic field and gravity, which is why 3D calibration of IMUs is absolutely required for reasonably accurate 3D orientation estimates.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”