I search a way to detect the movement of the phone regardless how the user holds the phone.
Some examples:
The background is that I want to recognize if the user pulls the phone out of the pocket (like pulls 30-40cm up and also some centimeters horizontal).
I think therefor I have to get a combination out of the userAcceleration and the attitude. But I did not find the correct maths..
Not sure what you mean by "correct maths". But I would read out the accelerometer and sum up the absolute value for all 3 directions (x/y/z). This would give you a single number for the acceleration, independent of the orientation of the phone or the direction of the movement.
Even better would be to calculate the RMS acceleration, i.e. sum the squares of x/y/z acceleration and calculate the square root of the sum.
The obvious drawback of this method is that it gives you no information on the direction of the movement. You might add some threshold or filtering to distinguish a single linear movement from shaking (e.g. by measuring the time between two acceleration events).
Additionally, you could determine the change of altitude (this is independent of the phones orientation) although I doubt whether a difference of 30 ... 40 cm can be measured precisely enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With