Society of Robots - Robot Forum

Software => Software => Topic started by: Adityav95 on July 13, 2011, 06:09:03 AM

Title: Roboduino Obstacle Avoider
Post by: Adityav95 on July 13, 2011, 06:09:03 AM
Hi I'm trying to  make an obstacle avoiding robot using roboduino, sharp GP2D12, 2 HS-425BB servos. I have written my own code (using arduino) but I'm facing 1 problem i.e i have no idea how to add a delay after it has detected an object. What i mean is that the moment the IR detects enough space to move forward it does so after detecting an object....i want to add a 2-3 second delay as the side of the robot crashes into the object.

Here is the code (using arduino):
Code: [Select]
#include <Servo.h>
const int analogPin = A0;
const int threshold = 190;
Servo Servo1;
Servo Servo2;

void setup() {
  Serial.begin(9600);
  Servo1.attach(3);
  Servo2.attach(5);
  int pos = 0;
}

void loop()  {
  int analogValue = analogRead(analogPin);
 
  if (analogValue < threshold)  {
        {
      Servo1.write(-180);
      Servo2.write(180);
      delay(1);
    }
  }
   else  {
           {
        Servo1.write(-180);
        Servo2.write(-180);
        delay(4);
      }
   }
}
     
   

Here is a video of the robot: Obstacle avoiding Robot! (http://www.youtube.com/watch?v=Z9K9z0TNPq8#)

Thnx in advance guys....i'm really happy that i made this robot....if i can get it working perfectly i'll get the chassis ready and be really satisfied!

Title: Re: Roboduino Obstacle Avoider
Post by: joe61 on July 13, 2011, 06:34:23 AM
I don't understand, you have the delay() function in the code, why can't you use that? Is there some other requirement as well, such as continuing to turn etc?

Joe
Title: Re: Roboduino Obstacle Avoider
Post by: mstacho on July 13, 2011, 07:46:05 AM
If I'm correct, the delay() function in Arduino is a delay in *milliseconds*, not seconds.  So you want delay(1000), not delay(1).  Otherwise it should work.

A more robust way of doing this, but one that would require more sensors and time, would be to turn the robot until the sensors detect that the path in front of it is clear, then move forward.  No delays required!

MIKE
Title: Re: Roboduino Obstacle Avoider
Post by: Adityav95 on July 20, 2011, 08:47:36 AM
I tried entering it in millisecond...doesn't make a difference. When i enter a 1000 the robot just keeps turning. Maybe there is an issue only my arduino ide. i have not recently updated it, so i'll that and tell you guys if it worked.


Thnx
Aditya