Go Down

### Topic: why we need both vel and acc contribution for actual position ?  (Read 148 times)previous topic - next topic

#### krishna458 ##### Aug 23, 2019, 06:08 pm
I was trying to understand multiwii quadcopter code. I started with understanding gps code. Here is a section of the code where I have doubt. Why actual position = pos + velocity contribution + acceleration contribution ? I mean velocity contibution and acceleration contribution, both are the same thing (I Think). So what is the purpose of adding both vel contribution and acceleration contribution ?

Here is the section of the code:

public:
_last_velocity(0) {
}

// setup min and max radio values in CLI
int32_t         get_position(int32_t pos, int16_t vel, float lag_in_seconds = 1.0);
void            clear() { _last_velocity = 0; }

private:
int16_t         _last_velocity;

};

int32_t LeadFilter::get_position(int32_t pos, int16_t vel, float lag_in_seconds)
{
int16_t accel_contribution = (vel - _last_velocity) * lag_in_seconds * lag_in_seconds;
int16_t vel_contribution = vel * lag_in_seconds;

// store velocity for next iteration
_last_velocity = vel;

return pos + vel_contribution + accel_contribution;
}

#### jremington #1
##### Aug 23, 2019, 07:46 pmLast Edit: Aug 24, 2019, 08:27 pm by jremington
The code does not appear to be correct.

Basic physics:  X = X0 + V0*t + 0.5*A*t2  (for constant acceleration over an interval).

A = (rate of change of velocity)/(time to change). 