Rover-bot, avoiding obstacles

Ok, I finally completed a rather simple but effective method for my little rover-bot to avoid obstacles. Basically I used the infrared range finders to measure the distance to close objects then change the speed or direction of each wheel to avoid the obstacle.  I used a some programing that I was not familiar with.  But hey, It’s all about learning.

 

So I mapped the signals from the IR range finders, and scaled them to the numbers 1 – 4.  When 4 is detected it means that no object is with in reasonable range.  So there are three options for turning.  First is to slow the opposite wheel down a little.  Second is to slow the opposite wheel more.  Third is to reverse the wheel and let the bot spin on its axis.  So depending on how close the obstacle is the more aggressively it turns.

 

I used the switch-case command to direct the program.  I am sure there are more elegant solutions, and I am also sure that as I learn more I will modify the program accordingly.  At least this is better than a long string of if-else statements.

 

So here is a video of the rover bot being confronted with a few obstacles and how it deals with the problem. Remember that this is completely autonomous.  No remote control is used.  The little thing evaluates the situation then reacts on its own.

Here is a short section of the code I used to avoid obstacles.

 

// read sensor pins and map values

sensorValueL = analogRead(sensorPinL);

sensorValueL = map(sensorValueL, 200, 625, 4, 1);

sensorValueR = analogRead(sensorPinR);

sensorValueR = map(sensorValueR, 200, 625, 4, 1);

//Check for obstacle in front of Light side

switch (sensorValueR) {

case 1: //Object on Right close enough to nearly touch rover bot <1.5”

//control motor movements

digitalWrite(dir_a, HIGH);

digitalWrite(dir_b, LOW);

analogWrite(pwm_a, 150);

analogWrite(pwm_b, 150);

break;

case 2:  //Object detected on right close 2.5”

//control motor movements

digitalWrite(dir_a, HIGH);

digitalWrite(dir_b, HIGH);

analogWrite(pwm_a, 150);

analogWrite(pwm_b, 50);

break;

case 3:  //Object detected, but not real close 4”

//control motor movements

digitalWrite(dir_a, HIGH);

digitalWrite(dir_b, HIGH);

analogWrite(pwm_a, 150);

analogWrite(pwm_b, 100);

break;

default:

 

// drive right motor forward at normal speed

//control motor movements

digitalWrite(dir_a, HIGH);

digitalWrite(dir_b, HIGH);

analogWrite(pwm_a, 150);

analogWrite(pwm_b, 150);

//check for obsticle on Left side

switch (sensorValueL) {

case 1: //Object on Left close enough to nearly touch rover bot <1.5”

//control motor movements

digitalWrite(dir_a, LOW);

digitalWrite(dir_b, HIGH);

analogWrite(pwm_a, 100);

analogWrite(pwm_b, 150);

break;

case 2:  //Object detected on right close 2.5”

//control motor movements

digitalWrite(dir_a, HIGH);

digitalWrite(dir_b, HIGH);

analogWrite(pwm_a, 50);

analogWrite(pwm_b, 150);

break;

case 3:  //Object detected, but not real close  4”

//control motor movements

digitalWrite(dir_a, HIGH);

digitalWrite(dir_b, HIGH);

analogWrite(pwm_a, 100);

analogWrite(pwm_b, 150);

break;

default:  //normal speed forward.

analogWrite(pwm_a, 150);

analogWrite(pwm_b, 150);

 

}}}

Advertisements
Tagged , , ,

One thought on “Rover-bot, avoiding obstacles

  1. Mr.Jay says:

    It’s Arduino! Android Open Accessory is based on it. You did a great job! My blog: xmscan.wordpress.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: