sorry I am all new to this, but I have a principal question.
It is about some lines of code in this file:
http://code.google.com/p/multiwii/sourc ... ltiWii.pde
This is a part of the code:
Code: Select all
error -= gyroData[axis];
PTerm = rcCommand[axis];
errorGyroI[axis] = constrain(errorGyroI[axis]+error,-16000,+16000); //WindUp //16 bits is ok here
if (abs(gyroData[axis])>640) errorGyroI[axis] = 0;
ITerm = (errorGyroI[axis]/125*I8[axis])>>6; //16 bits is ok here 16000/125 = 128 ; 128*250 = 32000
}
if (abs(gyroData[axis])<160) PTerm -= gyroData[axis]*dynP8[axis]/10/8; //16 bits is needed for calculation 160*200 = 32000 16 bits is ok for result
else PTerm -= (int32_t)gyroData[axis]*dynP8[axis]/10/8; //32 bits is needed for calculation
delta = gyroData[axis] - lastGyro[axis]; //16 bits is ok here, the dif between 2 consecutive gyro reads is limited to 800
lastGyro[axis] = gyroData[axis];
deltaSum = delta1[axis]+delta2[axis]+delta;
delta2[axis] = delta1[axis];
delta1[axis] = delta;
if (abs(deltaSum)<640) DTerm = (deltaSum*dynD8[axis])>>5; //16 bits is needed for calculation 640*50 = 32000 16 bits is ok for result
else DTerm = ((int32_t)deltaSum*dynD8[axis])>>5; //32 bits is needed for calculation
axisPID[axis] = PTerm + ITerm - DTerm;
I assume that this piece of code calculates the PID for stabilizing angular velocity (correct me if I'm wrong).
P = angular velocity
I = integral of angular velocity = angle
D= derivative of angular velocity = angular acceleration
The D-Term is mainly calculated following
Code: Select all
delta = gyroData[axis] - lastGyro[axis];
Then, all three terms (P,I,D) are summed up, but the D-term is subtracted
Code: Select all
axisPID[axis] = PTerm + ITerm - DTerm;
That would - to my understanding - mean, that the D-term does actually not "amplify the reaction speed", but it will dampen and "weaken" the reaction of the P-term. The D-term is inversed, and the amplitude will be inversed with relation to the P-term.
But to my surprise, I read the following on http://www.multiwii.com/software :
Derivative coefficient: this coefficient allows the tricopter to reach more quickly the requested attitude. In practice it will amplify the reaction speed of the system, and in certain cases an increase of the Proportional term.
Am I understanding something wrong in the code? I must admit that I don't know the syntax, I assume it is something like arduino?