Hi John,
Thanks for your constructive reply, I am not worried to turn the robot to the shortest direction as the application well decide the direction according to the sensors readings. basically, I am turning the robot 30 or 45 degrees (right or left) if right or left is free (No object).
I used bit of your code, now I am able to turn the robot to some degree and I also scarified 5 more degrees because of uncertainties. for example: if I wanted to turn it 30 degrees to right, the robot turns 30 degree, if the compass reading is between 30 to 35, it stops.
If you can please check the code, it has some problem when the compass reading is close to 360 degree because the desired angle will be 10- 40 from north and the current reading is something like 340-360. so, 10-40 is never smaller than 340-360. Can you please suggest any solution here.
void turnTheRobot(int angle){
int currentBearing = getBearing();
int newBearing = currentBearing + angle;
if(newBearing > 359) {
newBearing -= 359;
}
while(1) {
int x = getBearing();
if(x >= newBearing && x <= newBearing + 5) {
moveForward(0);
break;
}
else {
turnRight(80,80);
}
}
}