How to use cal data from MagCal/Magneto into AHRS

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.
Regards
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, diydrones.com/profiles/blogs/adv … 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.
Regards
Kevin

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).
Regards
Kevin

EDIT, 1 data should have been a positive on first raw reading, now corrected
KEVIN’S, 3 X IMUV3 RAW DATA AND AHRS HEADINGS.xlsx (16.8 KB)
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.

Kevin
PS, I would have thought a bright boy like you would have seen the data was correct, but for the heading error formula.
KEVIN’S, 3 X IMUV3 RAW DATA AND AHRS HEADINGS.xlsx (16.7 KB)

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.
Regards
Kevin
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)
Regards
Kevin

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.
[/quote]

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.
[/quote].
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.
Regards
Kevin

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.
Regards
Kevin
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;
#if PRINT_ANALOGS==1
// Serial.print(",AN:");
//Serial.print(AN[0]); //(int)read_adc(0)
// Serial.print(",");
// Serial.print(AN[1]);
//Serial.print(",");
//Serial.print(AN[2]);
// Serial.print(",");
// Serial.print(AN[3]);
//Serial.print (",");
//Serial.print(AN[4]);
//Serial.print (",");
// Serial.print(AN[5]);
Serial.print(c_magnetom_x);
Serial.print (",");
Serial.print(c_magnetom_y);
Serial.print (",");
Serial.print(c_magnetom_z);
#endif
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?
Regards
Kevin
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

Hi Kevin C, yes l now see what you say about Z, I have done nothing different in the following apart from l have gone out to my front yard again, closest thing metallic >10M apart from laptop at >3M and mega at<1M. l have attached old b IMU, done out in the open. 1 is done moving in the open air where calibrated, the other is on the ALL wooden compass rose. Z are in spec, still way of centre though.
Could you please also answer questions asked previously.
Regards
Kevin

[quote=“kevin1961”]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 be 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.[/quote]
old b, outside in air.xlsx (45.2 KB)
old b, outside on compass rose, by trees front yard.xlsx (194 KB)

Hi All, compass heading done on ALL wooden Compass Rose, Mag N approx by yacht hand held compass. Done as per previous post in front yard. Between +12, -9 to compass headings.
Regards
Kevin
old b, COMPASS HEADING ,outside on compass rose, by trees front yard, .xlsx (9.67 KB)

Hi, Kevin.

It looks like your two most recent plots are better centered around the origin, though I can see that they are still not quite circular. The raw values and your calibration constants seem reasonable to me.

We have not characterized the properties (linearity, heading accuracy, etc.) that you asked about previously. Our MinIMU and other similar boards are primarily intended to be carrier boards to make the sensor chips easier to interface with, and we make an example AHRS program available in the hopes that users will find it helpful as a starting point, but it might be that you are looking for better performance than the software or the sensors themselves can provide. You might get better results with a different calibration method or AHRS implementation (some of which Jim has touched on, and some examples can be found on the Resources tab of the product page), but we don’t have any specific recommendations about those.

- Kevin C

Hi Kevin C, l have re down loaded RTIMUlib and now it has compiled l was able to do another set of data.
This was done outside, calibrated using ArdunioMagCal and saved to eprom. Compass readings done as others with mag N via yacht hand held compass an nearest metal >4M away.
-7 to +10 error which is slightly better than previous.
I have also included (something you would be aware, but don’t really won’t shown l imagine) your competitors BNO55.
I was hoping you would have been able to some how correct the large errors from the V3 (l now you don’t make the chips), as you can see the BNO55 are near perfect including tilting 30 degrees left and right.
Thank you for your time, even if the reply’s were very slow in coming.(were as Jim’s (thanks Jim)were very quick and helpful).
Regards
Kevin D
Kevins_ BNO055 and IMUV3.xlsx (14.4 KB)

The comparison with the BNO055 is interesting; thanks for sharing it. Given the difference in price, I wouldn’t be too surprised if it is inherently a better-performing part than the sensors on the MinIMU, and if you like the results you are getting from it, great.

We would like to look at providing better software for our IMUs, and it would be nice for it to eventually have an easier and more accurate calibration process, but it is not something we are currently focusing on.

- Kevin C

Hi Kevin C, I appreciate your honesty about other IMU’s. Re pricing there is no difference down here, at about $55 Aust each and l ended up buying 4 xV3. One thing that l hadn’t done which could make a difference is to do the RTEllipsoidFit but l see this is in Lib 2, and l could not get it to compile (know l now why this lib compiled as it was for Ardunio, but it doesn’t have RTEllipsoidFit) and l didn’t do the Accl cal thingy as l don’t understand it. If you get the time you could use both and show that your results are much improved and that l have been unfair in my comparison, please do.
Regards
Kevin D