# Estimating velocity and position

I got a few question on calculating velocity and position. First as u look at the picture, i have already remove g from acc data. So next i need to find velocity which is v, what i need to sub for T? is it 9.8m/s? and my a = totalacc? and how about the value for v[k] ?

velocity = v[k+1] = v[k] + Ta[k]
position = r[k+1] = r[k] + Tv[k]

Look it up where ever you found those equations, and no T is not 9.8!

Mark

The usual formulas for velocity and acceleration are
v = u +at
v2 = u2 + 2as
s = ut + 0.5 at**2

Where v = final velocity in m/s
u = initial velocity
a = acceleration in m/s/s
s = distance in m
t = time in seconds

**2 means to the power of 2 (or squared)

The acceleration due to gravity is 9.81 m/s/s

...R

Edited to change ^ to ** which is the correct C/C++ method for exponentiation (^ means XOR) Bad hair day.

Physics is case sensitive to. If this is what I think it is (N-body problem solved by Euler's method or one of its derivatives) then it's not g.

Mark

The usual formulas for velocity and acceleration are
v = u +at
v2 = u2 + 2as
s = ut + 0.5 at2

AWOL:
The usual formulas for velocity and acceleration are
v = u +at
v2 = u2 + 2as
s = ut + 0.5 at2

Thank you for taking the trouble to use superscripts. I'm dreadfully lazy - slap self on wrist.

...R

It's just that, in a C context, "^" confuses a lot of people (especially if they're from a BASIC background)

The equations you wrote:

velocity = v[k+1] = v[k] + Ta[k]
position = r[k+1] = r[k] + Tv[k]

are approximations for estimating the velocity and position, estimations like this are used when the acceleration of the system is not constant and does not have a closed-form solution. The equations given by others are used when the acceleration of the system is constant, about the only time acceleration is constant is in a Physics classroom. v[k+1} is the velocity at the kth + 1 step, likewise a[k] is the acceleration at the kth stepand T is the time increment.

The approximations above are a very crude way to solve for velocity and acceleration, but probably satisfactory for your application as long as T is chosen appropriately.

By the way Physics is not case dependent, we use upper and lower case letters in equations simply as a matter of choice it does not change the Physics.

By the way Physics is not case dependent, we use upper and lower case letters in equations simply as a matter of choice it does not change the Physics

But what about "g" and "G"?

AWOL:

By the way Physics is not case dependent, we use upper and lower case letters in equations simply as a matter of choice it does not change the Physics

But what about "g" and "G"?

Those are style decisions that do not affect the physical world at all. There is nothing unique about the meaning of g or G they can be defined to be whatever you want, that is why in technical papers the authors usually are very careful to define any symbols, like g and G, usually the first time they are used, when equations are written any symbols not already clearly defined are defines either right before or after the equation.

How do i know i got the correct answer? Is this the correct output?

Fufu:
How do i know i got the correct answer?

You need to understand what the expected output is for the test you carried out, and then compare that to the actual output.

The first thing I checked was the total acceleration and it was wrong I stopped at that point. It would be a lot easier to look at the code that was supposed to implement those equations then looking at the output.

Is this the correct output?

No. The accelerations in the X, Y and Z directions are completely independent of each other.

You can estimate velocity and position for each direction stepwise, using equations similar to what you have, but those three independent accelerations give rise to three equations for the X, Y and Z velocities and three equations for the X, Y and Z positions.

AWOL:
It's just that, in a C context, "^" confuses a lot of people (especially if they're from a BASIC background)

I seem to be suffering from a sawdust brain today. I had forgotten that C uses ^ as XOR. What's even more unforgiveable - so does Ruby. I will edit my post to use **.

...R

I follow according to the low-pass filter equation. Did i miss out something?
g = 0.9 * g + 0.1 * V

g is a global variable initially set to Zero.
v is current sensor value // g level or ADC output value?

``````float ValueX1 = 0,ValueY1=0,ValueZ1=0;
float alpha = 0.9f;
float dt = 0;
float timeConstant = 0.18f;

void loop() {

alpha = timeConstant / (timeConstant + dt);

ValueX1 = alpha * ValueX1 + (( 1 - alpha ) * ValueX); //ValueX current value
ValueY1 = alpha * ValueY1 + (( 1 - alpha ) * ValueY); //ValueY current value
ValueZ1 = alpha * ValueZ1 + (( 1 - alpha ) * ValueZ);//VauleZ current value

accX = ValueX - ValueX1;
accY = ValueY - ValueY1;
accZ = ValueZ - ValueZ1;

totalacc = sqrt((accX*accX) + (accY*accY) + (accZ*accZ));
}
``````