Author Topic: Roboduino Obstacle Avoider  (Read 3714 times)

0 Members and 1 Guest are viewing this topic.

Offline Adityav95Topic starter

  • Full Member
  • ***
  • Posts: 64
  • Helpful? 0
Roboduino Obstacle Avoider
« 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!

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!

« Last Edit: July 13, 2011, 06:11:18 AM by Adityav95 »

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Roboduino Obstacle Avoider
« Reply #1 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

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Roboduino Obstacle Avoider
« Reply #2 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
Current project: tactile sensing systems for multifingered robot hands

Offline Adityav95Topic starter

  • Full Member
  • ***
  • Posts: 64
  • Helpful? 0
Re: Roboduino Obstacle Avoider
« Reply #3 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

 


data_list