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 contribution 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 {
    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; }

    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;

I didn't quite understand the codes you provide. Back to your wrong statement, velocity and acceleration are two different physical quantities. Acceleration is the time derivative of velocity. When you integrate the equations of the motion, there are multiple terms that affect the next position.

Continuous motion model:

dx/dt = v;

dv/dt = a;

where x is the position [m], v is the velocity [m/s] and a is the acceleration [m/s^2].

These equations of motion can be discretized by using 'dt' time step and constant acceleration profile between discrete time steps.

Discrete motion model:

x_k = x_k_1 + v_k_1*dt + 0.5*a_k_1*dt^2

v_k = v_k_1 + a_k_1*dt

Here you can the see that the next position (x_k) is a function the previous position (x_k_1), previous velocity (v_k_1) and the acceleration input (a_k_1).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.