PID To turn

Hello everyone, my team and I have a PID control to turn, we have the idea that a system control is okay to have a exactly turn (or turn with a minimun error), but in autonomous mode the robot isn’t precise in the turn or sometimes does not stop turning
The function:

void turn_PID(float setPoint, int max_time, int sleep_time){
bool isRunning = true;
float error;
float output;
float currentValue;
float derivative;
float oldError;
int minum= 15;
while(isRunning && T1.time()<max_time){
currentValue = rectifyInput(sGyro.value(vex::rotationUnits::deg)/10);
error = currentValue - (setPoint);

We need to read opinions or experience with this system, have a good day. :slight_smile:

can you post the entire function?

also please indent your code, it makes it a lot easier to see what’s going on