I am getting the 3dimensional values of a grove pi module,
acc_vector = (accX, accY, accZ)
each 100 milliseconds .
What I want is, using java, diplaying the movement that I make with the module...but my problem is not how to display it :p
For this I need to compute the value of the position
position_vector = (x,y,z)
corresponding to the acceleration values. But I have no clue about how to do it.
Here is what I've tried, but it always gives odd results (initial position, speed and acceleration are (0,0,0) ):
position_vector = 0.5f*acc_vector*t;
position_vector += acc_vector;
position_vector = acc_vector*(t-t_just_before);
It will depend on how you want to interpolate the acceleration. The easiest (but likely least accurate) would be to assume constant acceleration between samples. In that situation, your code for the
xcomponent should resemble
position += velocity * timeStep + 0.5 * acceleration * timeStep * timeStep; velocity += acceleration * timeStep;
You would have to do the same for the
To get more accurate results, you may need more sophisticated techniques. You can look up numerical methods such as Runge-Kutta.