I tried to tune my pid loop… i tried everything… the Ziegler–Nichols method doing it myself EVERYTHING but absolutely nothing works to i think its the code so here my code:
double desiredValue = 3000 * 0.8; // in percent
double currSpeed;
int flywheelPID(){
double kU = 0.1;
double pU = 0.5;
double kP = 0.2; // 0.04 0.045 0.07
double kI = 0.0; // 0.01 0.01 //0.018
double kD = 19; // 0.45 0.8 1.5 14.5
double kF =0; //0.0;
double totalError = 0;
double lastError = Rotation20.velocity(rpm);
vex::task testing(SeeIfPID);
while (PIDenable == true) {
double currValue = Rotation20.velocity(rpm);
double currError = desiredValue - currValue;
double target = desiredValue * kF;
totalError += currError;
if (currError == 0 or currError >= desiredValue){
//totalError = 0;
}
double outputFlywheel=FlywheelPID.getOutput(currValue,desiredValue);
double diffError = currError - lastError;
currSpeed = (currError * kP + totalError * kI + diffError * kD + target)/12;
if (currValue / 3000 * 100 >= 1){
printf("Flywheel is going at: %f\n",outputFlywheel);
}
if (currSpeed <= 0){
// currSpeed = 0;
}
//outputFlywheel = 0;
LauncherMotorA.spin(forward,currSpeed,volt);
LauncherMotorB.spin(forward,currSpeed,volt);
//LauncherMotorA.setVelocity(-currSpeed, percent);
//LauncherMotorB.setVelocity(-currSpeed, percent);
lastError = currError;
task::sleep(20);
}
return 1;
}
is something wrong in it?