Just to try something new, I have tried to adjust current PI controller to be PDF contoller(http://stablesimulations.com/technotes/pdf.html). Apart a cool name

Probably not all people like it, as a stick controls are really soft, but defenetly worth to try:
Code: Select all
//**** PITCH & ROLL & YAW PID ****
for(axis=0;axis<3;axis++) {
if (accMode == 1 && axis<2 ) { //LEVEL MODE
errorAngle = rcCommand[axis] - angle[axis]; //500+180 = 680: 16 bits is ok here
PTerm = -(int32_t)angle[axis]*P8[PIDLEVEL]/100 ; //680*20 = 13600: 16 bits is ok here
errorAngleI[axis] += errorAngle; //16 bits is ok here
errorAngleI[axis] = constrain(errorAngleI[axis],-10000,+10000); //WindUp //16 bits is ok here
ITerm = (int32_t)errorAngleI[axis]*I8[PIDLEVEL]/4000; //32 bits is needed for calculation:10000*I8 could exceed 32768 16 bits is ok for result
} else { //ACRO MODE or YAW axis
error = (int32_t)rcCommand[axis]*10*8/P8[axis] - gyroData[axis]; //32 bits is needed for calculation: 500*10*8 = 40000 16 bits is ok for result if P8>2 (P>0.2)
PTerm = rcCommand[axis];
errorGyroI[axis] += error; //16 bits is ok here
errorGyroI[axis] = constrain(errorGyroI[axis],-16000,+16000); //WindUp //16 bits is ok here
if (abs(gyroData[axis])>640) errorGyroI[axis] = 0;
ITerm = (int32_t)errorGyroI[axis]*I8[axis]/1000/8; //32 bits is needed for calculation: 16000*I8 16 bits is ok for result
}
PTerm -= (int32_t)gyroData[axis]*dynP8[axis]/10/8; //32 bits is needed for calculation 16 bits is ok for result
delta = gyroData[axis] - lastGyro[axis]; //16 bits is ok here, because the dif between 2 consecutive gyro reads is limited
DTerm = (delta1[axis]+delta2[axis]+delta+1)*dynD8[axis]/3/8; //16 bits is ok here
delta2[axis] = delta1[axis];
delta1[axis] = delta;
lastGyro[axis] = gyroData[axis];
axisPID[axis] = PTerm + ITerm - DTerm;
}
Note: Do not drop Level I to 0, as you would not have stick control at all.
regards,
ziss_dm