Hello,
When telling my robot to turn to a negative number with my inertial sensor PID code it will turn the incorrect way and take a longer time to reach the set target, also leading to inaccurate results due to the extra speed. Any help would be greatly appreciated.
void turn(int speed){
int moveguy = speed*0.5;
if(runTurn == true){
TopLeft = moveguy;
BottomLeft = moveguy;
TopRight = -moveguy;
BottomRight = -moveguy;
}
void PIDTurn(void* Param){
while(1==1) {
gyroPOS = ((inertial.get_rotation()+inertial2.get_rotation())/2);
Gerror = turnTarget - inertial.get_rotation();
Gproportion = gyroKp * Gerror;
if (Gproportion > maxTurnPower) Gproportion = maxTurnPower;
else if (Gproportion < -maxTurnPower) Gproportion = -maxTurnPower;
Gderivative = gyroKd * (Gerror - GprevError);
GprevError = Gerror;
Gintegral = gyroKi * (Gintegral + Gerror);
Graw = Gproportion + Gderivative + Gintegral;
turn(Graw);
newTurnTarget = false;
pros::delay(20);
}
}
void setTurn(int degrees){
runPID = false;
runTurn = true;
if(degrees>=0) turnTarget = degrees;
else if(degrees<0) turnTarget = degrees+360;
// turnTarget = degrees;
newTurnTarget = true;
}