Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone compass tilt compensation

has anybody already programmed a iphone compass heading tilt compensation?

i have got some approaches, but some help or a better solution would be cool!

FIRST i define a vector Ev, calculated out of the cross product of Gv and Hv. Gv is a gravity vector i build out of the accelerometer values and Hv is an heading vector built out the magnetometer values. Ev stands perpendicular on Gv and Hv, so it is heading to horizonatl East.

SECOND i define a vector Rv, calculated out of the cross product Bv and Gv. Bv is my looking vector and it is defined as [0,0,-1]. Rv is perpendicular to Gv and Bv and shows always to the right.

THIRD the angle between these two vectors, Ev and Rv, should be my corrected heading. to calculate the angle i build the dot product and thereof the arcos.

phi = arcos ( Ev * Rv / |Ev| * |Rv| )

Theoretically it should work, but maybe i have to normalize the vectors?!

Has anybody got a solution for this?

Thanks, m01d

like image 254
user302606 Avatar asked Mar 27 '10 15:03

user302606


People also ask

What is a tilt compensated compass?

A tilt compensated electronic compass system requires a 3-axis magnetic sensor and a 3- axis accelerometer sensor. The accelerometer is used to measure the tilt angles of pitch and roll for tilt compensation.

Does iPhone compass adjust for declination?

Pro Compass for iPhone In all display modes, Pro Compass shows both magnetic and true direction simultaneously, with a rotating outer true ring that is automatically adjusted for local magnetic declination. Sun and Moon position are marked on the compass rings and continually updated.

Does iPhone compass give True North?

Once the compass has been calibrated, the compass at 0 degrees will point to magnetic north — this differs from True North. If you want your iPhone's compass to always point to True North, you can change it by going to Settings > Compass > "Use True North."


2 Answers

Yep. You DEFINITELY have to normalize. This is from my code that I use to extract the orientation of the device. Gravity is obtained as the x,y,z of the accelerometer and compass is obtained from the x,y,z of the heading function

gravity.normalize(); compass.normalize(); compassEast=gravity.cross(compass);
compassEast.normalize();
compassNorth=compassEast.cross(gravity); compassNorth.normalize();

Let me know if you need the full code. Also, for those who havnt yet seen the iphone 4s gyroscope in action: its amazing! I swapped the above input to gravity and compass for the equivalents from the gyro and the result is stable and smooth and awesome :) Go Apple.

like image 50
twerdster Avatar answered Oct 01 '22 23:10

twerdster


I didn't receive the source code but I set up my own example. You can see the project and code here: http://www.sundh.com/blog/2011/09/stabalize-compass-of-iphone-with-gyroscope/

like image 25
Ellen S Avatar answered Oct 02 '22 00:10

Ellen S