Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect movement regardless device rotation

I search a way to detect the movement of the phone regardless how the user holds the phone.

Some examples:

  • I am interested in the vertical movement (like the user pulls the phone up) 'ignoring' if the phone lays on the table or held in the hand (maybe upside-down).
  • Also interested in the horizontal movement (like the user pushes the phone away from the body) also 'ignoring' how the user helds the phone.

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..

like image 916
Thorsten Avatar asked Sep 12 '14 10:09

Thorsten


1 Answers

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.

like image 57
Chipmuenk Avatar answered Oct 13 '22 19:10

Chipmuenk