6

I am developing an app using android OS for which I need to know how can I calculate the movement of the device up in the vertical direction.

For example, the device is at rest (point A), the user picks it up in his hand (point B), now there is a height change between point A and point B, how would i calculate that?

I have already gone through the articles about sensors and accelerometers, but I couldn't really find anything to help me with that. Anyone have any ideas?

2
  • Do you need the accurate height change?
    – Ali
    Jun 9, 2011 at 12:07
  • No, I just need to know that there has been a height change of more than 2 or 3 ft.
    – Raza
    Jun 9, 2011 at 16:04

3 Answers 3

5

If you integrate the acceleration twice you get position but the error is horrible. It is useless in practice. Here is an explanation why (Google Tech Talk) at 23:20. I highly recommend this video.

Now, you do not need anything accurate and that is a different story. The linear acceleration is available after sensor fusion, as described in the video. See Sensor.TYPE_LINEAR_ACCELERATION at SensorEvent. I would first try a high-pass filter to detect sudden increase in the linear acceleration along the vertical axis.

I have no idea whether it is good for your application.

3
  • 1
    Thanks @Ali. The video really helped me understand accelerometers and their calculation. However, like you said it is quiet impractical, so I am dumping the idea of this app as I don't see it being used in it. Basically, the core idea of the app depended on measuring the distance (though just knowing if it's > 3ft ) of the device from rest to the pick up point of the user, which now I see can't be done with the accelerometer.
    – Raza
    Jun 10, 2011 at 7:25
  • Glad to hear it helped. As far as I know there is a gesture library, also mentioned in the video, perhaps it already supports what you need.I do not program Android devices so I do not know more about it. Good luck!
    – Ali
    Jun 10, 2011 at 8:48
  • Hi, thanks. I'll look into the gesture library. Secondly, I am just testing some stuff with the TYPE_LINEAR_ACCELERATION, i might get it to work as i want. Will post the update if I get lucky.
    – Raza
    Jun 10, 2011 at 10:56
3

You can actually establish (only) the vertical position without measuring acceleration over time. This is accomplished by measuring the angle between the direction to the center of the earth, and the direction to the magnetic north pole.

This only changes (significantly) when the altitude (height) of the phone changes. What you do is use the accelerometer and magnetometer to get two float[3] arrays, treat these as vectors, make them unit vectors, and then the angle between any two unit vectors is arccos(AxM).

Note that's dot product ie. math.acos(A[0]*B[0]+A[1]*B[1]+A[2]*B[2]) Any change in this angle corresponds to a change in height. Also note that this will have to be calibrated to real units and the ratio of change in angle to height will be different at various longitudes; But this is a method of getting an absolute value for height; though of course the angle also becomes skewed when undergoing acceleration, or when there are nearby magnets :)

0
  1. you can correlate it to magnetic field sensor in microTesla

  2. You can use dist= integral of integral of acceleration ~ sigma ~ summation = integral of speed+constant

1
  • 2
    You say what?? Can you explain this?
    – JP Illanes
    Nov 19, 2015 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.