nunolourenco
nunolourenco

Reputation: 699

Android Speed based on accelerometer values

I need to obtain the velocity of an android device, based on the accelerometer values. I made a code that allows me to get the accelerometer values, and then I calculate the velocity, using the formula: v = v0 + at. (vector calculation)

My problem is that my velocity only increases and never decreases. I think the problem is that the device never gets an negative acceleration.

Can you help me with this?

Upvotes: 6

Views: 7475

Answers (3)

Pentium10
Pentium10

Reputation: 207863

You can use a combination of the accelerometer and the digital compass, in phones that have them, to determine a speed and direction as mentioned in this post.

If all you need to do is determine if the person is walking, all you need is the accelerometer. Just process its output for foot steps.

There are plenty of tutorials on the web for detecting foot steps with an accelerometer.

There an app note here: http://www.analog.com/library/analogDialogue/archives/41-03/pedometer.html that gives a decent mathematical background and an example algorithm. Its of course up to you to extract the math and rewrite it for Android (the example code is written in C). I don't currently know of an open source android library with a footstep detection algorithm.

If you implement something, I would like to get the code, don't forget to post back the results.

Upvotes: 1

maerics
maerics

Reputation: 156424

Obtaining velocity from the accelerometers might not be possible (forget reliable) because at constant speed there will be no acceleration (other than gravity). You might be better off obtaining GPS location data and their associated time samples and computing velocity by distance over time.

Upvotes: 6

CommonsWare
CommonsWare

Reputation: 1006614

Are you subtracting out the force of gravity? The device is always accelerating -- even if it is just sitting on your desk, it is accelerating at 9.8 m/s^2 away from the center of the Earth.

Upvotes: 4

Related Questions