1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to calculate Distance from Accelerometer Data

  1. Sep 14, 2016 #1
    Hi All,
    I am a beginner in embedded world. Currently I am working on MPU9250 motion sensor. My objective of project is to calculate the distance in real time using accelerometer. e.g. If I am at point A (i.e located at 5cm on X-axis) and I am willing to move towards point B (i.e. located at 50cm on X-axis) then the movement from A->B should show changes in distance as 5,6,7,---10---50 cm. Similarly movement from B->A should show changes in distance as 50,49,48----30,29,----5 cm.

    My project is very generic and it is to be implemented on embedded processor, so I don't need any costlier algorithm like kalmaan etc. I had gone through many forums for accomplishing this task. I am using double Integration and also filtering the noise and managing the drift as well.

    The issue I am currently facing is that, I am getting data , which varies even when the sensor stand still. Due to which the final estimated distance is getting change continuously. Also when I move the sensor the overall estimated displacement is coming out to be very low. Also the changes in X,Y & Z are not so simultaneous during changes in position. Please suggest me some direction to eliminate the issue.

    Currently my displacement algorithm is -
    V[t] = V[t-1] + (A[t]+A[t-1])*T/2-----Where T is my sampling interval set by RTOS. 100msec
    Pos[t] = Pos[t-1] + (V[t]+V[t-1])*T/2

  2. jcsd
  3. Sep 14, 2016 #2


    User Avatar
    Homework Helper
    Gold Member

    You will never completely eliminate the issue--you will always have some displacement error. You can try to identify individual sources of error and control the ones that are controllable. If you are using single axis acceleration to determine displacement, then you should minimize the "tilt" of the sensor at all times throughout the motion. If your end result looks very low, what does your intermediate data look like? Does the raw acceleration data correspond to the actual applied accelerations? Does your filtered acceleration data look reasonable? Can you reduce your sample interval or is that a hard limit of the RTOS? What is the full-scale range setting are you using? What is the maximum acceleration you are applying?
  4. Sep 14, 2016 #3


    Staff: Mentor

    What you described is called inertial navigation. A Google search for that phrase returns 1500000 hits. I'm sure you can find much useful info online.
  5. Sep 15, 2016 #4


    User Avatar

    You can calculate the distance by directly using your test acceleration values rather than velocity by using (A*T^2)/2 rather than the velocity in the second factor of your "Pos[t] = Pos[t-1] + (V[t]+V[t-1])*T/2" equation.

    The resulting accuracy will be determinate upon the time increment you select for each acceleration value interval.
  6. Sep 15, 2016 #5
    The integration adds quite a bit of noise, you can use the FFT method for calculating velocity and position if you have enough processing power.
  7. Sep 21, 2016 #6
    I looked at the data sheet for this and I was wondering what "G" range you programmed it for. I assume that if you are walking around with this device that you programmed it for the 2G range.

    How are you reading the device? Are you sure you are getting samples at precise intervals?
  8. Sep 21, 2016 #7
    Yes I am getting samples at precise interval. May I know what makes you assume that the device is programmed for 2g since I haven't post any readings of the device.

    Moreover the device is programmed for 8g as I am using a TI sensortag which provide all necessary software settings. With this settings I had confirmed gravity vector at parallel surface i.e. x=0, y=0, z=1. Similar readings obtained for all other surface when placed resting. Also for any quick movement I found the acceleration changing from low to high value.
    If you can guide me specifically about your assumption I can check accordingly.
  9. Sep 21, 2016 #8
    Low range settings may be more appropriate for walking. You would get better accuracy. Higher range settings would be better suited for detecting things like impacts. 8g sounds pretty high but I could be wrong. Are you maxxing the output value when you quickly move the device? If not, you could try a lower setting.

    Could you describe how you are filtering the data and what the sample rate is?
  10. Sep 23, 2016 #9
    Hello Aaron,

    Yes, with 2G setting I got quite a good variation for movement. For 8G setting this was not the case, as I have to give a fast jerk for obtaining it. Thanks for your advice. Now, the output seems to be more stable.
  11. Sep 23, 2016 #10
    Glad to help.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted