Are there any good examples for how to use the accelerometers in iPhone OS?
-
05-07-2019 - |
Question
I think that there are some issues with the earth Gravity, so I wonder if there are any examples where the accelerometers work by subtracting these.
Solution
(It's too bad you can't file a bug with planet Earth to fix its Gravity issue!)
There are several examples listed under "Related sample code" in the UIAcceleration Class Reference.
As that doc states, a value of 1.0 represents roughly +1g. So if you point the iPhone straight up in portrait orientation, you should see roughly <0, -1, 0>. As you rotate the phone around, the magnitude of the acceleration vector sqrt(x*x+y*y+z*z)
should stay around 1.
OTHER TIPS
Apple's AccelerometerGraph demo includes sample code that implements a high-pass filter-- effectively filtering out the effect of gravity. It's pretty simple to just grab it and modify to suit your needs.