2

I almost read every single question here about vertical movement but I couldnt get an exact conclusion and idea. Because most of the questions are about game programming where a lot of noise, rotation etc are involved like this one or this one.

My question is quite simple. I only want to detect up and down movement (true or false, no measurement). I don't care about if portrait or landscape mode or rotation. I only want to know if user is moving phone up or down. For example; I want to detect pull up movement. I put my phone in my pocket and do pull ups. Is it even possible? How accurate can it be and which sensors should I concentrate on?

Emil
  • 6,411
  • 7
  • 62
  • 112
  • This should be entirely achievable using the accelerometer. Just check if it gives alternating values. What have you tried? What didn't work? – Carcigenicate May 25 '17 at 12:38
  • @Carcigenicate I tried accelerometer only but I cant understand the changes of Y axis (I believe this is the one I need to concentrate on), Change is very minimal and sometimes goes minus, sometimes up. quite wavy. I thought that I need to combine with gravity somehow, no? – Emil May 25 '17 at 12:50
  • using accelerometer you can determine the linear acceleration in any specific axes, i.e in X,Y and Z axes – Debu May 25 '17 at 12:50
  • @batmaci Don't care about which axis it is, since the person could hold the phone any way. Look for acceleration in any axis, and count a change as 1 rep. And take the absolute change (using `Math.abs`) so you dont need to deal with negative numbers. – Carcigenicate May 25 '17 at 12:53
  • @Carcigenicate Is it even more accurate the use Linear accelerometer? I read that it reduces noise from accelerometer and you get more accurate change – Emil May 25 '17 at 12:55
  • @batmaci Never used it, only the accelerometer. – Carcigenicate May 25 '17 at 12:56
  • Have you tried plotting the X,Y,Z acceleration data on a graph whilst doing pullups? If there is a clear pattern or spikes in the data then you can make an app that detects that pattern/ acceleration impulse (in any axis). – Aaron Thompson May 25 '17 at 13:00
  • @AaronThompson Indeed i did and I couldnt any conclusion because my problem was I wasnt sure which change was up or down. because I cant count every change as 1 rep like Carcigenicate said. It should be only Up movement is 1 rep. I will try it again and update my question with some values of changes on axises – Emil May 25 '17 at 13:07

1 Answers1

2

This is actually much more difficult than you might suppose.

The phone's gyroscope sensors give you the movement of the phone with respect to the phone, not the world. Leaving the phone face-up, flat on the table would give you

  • x = 0.0,
  • y = 0.0,
  • z = -9.8.

These values would be fluctuating slightly due to the sensors. As the phone rotates, these base (at rest) values change - at 45 degrees you get

  • x = 6.93,
  • y = 0,
  • z = 6.93,

so that sqrt(x*x + y*y + z*z) = 9.8. If you want to isolate up-down movement, you either have to stop the phone rotating, or ignore this movement.

If you stop the phone rotating - e.g. phone must be held upright in pocket, then you can just look at the x component which will, at rest, read -9.81 and changes will show acceleration, less-negative or positive being in an upward direction, more-negative in a downward direction.

If you wish to ignore other movement (e.g. user only uses this for defined activities), then the absolute value will do. sqrt(x*x + y*y + z*z) will give you 9.8 at rest and changes to that value will be due to acceleration of the device. A bit of maths later (brute-force numerical integration) and you can have speed or distance travelled (although note that this get very inaccurate very quickly...)

Note there is a Rotation Vector Sensor API that may allow you to remove the device's orientation from the gyroscope readings allowing you to calculate the real-world movement, however I haven't tried this API and do not know what extra hardware (if any) is needed.

Jonathan Twite
  • 932
  • 10
  • 24