How to use cal data from MagCal/Magneto into AHRS

The navigational problem with the southern hemisphere is that the sun is in the North.
Confuses the hell out of me!

All right for you guys standing on the top of Earth, down here we have to grip it with our toes. Sun rises in the West and sets in the East,silly billy.(you are if you believe that)

Hello Pololu, are you able to add any insight to this conversation, it is your product.

Hi, Kevin:

It is not clear to me that you have correctly used Pololu’s method of calibrating the magnetometers. This procedure should work reasonably well in most cases. However, you mention that all four magnetometers “show nonlinearity”, which suggests that you may be doing something wrong.

If you want help from the Pololu engineers, I suspect that they will ask you to

  1. document how you are doing the calibration,
  2. show what the correction constants are,
  3. show how you have modified the MiniIMU-9 AHRS program to reflect those constants, and
  4. show plots or tables of the before and after calibration response of all four of your sensors.

In any case, I would like to see those numbers and results.

With the data you kindly posted, I’ve done a fair bit of work with one of your sensors and have shown that with proper calibration, it has acceptably linear response and is capable of providing headings accurate to 3 degrees or better.

I doubt that you will get headings more accurate than +/- 1 degree with any consumer grade IMU currently on the market, even with careful calibration.

Hi Jim, re calibration, l have done as suggested by Pololu, painting the inside of a sphere, l also added when this was not working well, painting the outside at the same time.Using there cal code,taking the max/min numbers and placing into the AHRS code.
I also read were it was suggested you should keep any lateral movement to the min, so accelerometers don’t read to much and rotate the imu around it’s axis. Tried that and Min/Max into the AHRS.
Constants? are these the Min/Max, that is all l have done.
Then tested with the AHRS with the results non linear and Tilt changing the headings up to +10 -10 degrees manly on Westerly headings, there was 0 to ±4 degrees on other headings. Mag N with no Mag viaration applied, approx 17 degrees (we should be add a further +14 East).
Attached 2 other sensor raw data. 1 doesn’t look to bad but still aren’t linear and tilt issues
I hope you get some sort of remuneration from POLOLU as they have left this one to you.
imu pololu forum.xlsx (13 KB)

The data from the second sensor look beautiful. If the Pololu calibration method doesn’t work for that sensor, you are very clearly doing something wrong.

However, you haven’t provided enough information for anyone to figure out what that might be.

Hi Jim, that was a bit of a trick, wrong data (copied from wrong sheet). That was a V3 done in the Northen Hemisphere. 1 extra attached (as you can see it is also on an incline . Will get to do a new set of data today.Will also try and do calibrated data but it will be 1 sample unless you can show how to do averaged sample in AHRS. Guru jack had altered the cal code to do raw averaging.
KEVINS IMU for forum.xlsx (14.6 KB)

Hello, Kevin.

It seems like Jim is probably at least as knowledgeable on this topic as any of us at Pololu, and he has already provided a lot of good information and analysis in this discussion (thanks, Jim). If you’re still trying to get the simple min/max calibration in the MinIMU9AHRS program working, then I agree with him that it would be helpful to see the constants you got from the Calibrate example to check that they make sense. We should also verify that you are using them in the MinIMU9AHRS program correctly: you should have replaced the values starting on line 70 of MinIMU9AHRS.ino with your own values.

Have you made any significant changes to other parts of the program that you are currently using? If so, it might be a good idea to try again with the original, unmodified program (but with your own calibration constants filled in) to make sure your other changes aren’t causing problems.

- (another) Kevin

To another Kevin, Hello to you and Pololu. The min/max are as follows. Old =first parts order, new=latest parts order.
Old A, -3665, -3355,-3736, 3286,3182,2852
Old B, --4170,-3969,-4293, 3745, 3844,3065
New A, -3141, -3494,-3523, 4546,4185, 4249
New B,-3251,-3143,-3038, 3677, 3606,3564
Measurements taken outside away from any interference, being the lap top at about 1 to 1.5 M away, but l can see when testing there is no change in the reading from the laptop at this distance.
AHRS code example below

// LSM303 magnetometer calibration constants; use the Calibrate example from
// the Pololu LSM303 library to find the right values for your board
//new “B”
#define M_X_MIN -3251
#define M_Y_MIN -3143
#define M_Z_MIN -3038
#define M_X_MAX 3677
#define M_Y_MAX 3606
#define M_Z_MAX 3564
The AHRS is not altered in anyway.
I haven’t sent any more raw data as l need to get some connection joiners so l can change over the IMU’s easily.It is about an hours drive to town and haven’t needed to travel in just yet. Will be doing them by Monday hopefully.
I am thinking it has to do with the limited magnetic field down here, as we are 71 degrees pointing up.
I have tried the IMU with silk screen down with orientation changed, but have not changed/tested using other axis, if it would make a difference.
Do you think using any altered matrix instead of min/max would make a difference?
You suggest to do it like Sail Instu blog, but no one will give or show a code or alterations that are required to enable this.
I started on a nill knowledge base on this about 4 weeks ago and have been reading/researching this topic and now have a better understanding of what the go is.
All over the internet people talk about using MagCal/Magneto type cal formulas, but no one shows how to do it,but for
Yury, … or-dummies.
But the viewer wouldn’t work so l couldn’t see the results with the 3D on the HMC5883L to see if it made any difference, because it also won’t play the game down here.
My code writing is very limited but getting better with playing, but it is way beyond me to adapt AHRS to the Yury type matrix, if it even can be. I could play and alter his code to show compass heading which would then confirm if it made a difference to the compass heading, but l haven’t got to it yet.Hoping you can a) show me were l am going wrong, b) alter the code to enable better calibration.
Regards Kevin in Tasmania

Hello again Kevin, could you please say what you believe is the best results the V3 will do.
Linearity, how accurate around the full 360 degrees.
Magnetic North, how accurate to Mag North, (±variation)
Repeatability, how close will it give of the previous reading, after power ON/Off a few times.
Roll/Tilt, how much should the compass heading change over a horizontal reading to say 30 degree tilt left/right.
All of the above are an issue with the V3 and me.

Hi, Kevin:

Are the “B” sensor data in the latest spreadsheet you posted?

You can test the results of applying the corrections yourself, by putting the B sensor min/max values into the AHRS program and while it is running, rotate the B sensor around on the platform you’ve built.

Please post a table of the platform headings and the AHRS heading values.

Hi Kevin and Jim, attached is spread sheet showing 3 x IMUV3 raw data and AHRS with IMU calibration corrected MIN/MAX data, showing compass headings. You can see how far off they all are.All info is recorded on spread sheet.
Also attached a photo of the set up (in Word, as they were to big,even in PDF, (can someone will tell me how l can do it please).

EDIT, 1 data should have been a positive on first raw reading, now corrected
imu1.docx (761 KB)
imu2.docx (423 KB)

Hi, Kevin:

It is impossible to have a heading error greater than 180 degrees, so could you correct your spreadsheet to list in two columns the platform/compass rose headings and the corresponding AHRS heading (instead of heading error)?

Thanks, Jim

Edit: never mind, I corrected the heading errors and did plots for A and B versus the compass rose. As you can see, they aren’t bad.

Cheers, Jim
KEVIN_heading_error_corrected.xlsx (13.1 KB)

H Jim, that heading error is just my basic formula not liking the different format of the AHRS, it is because the AHRS gives it in ± 180, so l hadn’t gone and corrected the heading error, not that there is anything wrong with the data.
But l have now manually corrected the heading error, so don’t use the error formula. The compass rose and AHRS headings are correct.

PS, I would have thought a bright boy like you would have seen the data was correct, but for the heading error formula.

Hi Jim, saw you had done the corrections after posting (of course you are a bright boy, ha ha) .
I would have thought a difference of the IMU below, wouldn’t have been classed as "aren’t bad"
You want to see the reading when you put some tilt on the Westerly (new A/B) heading. 30 degree Left or Right can go ±10 degrees and Easterly for Old B on on top of the the non linear readings. They can also be better or worse depending on how they feel.
Even just putting a halving correction to the headings still doesn’t give a pretty picture, unless you are doing something a lot smarter than that?
New A) -8 to 14 error.
New B) -6 to 15 error.
Old B) -10 to 15 error.
Edit— l on purpose did not change the AHRS headings to full 360 reading, so that the question of whether l had played with the AHRS code because it wasn’t showing headings in ± 180 could arise.Just trying to keep to the facts.
Thanks Jim l now see the formula for the ±180 correction, not that l was going to use it re above.
Looking at your graph, still doesn’t change that if you go from 0 to 30, it has picked up and additional 9-14 in only 30 degrees, or l am missing something here?
Liking this edit biz, as most forums turn it off, so l can fix my poor grammer (maybe)

Hi, Kevin:

I don’t think there is any problem with the sensors or the AHRS program.

I do think there is a problem with the way the sensors are mounted, as some of the raw data from your turntable clearly show “glitches” (not normal sensor noise) and probably, the min/max values are not the best either. Those need to be collected by rotating in 3D anyway, and not on a turntable.

If you are still using long wires to connect the sensors to the Arduino, that is definitely, now or in the future, a problem. Connections for I2C signals are not intended to be longer than a few cm at most.

One way around the glitch problem (for now) is to collect a lot of data for calibration and reject the outliers.

Hi Jim,

Remounting, the sensors are taped to a piece of wood, which is rotating around a stainless screw.I have tried mounting the sensor to the wood with a cable tie, just in case there was pressure exerted onto the chip which was causing the inaccuracy, but it made no difference.

[quote=“Jim Remington”]as some of the raw data from your turntable clearly show “glitches” (not normal sensor noise[/quote].

What is the glitch you are talking about? If that is the changing Z value, that is because the ply compass rose is slightly warped so the imu is not rotated at a dead flat horizontal.

What values would you expect ?My values are higher than a correctly working unit in the USA. Could you suggest a better method of cal, as far as l can understand l am doing additional movement of the IMU than POLOLU suggest, as stated in pre posts.I am NOT taking min/max from horizontal rotation of the IMU around the compass rose.

[quote=“Jim Remington”]If you are still using long wires to connect the sensors to the Arduino, that is definitely, now or in the future, a problem. Connections for I2C signals are not intended to be longer than a few cm at most.

l have already shortened the cable to <2M. I could of course shorten that further but arn’t we then bringing interferance from the mega? Also l believe l can shorten it to 1 cm and l bet the reading don’t improve I will do that so it can be proven 1 way or the other. The sensor is working all right in North America on 8M of flat core cable

[quote=“Jim Remington”]One way around the glitch problem (for now) is to collect a lot of data for calibration and reject the outliers.
Will take more readings in different locations around the property, but that isn’t going to help if l mount it in a boat.
Jim, thanks for your continued interest.

Hi All, 4 more lots of raw data for 2 x IMU’s, 1 inside my workshop with lots of metal and power within <1m.
The others l have changed to a flatter compass rose and have just rotated the IMU around the centre of the compass rose, of course it is not without a bit of jerking in the process (this isn’t a laboratory, ha ha)
As you can see not good, this is now in my back yard, metal trailer at about 4M . Cable between IMU and Mega <500mm.
I haven’t been able to do any AHRS compass headings as the AHRS just stops after 1 heading as says it can’t add up floats or the like, it was doing this yesterday, ever now and then with a longer cable>3M,and with a longer 1 again, 8M it never did it. This maybe do to everything is in the sun, but raw data still coming into serial , just the AHRS locking up.
As an aside, I have now learn’t how to copy mass data into separate columns in a spread sheet, wow, that’s easier than writing all the data in like l was up until today, one reason l had enough of getting data.
test outside.xlsx (47.2 KB)

Hi All, l have attached a print out of the AHRS corrected(hopefully) data of IMU New A, Calibrated then rotated around the compass rose. As you can see the MIN/MAX hasn’t centred the data, but please correct if l am not looking at this the right way.

// adjust for LSM303 compass axis offsets/sensitivity differences by scaling to +/-0.5 range
c_magnetom_x = (float)(magnetom_x - SENSOR_SIGN[6]*M_X_MIN) / (M_X_MAX - M_X_MIN) - SENSOR_SIGN[6]*0.5;
c_magnetom_y = (float)(magnetom_y - SENSOR_SIGN[7]*M_Y_MIN) / (M_Y_MAX - M_Y_MIN) - SENSOR_SIGN[7]*0.5;
c_magnetom_z = (float)(magnetom_z - SENSOR_SIGN[8]*M_Z_MIN) / (M_Z_MAX - M_Z_MIN) - SENSOR_SIGN[8]*0.5;
// Serial.print(",AN:");
//Serial.print(AN[0]); //(int)read_adc(0)
// Serial.print(",");
// Serial.print(AN[1]);
// Serial.print(",");
// Serial.print(AN[3]);
//Serial.print (",");
//Serial.print (",");
// Serial.print(AN[5]);
Serial.print (",");
Serial.print (",");
Jim, l just re read your last post, when you are talking re Cal, are you saying to print all the cal max/min then cull out any that look onerous and then use the resultant min/max. So you need to do the data manually?
New A, calibrated, outside.xlsx (76.5 KB)

For debugging purposes, it might be useful for you to print the raw readings as well (magnetom_x, y, z). It doesn’t look like the readings are being adjusted very well; the plot in your latest spreadsheet is noticeably off-center. The Z axis values look especially strange - they’re outside the range of -0.5 to +0.5 that they should be in.

Just to check whether your turntable setup is interfering with the readings, could you also try printing out (raw and corrected) AHRS data from rotating the IMU around in the same environment you calibrated it? (In other words, if you calibrated by holding the IMU while standing in the middle of a room, try getting some AHRS data from holding the IMU and turning it in a circle in the same place. I would expect the calibration constants to work well in that case.)

- Kevin C