# 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:

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
Still not got 100 % will try reading again

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