{
double kP = 1.2432; // kP (scaling number)
int x = 0; // Timer for exit condition
while (true) {
double error = target - Inertial21.rotation(deg); // error = (target - current)
set_tank(error * kP, -error * kP); // Set motors to (error * kP)
Controller1.Screen.clearScreen();
Controller1.Screen.setCursor(1, 1);
Controller1.Screen.print("%8.1f", Inertial21.rotation(deg));
// If the velocity of the left and right motors are 0...
if (left_back.velocity(pct) == 0 && right_back.velocity(pct) == 0) {
x+=10; // Increase x by 10
if (x >= 30) { // If x is 30 (meaning the motors were at 0 velocity for 50ms)...
break; // Break the while loop
}
}
// If the velocity of the left and right motors are not 0...
else {
x = 0; // Set the timer to 0
}
wait(10, msec);
}
set_tank(0, 0); // Make sure motors are off before leaving this function
Inertial21.setRotation(0, degrees);
}
Currently I have this p loop. However, when i run it the next part of the autonomous doesnt work. I think its my exist condiiton. How can I make a better exiit condition or fix this one?