3

I'm new to programming with accelerometers on Android.

I want to know how fast my device is moving in any direction using the accelerometer on my Android. I have googled and found code on doing different things based on the direction in which the device is moving, but there's nothing that talking about doing different things based on the rate at which my device moves.

Can somebody help with this?

  • Unfortunately, knowing your instantaneous acceleration is of no use for determining your velocity in a given reference frame. For exmaple, a passenger in a car travelling at *constant* velocity will be experiencing *zero* acceleration, whether their speed is 10 miles per hour or 100 miles per hour. – AakashM Jun 18 '12 at 08:35

1 Answers1

2

An accelerometer only measures the rate of change of velocity. (This is the definition of acceleration.) So the only way to use it to tell velocity is to know actual velocity V_0 at some time t_0 and then record dV_i = A_i*(t_i - t_(i-1)) for successive times t_1,t_2,... where A_i is the acceleration at t_i. Then velocity at t_n is V_0 + sum_(i=1,n)(dV_i).

This is called integration and it's what made Isaac Newton (among others) famous.

This calculation is very vulnerable to error. I'd say it's not even worth trying for fun.

A more useful way to measure velocity is change in position (from the location sensor) divided by time.

Gene
  • 46,253
  • 4
  • 58
  • 96
  • This calculation is vulnerable to error for a human, but a computer can calculate higher resolutions of Riemann sums and a better approximation. And when all else fails, use a rolling average. – gobernador Jun 17 '12 at 05:14
  • 3
    @gobernador, the problem is inaccuracy in the sensors. Even a small constant deviation of 0,1G (1% of earth gravity) in one direction will give an error of 100km/h within 5 minutes, even if the device is stationary. – Albin Sunnanbo Jun 17 '12 at 07:21
  • 2
    +1 and I second that, it is not even worth trying. Even though in [Android accelerometer accuracy (Inertial navigation)](http://stackoverflow.com/a/7835988/341970) I talk about distance, the same holds for velocity. – Ali Jun 17 '12 at 07:41
  • @Albin You're right, and that makes me wonder, why include the sensors at all? – gobernador Jun 17 '12 at 15:32
  • 1
    @gobernador, the acc sensors are there to give rotational information, mostly to find out what is up and what is down. Useful for muting ring signal when flipping your phone upside down, for detecting shaking and turning in games. All those situations where where you use the absolute value of acc, and not integrating, works perfectly well. – Albin Sunnanbo Jun 17 '12 at 17:22
  • The A-sensors are also good for "gestures" as in a Wii controller. – Gene Jun 18 '12 at 18:06
  • Thank you for your responses, everyone. I have calculated the velocity and taken adequate readings, but it looks like I don't have the accuracy I need. Does anyone have an alternative solution? Or should I give up on this? – uttara_shekar Jun 18 '12 at 18:39