Gettin' smarter

Posted on 08:43 by Flyku

Here is a new clip of my robot getting its self out of a tight corner, this might not be so impressive at face value but it demonstrates the latest iteration of the robots obstacle evasion program. This has big advantages over the last version of the code in that it is continuously scanning the surrounding area and reacting proportionally, as apposed to the stop start nature of the last code.

Here is the main body of the code:

void loop (void) { // Main body of the program

int inches;

while(inches>15) // while nothing is within 15 inches do the following
{
if (pos == 0)
{
dir = 3; // if it is looking left direction is positive

headservo.write(pos); // tell servo to go to position in variable 'pos'
delay(3);
}

else if (pos == 180)
{
dir = -3; // if it is looking right direction is negative
headservo.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3ms for the servo to reach the position
}
headservo.write(pos);
inches = ping (); // anybody there?
pos += dir; // recalculate position variable
forward(1); // Move forward

}

int x = headservo.read();
wait(0); // stop the robot

if(inches>7) // for objects further away turn gradually
{
if (x>=0 && x<90)
{ rightservo.write(96);
leftservo.write(0);
delay(100); }

if (x>=90 && x<=180)
{ rightservo.write(180);
leftservo.write(94);
delay(100); }
}

else // for close objects turn hard
{

if (x>=0 && x<90)
{ right(100); }
if (x>=90 && x<=180)
{ left(100); }
} }


Please note that this is not the complete code, nor is it optimised.

There are many robots that use this type of navigation, however it took me several tries to get it working correctly, i struggled to find any good guides on writing this kind of program (which is unusual for the Arduino community). If you are trying to program a robot this way i will offer any information i can, i may also write a tutorial at some point. Until then there is a full version of the code on my LMR page.
http://letsmakerobots.com/node/15803

4 comments:

Anonymous said...

Can you post the complete code for the robot?
I try to do a robot like your, but I use a sharp sensor, not a ping sensor.I can't create the code for scaning the area and avoid the obstacles and I wish to get some ideas from your code; if you can.
(Sorry for may bad english)

Flyku said...

The complete code is an attachment in the link at the bottom. if you cant find it i will email you but i dont want to put the whole thing here as it will use to much room.

Anonymous said...

I found him. I was not careful.
Thy

Anonymous said...

it*

Post a Comment