Search code examples
androidaccelerometerandroid-sensors

How to find Linear acceleration along x-axis using accelerometer


I am currently working on an android app in which I want to get acceleration along only x-axis. There are some confusions in mind which I want to clear.

  1. First confusion is regarding the output of accelerometer's x-axis data. Is it the acceleration or the velocity. (Pardon me on bad physics concepts).
  2. Second confusion is that when I get the isolated reading of x-axis I get a change when phone tilts. I don't want that. I want the reading only when I move the phone horizontally.
  3. Third problem is that I want to get the speed of phone's movement along x-axis by using above data. Is it possible?

I still doesn't know whether any of above is possible or not. Kindly enlighten me if it is?


Solution

  • It might be possible if your requirements allow for drift...

    1. The accelerometer outputs acceleration.
    2. Are you certain your not moving it at all in the x-axis direction during rotation? Also you may be seeing gravity come into play if the rotation aligns the X-axis with gravity's pull. You will need to filter this out.
    3. Your primary issue with this one will be that accelerometer data is very noisy and due to the double integral you will need to do to get the distance traveled (or even the single integral to get the velocity) you will experience drift.. If your requirements are tolerant of drift, then it can definitely work.

    Edit: Place to start: https://developer.android.com/guide/topics/sensors/sensors_overview.html