Compass-Accelerometer calibration

Hallo folks
my name is stefano and I'm working on an self guided robot car.
My objective is to start from point 1 (way point 1 - WP1), point the car to point 2 (way point 2 - WP2), turn 180°, return to point 1. Distance between WP1 and WP2 is 3 meter.

The logic I'm implementing is the following:

  • get lat-lon position
  • calculate the course from current position to way point 2
  • compare robot car heading with course
  • steer to correct direction

The hardware I'm using is

  • ARDUINO MEGA
  • L293d Motor Controller Shield
  • Rover 2 motor
  • adafruit LSM303DLHC compass
  • GPS NEO C94 M8P (high precisione RTK GPS)

All this hardware is mounted as shown in the picture attached.

I'm having a lot of trouble with the compass.
Although I calibrate the compass following the clear preocedure here LSM303DLHC - Calibration, Pitch, Roll and Tilt Compensated Heading - Sensors - Arduino Forum, the reading from the compass is pretty unconsistent.

For example: if I point the robot car to the north and then I turn it 90 degrees est, the reading is 93°. Then if I turn the robot car 90° more, tre reading is 177°. And finally if I turn the robot car 90° more, thereading is 267°.

Can anybody help me to figure out what can be the cause and how to solve it?

Thank you very much for your time

Is the magnetometer physically isolated?

No. It isn't. I monuted the compass on a pole 15 cm above all the electronics. This is alike most other similar project

You haven't posted enough information to determine what is wrong, if anything.

To check whether the compass/accelerometer calibration has been done properly, perform the calibration procedure again, but instead output the corrected measurements and run those through Magneto. If the newly calculated offsets are not zero and the scale factors not 1.0, then you made a mistake.

That said, the very best you can expect using that magnetometer as a compass is +/-1 degrees orientation error, and the error will be MUCH larger if the code does not perform tilt compensation, or the compass is not perfectly level.

A compass error of 1 degree corresponds to 5 cm lateral position error in 3 meters travel.

Please tell us about your setup, and the positional accuracy that you have achieved using the NEO C94 M8P RTK system.

@jremington -- Thank you very much for your suggestions. I run the calibration procedure once more and I moved the car in all directions for 5 mins. I run the combined bias and correction for combined scale factor through Magneto and the newly calculated offsets are NOT zero and the scale factors is NOT 1.0.
I undestand there is a mistake somewhere, but I can't figure it out.

The positional accuracy that you have achieved using the NEO C94 M8P RTK system is 2-4 cm and can be improved more with a better accuracy on the base station

Once the magnetometer is moved from its calibrated position, the calibration is no longer valid.

If 2 magnetometers, with very similar characteristics, were mounted so that the x,y,z axis are 180 degree out of phase with each other, the had and soft errors would be canceled out by summing the 2 readings together; with such a scheme the magnetometers would be self calibrating.

@Idahowalker - Hi and thank you very much for the hint. However it is non clear the math behind this setting.
Let's assume I have 2 identical magnetometer, (A and B). The x axes of magnetometer A points to north and reads 0°. The x axes of magnetometer B points to south and reads 183°. What is the correct reading?
0 + (183 - 180)/2 = 1.5°?

The reading would be the sum of the x axis reading with the top magnetometer x axis being the reference magnetometer. The bottom magnetometer is the calibration reading.

Let's assume that CAL is the reading from the calibration magnetometer and MAG is the reading from the reference magnetometer, then the actual reading is:
MAG+(CAL-180-MAG)/2
Is this correct?

Tks

I run the calibration procedure once more and I moved the car in all directions for 5 mins. I run the combined bias and correction for combined scale factor through Magneto and the newly calculated offsets are NOT zero and the scale factors is NOT 1.0.

Please supply more details. How different ARE the offsets and scale factors? Post the code you are using to correct the magnetometer. Post a screenshot of the Magneto output. Note: five minutes is excessive. At most you need 200-300 data points, distributed fairly evenly in all possible orientations.

Once the magnetometer is moved from its calibrated position, the calibration is no longer valid.

Not always true, but to avoid that situation you should always calibrate the compass in the robot, with the robot power on.

If you do that correctly, using an additional magnetometer is just a waste of time and effort.

jremington:
If you do that correctly, using an additional magnetometer is just a waste of time and effort.

Not if the robot is of significant size, or weighs more than 10kg

I follow the process and code highlighed here

https://forum.arduino.cc/index.php?topic=265541.0

The Combined bias I get is:
X=-6588.3987723
Y=14389.177118
Z=324.739276

The correction for combined scale factor, misalignment and soft iron is

1.046031 0.009010 -0.009041
0.009010 1.041075 0.005489
-0.009041 0.000598 0.969507

The evaluation of the calibration process return this data

The Combined bias:
X= -234.057417
Y= 133.781707
Z= -138.923487

and the correction for combined scale factor, misalignment and soft iron is

0.995784 -0.000907 -0.001055
-0.000907 1.002600 0.002456
-0.001055 0.002456 1.004587

The robot car is a small device less the 2 kg

Not if the robot is of significant size, or weighs more than 10kg

A friend of mine worked on a very large oceanography research vessel with 500 scientists and crew aboard.

To calibrate the SINGLE magnetometer used for navigation, the captain used the thrusters to rotate the entire vessel in a circle, twice. The procedure worked very well.

What good does a second magnetometer do, except possibly to inform you that you can't believe either reading?

The evaluation of the calibration process return this data

The Combined bias:
X= -234.057417
Y= 133.781707
Z= -138.923487

The scale factors are probably OK, but the bias correction is obviously not, especially the Z correction, which is about the same size before and after calibration. What changes between calibration runs?

NO changes

stefano_uffreduzzi:
NO changes

Normally-open changes?

Changes what?

To be more clear after the calibration process I amend the code with the result from Mangneto and I run the evaluation process. The results I obtain are in my previous post.

Something changed, or you are applying the calibration results incorrectly.

Given the microscopic amount of information you have provided, we are in no position to guess what the real problem might be.

jremington:
Something changed, or you are applying the calibration results incorrectly.

Given the microscopic amount of information you have provided, we are in no position to guess what the real problem might be.

I really want to collaborate and provide all information you need to help. Nor I'm lazy in this. I'm new to arduino problem solving, and I understand I need help also on this.
I have the suspect i'm not applying the calibration result correctly. Do you suggest to print a screenshot of the magneto results and how I apply the numbers in the scketch?
Or can you please tell me what type of information you need?
I attached a picture of the robot car
Tks

jremington:
A friend of mine worked on a very large oceanography research vessel with 500 scientists and crew aboard.

To calibrate the SINGLE magnetometer used for navigation, the captain used the thrusters to rotate the entire vessel in a circle, twice. The procedure worked very well.

And the Z axis?