Tilt compensation for Compass

Pardon me for this basic question.
I have a query that why tilt (measured by accelerometer) is required if I am making compass.
Whats the Physics behind it.

I am developing a mobile application to get the orientation of device using magnetometer.

Thanks
chits

Hello.

I think it’s more a geometry issue than a physics issue. 3D geometry with various perspectives thrown in is confusing, so it’s nice to have props as you’re thinking about this. Here are two examples where you can see that the tilt of the compass matters:

The earth’s magnetic field is not parallel to the ground everywhere. If you imagine yourself to be the compass, the direction of your torso to be the direction we care about, and your arm to point in the direction of the magnetic field, the answer we typically want from a compass is the angle from your torso to your arm when viewed from above. If you face north, you would point straight ahead, but because the field is not parallel to the ground, you might be pointing partly up or partly down; whatever that level of offset from horizontal, you can easily still see that the angle we care about is zero degrees. You can wave your arm up and down to have a good idea of the whole plane that is running north and south. If you now turn 45 degrees but keep waving your arm in that same plane, you can see that the angle from your torso to arm is 45 degrees the whole time, and you could report that your heading is 45 degrees from north. However, if you now tilt the plane you are in, you will see that you have to change the motion of your arm to keep it in that north/south plane, and that angle from your arm to torso is now changing where before it stayed constant. Conversely, you could keep pointing at one angle and roll your torso, and you’ll see that the angle changes even though your heading is 45 degrees the whole time. If you have trouble with the literally hand-waving approach, you can hold two PC boards along an edge with some angle between them or open a hardcover book. One PCB or cover would represent the north-south plane, and the other the direction of the compass. If you now tilt the book while keeping the angle between front and back cover the same and while pointing the “direction” cover in the same direction, the other cover won’t be able to stay in the north/south plane.

Here’s a different kind of case to consider. Imagine you are moving your compass around a field line that is parallel to the ground, and that you are keeping the compass tangent to a cylinder around that field line such that your Z-axis magnetic reading is always zero. You can have a whole set of 3D orientations where the X and Y readings are the same, but you might not want to call the heading the same for all of those cases.

Some of what it comes down to is that if you want an answer relative to some coordinate system, such as an angle within a plane parallel to earth, your sensor needs to be able to measure the magnetic field relative to itself and its own orientation relative to your reference. For the most extreme case, just consider flipping over a regular mechanical compass (without any tilt-compensating gimbal mechanism): east and west will be flipped because the compass is now not aligned to the reference system you expect.

- Jan

Thanks Jan,

3D geometry is a bit confusing, I have to read 2-3 times more to understand :slight_smile:
Still not got 100 % will try reading again :slight_smile:

Ok If I get tilt from gravity = 30 degree.
If Compass is showing 60 degree (0 is N and 90 is E) with a tilt of 30 deg from gravity.
What formula to be applied to correct the compass reading.?

Compass here is magnetic north, later we need to correct again by adding/subtracting offset
based on geographic location.Correct?

I do not have any experience with the actual calculations. It looks like there are many relevant results if you look for something like “magnetometer tilt compensation”. By the way, I don’t think you get to start with “compass is showing 60 degrees”; rather, you have the three readings for the three magnetometer axes and the three readings for the accelerometer axes, and you need to combine all that to get your answer as a single heading number. And yes, you would have to compensate for the magnetic north/geographic north difference at your location, too.

- Jan

Agreed, basically first roll & pitch needs to be calculated from ax,ay,az(accelerometer data).
I googled and their seems to be algos for calculating these angles.yaw(rotation arnd z axis is not required i guess).

Then use these roll & pitch angle to get Mx’,My’,Mz’ from Mx,My&Mz and finally calculate azimuth angle.

Lastly add the difference(magnetic declination) between true north & azimuth (either by GPS or lookup table).

Here is what I am referring to , for everyone reference I am posting weblinks

Calculating Roll & pitch from Accelerometer values : freescale.com/files/sensors/ … AN3461.pdf

Calculating Azimuth(magnetic north) using roll /pitch & Magnetic values along all 3 axis.
ssec.honeywell.com/position- … ts/sae.pdf
diydrones.ning.com/profiles/blog … ed-heading

Finally to get True North.Based on geographical co-ordinate , use GPS or web service like
ngdc.noaa.gov/geomagmodels/s … eclination
to calculate declination at that place.

True North =
if(value is EAST)
add up the value from azimuth calculated above
if(value is WEST)
subtract the value from azimuth calculated above.