I have some code that tells the robot to center on a cube when the A button is pressed. But instead of centering, it just infinitely spins in a circle. I cannot figure out why that is (probably another simple mistake that I am not seeing). Does anybody know how to fix it? Code:
void Position () {
Brain.Screen.newLine();
Brain.Screen.print("Initializing...");
Brain.Screen.newLine();
task::sleep(100);
Brain.Screen.print("Detecting...");
Brain.Screen.newLine();
VisionSensor.takeSnapshot(1);
VisionSensor.takeSnapshot(2);
VisionSensor.takeSnapshot(3);
task::sleep(100);
while (1) {
if (VisionSensor.largestObject.exists) {
if (VisionSensor.largestObject.centerX > centerFOV + offsetX) {
Brain.Screen.print("Turning...");
Brain.Screen.newLine();
LeftDrive.spin(directionType::fwd,50,velocityUnits::pct);
RightDrive.spin(directionType::rev,50, velocityUnits::pct);
} else if (VisionSensor.largestObject.centerX > centerFOV - offsetX) {
Brain.Screen.print("Turning...");
Brain.Screen.newLine();
LeftDrive.spin(directionType::rev,50,velocityUnits::pct);
RightDrive.spin(directionType::fwd,50, velocityUnits::pct);
} else {
LeftDrive.stop(brakeType::coast);
RightDrive.stop(brakeType::coast);
}
}
}
}