Calibrating compass other brand 10DOF IMU

Aloha –
I have an Adafruit 10DOF IMU breakout (https://www.adafruit.com/product/1604) whose compass I am trying to bring back into calibration (reads 30degE from S). The board is pop’d by L3GD20H, LSM303, and BMP180 sensors. The board’s tutorial is located here (https://learn.adafruit.com/adafruit-10-dof-imu-breakout-lsm303-l3gd20-bmp180?view=all) and library links here (https://learn.adafruit.com/adafruit-10-dof-imu-breakout-lsm303-l3gd20-bmp180?view=all#software). In the Adafruit library for the LSM303 is a calibration sketch for obtaining min/max values. The tutorial (https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout/calibration) for the LSM303 states, [quote]The values displayed will be the the min and max ranges for each axis and can be used to re-scale the output of the sensor[/quote]And that is it. No further explanation. I have pored over the library files in search of somewhere these values are inserted, to no avail (my knowledge and experience being the limiting factor). On the other hand, this Pololu LSM303DLM (https://www.pololu.com/product/1273) is accurate (+3degE) as standalone with it’s default values. Once placed on a board, in a robot chassis, the compass is still easy to swing (https://github.com/pololu/lsm303-arduino/blob/master/LSM303/examples/Calibrate/Calibrate.ino) and gives comparable readings with the new min/max values placed in a subsequent sketch.
I am going to delete and re-populate the Adafruit libraries in the sketch folder and see how far that gets me. What is daunting to me is that Adafruit proffers their “unified” libraries. Failing that I want to try the Pololu libraries. Has anyone had any experience in these matters, and is willing to share, thus saving me some headache? I would like to put this board into service.
Mahalo,
Mark

For best results (and sometimes for any results at all) magnetometers must be calibrated in their final location. For the LSM303 series, Pololu engineers offer a number of resources showing how to calibrate the magnetometer and to use the results to make an electronic compass. pololu.com/product/1273/resources

Study them carefully, in particular the application note from ST and the sample Orangutan project (which is a simplified version).

The most accurate method for constructing the correction matrix is presented here: sailboatinstruments.blogspot.com … ation.html but that level of detail is often not necessary.

I looked through the Adafruit code for their 10DOF IMU and also could not find anywhere that a magnetometer offset and gain correction was applied. Perhaps the programmer doesn’t understand how to do it properly.

As an aside, the Adafruit folks seem to make reasonable efforts at the very basic educational level, but often drop the ball when the situation becomes more technically demanding.

Aloha Jim and thank you for your kind reply–

I have a couple Pololu LSM303DLMs, and not gotten too heavy into them after I found relative success swinging them in situ. I would like to move forward with the Ada 10DOF.

Searching the Ada forums I found two instances where moderators avoid answering the same question I pose here, what to do with those min/max values. Also seems the Pololu name was used often.

In my previous life, it used to be pull a chart, get some line-ups, go offshore on a calm day, …

If you are still confused about what to do with the min and max values, it is pretty simple. Suppose you determine Xmin and Xmax from a bunch of X magnetometer readings. In order to calculate a bearing, the readings must be centered on zero, but if Xmax is not equal to -Xmin, they are not. For any given raw reading, the zero-centered corrected value is figured by subtracting the average:

Xcorr = Xraw - (Xmin+Xmax)/2

If you measure Ymin and Ymax for the Y axis and the difference (Ymax - Ymin) is not the same as (Xmax - Xmin), there is also a relative gain error. To put the Y axis on the same relative scale as the X axis (also required for bearing calculations) you need both corrections as follows:

Ycorr = Yraw - (Ymin+Ymax)/2
Yscaled = Ycorr*(Xmax-Xmin)/(Ymax-Ymin)

The magneto method on the sailboatinstruments site also takes into account the case that iron objects or electrical currents are distorting the readings and/or are generating a cross-correlation between axes.

Jim –
From Ada Support:

And those referenced posts are a bit tedious for a bear with a small brain.

I can’t really imagine why Adafruit engineers have no time, or the understanding, to include the 3-4 extra lines of code in their product. “Brand X” I suppose, except in this case, not a bargain. Pololu deserves our support!

Typically when the bank statement arrives I can anticipate hearing from somewhere in the house — “Pololu!”

As an aside:

[quote]Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
[/quote]

6 DOF’s down, 4 DOF’s to go.

Re-populating my libraries with the latest Ada 10DOF libraries, some of which Github listed as being only 7 days old, I consistently received over Serial the error,

Commenting out that chunk initSensors() routine, Serial spat out headings 27 deg E of S. So, I tossed 'em out again.

Ran and got new min/max corrections from the Pololu Calibration sketch. Dropped those into the Pololu Heading sketch, and obtained headings comparable to Silva and Raytheon hand compasses. A degree or two off on cardinal points, that is what I get from a Pololu LSM303DLM with default min/max’s.

I am achieving +/-3 deg on cardinal points (too fragged to box it), mounted in situ. I could probably do better in the calibration exercise. Dropped the values into the bot’s sketch, and ran it, motors whirring, sensors sensing, blinkies blinking. I am pleased with the 3 degrees off at this point. Occasionally there is an outlier printed. But, really, at this point…

Comparing the c++ files of the two libraries, I found Pololu’s to be well commented and very informative. Jim’s explanation above is also well commented in the library.

So, actually, I have 12 Dollars Of Freedom to figure out, 'cause, you know, freedom isn’t free.

photo of Jade Wabbit attached.