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, Lolzzz

I 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
AWOL

Sorry, 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.
7  Using Arduino / Programming Questions / A crazy problem with while loop :( on: August 24, 2012, 06:02:21 am
Hello Guys,

I have this crazy problem, I don't know why I couldn't come with a proper solution.

Story: I want to turn the robot to a some degree (30 degrees) according to sensor readings. for example if right is blocked turn 30 degrees left and check if front is free move forward else check if left is free turn 30 degrees left.
I am using a compass to read the current bearing. if moving right add 30 degress to current compass reading and turn right until new compass reading is between previous comapss reading + 30 and previous compass reading  + 35.

Why 35? because, the compass reading is not accurate and it always gives one or two degrees up and down, for example: if the angle is 45, sometimes it gives 46 or 47 or 44. so, I am not worried about 5 degrees up and down.

if moving left. read current bearing and subtract 30 degrees from current bearing. turn left until new compass reaches our new angle.

here is the code.
Code:
void turnRightTheRobot(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(leftMotorSpeed, rightMotorSpeed );
      break;
    }
    else {
      turnRight(leftMotorSpeed, rightMotorSpeed);

    }
  }
}


the problem raises here
Code:
if(x >= newBearing && x <= newBearing +5)

for example---> if the current compass reading is 350, want to turn 30 degrees to right, the compass reading should be between 20 and 25 to stop. However with my solution 350 is always greater than 20 and never smaller than 25. I am stuck here.
I appreciate if you guys can help me. PLEASE.

PS. I have also tried with OR like
Code:
if(x == newBearing || x == newBearing +1 || x == newBearing +2 || x == newBearing +3 || x == newBearing +4)

Didn't work.  smiley-sad. some times it turns and works fine, but mostly turns and never stops smiley-sad
8  Using Arduino / Project Guidance / Re: Is it possible to turn the robot to a certain degree with Compass? on: August 24, 2012, 02:23:13 am
Hey Guys,

I have followed Johns approach, the problem is: the compass has inaccuracy and it does not give exactly 45 degree. for example, if the desire angle is 45 degrees, it turns the robot but does not stop because the compass has 1 or 2 degrees inaccuracy.
Code:
if(error == 0){ somecode; }

Error never become 0, since 45 becomes 46 or 47. what I am trying to do is define a range, between 45 and 50, if the compass reading is between 45 and 50 it should stop.
9  Using Arduino / Project Guidance / Re: Is it possible to turn the robot to a certain degree with Compass? on: August 23, 2012, 05:40:31 pm
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.

Code:
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);
  }
  }
}
10  Using Arduino / Project Guidance / Re: Is it possible to turn the robot to a certain degree with Compass? on: August 23, 2012, 04:55:48 pm
Thank you for the reply,

I will check with your solutions.


Regards.
11  Using Arduino / Project Guidance / Is it possible to turn the robot to a certain degree with Compass? on: August 23, 2012, 03:40:17 pm
Hello Guys,

I am working on a robot project, I am trying to turn the robot to a certain degree with the help of a compass, the robot uses two DC motors. so, I don't have any stepper or encoder to determine the wheel rotation.

My idea was to read the current bearing and add the new angle to it, then turn the robot until it reaches to that angle from north. for example:
Code:
compassReading = getBearing();
int newAngle = compassReading + 45 ;
if (newAngle > 359) {
newAngle = newAngle -359;
}
turnTheRobot(newAngle);

the Code for turning the robot can be something like this:
Code:
void turnTheRobot(int angle){
int counter = getBearing();
while (! counter == angle) {
turnRight(leftmotorSpeed, rightmotorSpeed);
counter= getBearing();
}
}

this code was a simple idea which I tried many times, however it still doesn't work.

Can anyone help me please. If it is possible can you guys provide a simple algorithm or a piece of example code.

I really appreciate your help.

Regard
12  Using Arduino / Project Guidance / Re: COMBINATION OF SHARP IR SENSORS WITH SONAR FOR MY ROBOT on: August 23, 2012, 10:40:23 am
Thank you very much Pauls,

yea, I had the same idea, but I was not sure whether I am on the right direction. I was thinking to take different reading and average them, as I saw in some examples. but I wasn't sure with my solution because it is my first time with robotics and arduino.

Although I have implemented this concept, it has some problems, like misbehaving. I am gona work and try to fix it.

Thanks again.
13  Using Arduino / Project Guidance / Re: COMBINATION OF SHARP IR SENSORS WITH SONAR FOR MY ROBOT on: August 23, 2012, 09:29:04 am
Thanks for the reply,

I have connected the ultrasound sensor via I2C bus, and the other three IR sensors are connected to arduino analog pins, I have linerised the sensor readings, so I can get proper distance from sensors,

I have written an algorithm for object avoidance with Sonar sensors, its good and working.

I have also tried with IR sensors, it is okay, and the robot avoid obstacles.

I have two boards on top of each other, like two floor. If I use the sonar sensors, they can not detect object that are shorter because the sonar can not see those objects. so I placed the IR sensor on the first level (like first floor) to detect the objects that the sonar can not detect.

what I am trying to do is: to detect the short objects with IR sensors and tall object with ultrasound sensor.

Both IR and Ultrasound Sensors (Right and Left sensors are 45 degree and one sensor is in the centre).

I can get all these readings from sensors. My problem is: I can not properly use them. to be honest, I can't write the algorithm for sensor fusion.
14  Using Arduino / Project Guidance / COMBINATION OF SHARP IR SENSORS WITH SONAR FOR MY ROBOT on: August 23, 2012, 04:58:12 am
Hey Guys

I am having trouble with the object avoidance algorithm, I have check with sonar sensors, it is okay and working,

I have also check with IR sensors, it is perfectly working. however, I am trying to combine these two kind of sensors,

I have three sonar sensors and three infrared sensors.

any ideas or suggestion, how to combine them them to have precise object avoidance systems.

I really appreciate your help,

Regards
15  Using Arduino / Project Guidance / Re: how many devices can be supplied by Arduino +5 pin? on: August 10, 2012, 05:00:26 pm
AWOL!

I just wrote to tell him that I am using external power supply, not the USB cable, anyway, I am experimenting with my first Arduino project.

Jaredpi, thanx for the reply,

Yea, I was thinking to find the current of each devices from their datasheets and sum them up, then compare to the total current of Arduino, as Lefty pointed that it could be greater than 500 mA if the Arduino is powered from external power supply.

Pages: [1] 2 3 4