Go Down

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

krishna458

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:



class LeadFilter {
public:
    LeadFilter() :
        _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

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).

Ahmed_sadek

Time in below and accel is in seconds. Velocity is computed for fraction second and also accel. To avoid float operations there are int numerical ways to calculating those parts for fractions of second without floats.

Go Up