11 years, 5 months ago.

how to derive?

Hello,

I read the positione with QEI libraries. I want to derive the position to get the velocity and the acceleration. Some ideas?

Thx

1 Answer

11 years, 3 months ago.

Simply apply the basic formulae:

velocity     = dx / dt
acceleration = dv / dt

Here is some untested pseudocode to do that:

#define dt      (0.01)

QEI encoder(p29, p30, NC, 624);  //chanA, chanB, index, ppr

float p_0 = encoder.getPulses();
float p_1 = 0;

float v_0 = 0;
float v_1 = 0;

float a = 0;

while (true) {
    p_1 = encoder.getPulses();
    v_1 = (p_1 - p_0) / dt;
    a   = (v_1 - v_0) / dt;    
    
    p_0 = p_1;
    v_0 = v_1;
    
    wait(dt);
}

And here is a reference to a program actually using it:

Repository: PIDRover

HTH, Emilio