Tracking Position in 3d space using 10-DOF IMU

16,450

Solution 1

An accelerometer will never give you a position, it will give you… acceleration.
But acceleration is related to speed which is related to position.
If you look at the units, you see that relation. Acceleration is expressed in meter per second squared (m/s²) while speed is in meter per second (m/s) and position in meter (m).
So if
t is the time elapsed since you last calculated the position (in a loop for instance),
a the acceleration you read from the sensor,
s the old speed, s’ the new speed,
p the old position and p’ the new position,

s’ = s + a * t
p’ = p + s’ * t

You need to do the same calculation in the 3 axes (x, y, z). Assuming you know the starting position and the starting speed is zero, you can track your object in real-time.

Solution 2

Integration is like calculating the area below a curve. Let's consider only one direction X. If you imagine a chart of acceleration over time, you have time as abscissa (horizontal) and acceleration as ordinate (vertical).

If you have two scalar values a1 and a2 representing acceleration at times t1 and t2 and imagine a linear transition between the two in the middle (at time (t1+t2)/2 acceleration is (a1+a2)/2...) the shape you can draw with this curve is a right-angled trapezoid of bases a1 and a2 and one side (with rectangular angles) of length t2-t1 (that is also the height).

The area is (base1+base2)*height/2 = (a1+a2)*(t2-t1)/2 or (a1+a2)/2 * delta_t

where delta_t is, (t2-t1), the time interval between sensor readings and (a1+a2)/2 is the mean of the last two reading values.

Doing this you might get the approximate speed difference starting from from an initial speed s0 (that you may assume as zero if you start still)

s(n) = (a(n-1)+a(n))/2 * delta_t + s0

Integrating again in the same way you can get "space" x or distance from a starting point x0

x(n) = (s(n-1)+s(n))/2 * delta_t + s0x + x0

If you start still from point 0, you can safely assume s0=0 and x0=0

s(n) = (a(n-1)+a(n))/2 * delta_t x(n) = (s(n-1)+s(n))/2 * delta_t

Or programmatically, saving only the last values:

old_a=a;
old_s=s;
a=getAccelerationX();

s = (old_a+a) * delta_t / 2.0;
x = (old_s+s) * delta_t / 2.0;

Please consider that this assumes a fixed still (speed=0) known (x=0) starting position, the ability to go on tracking one component of the acceleration (no matter how the sensor is rotated in space), and it will inevitably get more and more error after a while, as minimal errors will add up, so it is ideal for positions that can be tested after some time with other methods.

P.S. if you perform operations on a microcontroller (Arduino) in C be careful of how you express formulas: if old_a and a are integers, /2 will truncate the division result discarding decimals (bad idea), while /2.0 will generate a float. (old_a+a)/2*delta_t is worse than (old_a+a)*delta_t/2. The last has less error, but be careful that it does not overflow. Just to say that every error will sum up, so be careful of how you calculate it.

Share:
16,450
svhr
Author by

svhr

Updated on June 04, 2022

Comments

  • svhr
    svhr almost 2 years

    I need to track position and orientation of a gun in 3d space. I purchased a 10-dof IMU sensor (GY-87) to learn properly how to implement the solution of my problem. I am unable to find proper guidance due to lack of my knowledge in the field of electronics and Sensors. I found some good examples, but unable to implement it in arduino.

    3d Tracking with IMU

    Gait-Tracking-With-x-IMU

    I am currently able to detect Yaw, Pitch and Roll from the Sensor, from which i can detect the proper orientation of my gun. But I cant find a way to calculate position(x,y,z).

    I would be grateful to you if someonce can help me in this regards.

    Thank you

    P.S: I cant find much resources for GY-87, may be it is deprecated. But due to unavailability of resources in my country, I had to use this sensor. I am a computer science student and new towards electronics, so please correct me if I am not using any proper term.

  • A Person
    A Person almost 9 years
    You have to collect the acceleration data over a period of time and integrate it twice to obtain displacement, which is the distance moved away from the initial position. There are 3 displacements you have to calculate for each of the axes of course, as mentioned by Franck, in order to calculate the resultant displacement in 3D space