| Arduino Forum ::  Members :: Farhad
 Show Posts Pages: [1] 2 3 4
 1 Using Arduino / Programming Questions / Re: A crazy problem with while loop :( on: August 24, 2012, 11:00:55 am Pauls, Thanks for the comment, I am gona fix it. Someone suggested here to use do{ } while. I was using a while loop, then they told me to change and use (do, while loop) Thanks anyway.
 2 Using Arduino / Project Guidance / Re: Is it possible to turn the robot to a certain degree with Compass? on: August 24, 2012, 10:58:29 am Radman, Yes, it has a magnetic compass and I have not considered that, LolzzzI had no choice, I try to not send it near iron or magnetic stuff. I will try t o solve this problem in future with encoder or stepper motors.
 3 Using Arduino / Project Guidance / Re: Is it possible to turn the robot to a certain degree with Compass? on: August 24, 2012, 08:01:49 am hey guys, It seems that I solved the problem, just wanted to post my code for some people facing same problem, I don't know whether this approach is right or not, but it works. I hope it does not affect other parts of my application. you are more than welcome to comment and suggest a better approach. Code:void turnRightTheRobot(int angle){  int currentBearing = getBearing();  int desiredBearing = currentBearing + angle;  if(desiredBearing > 359) {    desiredBearing -= 359;  }  do{    int newBearing = getBearing();    double desiredBearingSINE = sin(desiredBearing * (PI/180));    double currentBearingSINE = sin(newBearing * (PI/180));        if(desiredBearingSINE > 0 && currentBearingSINE < 0) {     newBearing = newBearing - 360;       }     if(newBearing >= desiredBearing) {      moveForward(0, 0);      break;    }    else {      turnRight(80,80);    }   }while(1);}
 4 Using Arduino / Programming Questions / Re: A crazy problem with while loop :( on: August 24, 2012, 07:59:25 am hey guys, It seems that I solved the problem, just wanted to post my code for some people facing same problem, I don't know whether this approach is right or not, but it works. I hope it does not affect other parts of my application. you are more than welcome to comment and suggest a better approach. Code:void turnRightTheRobot(int angle){  int currentBearing = getBearing();  int desiredBearing = currentBearing + angle;  if(desiredBearing > 359) {    desiredBearing -= 359;  }  do{    int newBearing = getBearing();    double desiredBearingSINE = sin(desiredBearing * (PI/180));    double currentBearingSINE = sin(newBearing * (PI/180));        if(desiredBearingSINE > 0 && currentBearingSINE < 0) {     newBearing = newBearing - 360;       }     if(newBearing >= desiredBearing) {      moveForward(0, 0);      break;    }    else {      turnRight(80,80);    }   }while(1);}
 5 Using Arduino / Programming Questions / Re: A crazy problem with while loop :( on: August 24, 2012, 06:46:34 am AWOLSorry, I couldn't understand your message, can you please tell with a little more details. Thanks
 6 Using Arduino / Programming Questions / Re: A crazy problem with while loop :( on: August 24, 2012, 06:35:41 am Thank you guys for the reply, As I said, if the current bearing is greater than 330, it will turn right infinity, because the new bearing would be 1-30 degrees and it is always smaller than previous compass reading (greater than 330). Code:if (x >= newBearing && x <= newBearing +5)is there any other option to rethink about the above code.