Introduction
In the field of Robotics, starting from Unmanned Aerial Vehicle
to Land Rovers, all employ some form of obstacle avoidance technology. Obstacle
avoidance plays a crucial role in the development of intelligent rovers that
can detect obstacles in their paths automatically and navigate all by
themselves avoiding the obstacles. So, here in this article we will attempt to
build a system using Atmega 8 microcontroller and dedicated obstacle detecting
sensors to replicate obstacle avoidance behavior.
Obstacle Avoidance
Just imagine how a blind guy would navigate through a given
terrain. He must be having a stick which he uses as a detector for his
obstacles…Suppose there is a wall to his front; he keeps swiping his stick back
and forth and in the horizontal motion. So he would swipe his stick and he
would feel the obstacle…right? Now he has three choices; either he would turn
left or right or move back and go in the other direction perhaps. Here in the
domain of electronics, we have sensors to do the detection! It’s on us to add
the intelligence to it, so that it can navigate through the terrain.
In this particular article we will explore the field of
“intelligent obstacle avoidance”. Now there is a specific reason to why I call
it intelligent. Although we will be using concepts of finite Automata into the
obstacle avoiding problem, there is not much to worry. The concepts used here
will open up new perspectives for the improvement of traditional robots that
uses simple logic (I mean those which don’t employ Automata Theory to their
design!)
Problem
Let’s define our problem statement. You will have to build a
robot that is smart enough to avoid obstacles in its path and navigate
autonomously through a given terrain full of obstacles.
Problem Figure
Here the rover is surrounded by walls in all the three sides.
General Layout Of The Rover
This is the general layout of the rover. We have three TSOP sensor modules mounted at the front, left and right of the rover. We have used BO type motors to save space and money.(BO's are cheaper than conventional DC motors!)
Sensors
Sensors for obstacle avoidance come in different forms
employing different techniques for obstacle detection. There are Ultrasonic
Ping sensors which use ultrasonic waves for object detection and ranging, but
these are costly. Again there are SHARP IR sensors which are again a very
costly solution to your needs. Then there are normal IR LED and Sensor pairs
which you can use, but these normal IR sensor pairs have a major drawback,
which is that these gets confused by ambient IR light. So, how do we find a
better solution? Well if you only consider obstacle detection (and not distance
ranging!), then the effective solution is to use a TSOP sensor. These sensors
although basically are of IR type but they don’t get confused by ambient IR
light. Hence you get efficient obstacle detection. Dedicated TSOP sensor
modules are available in the market, buy there of them; each for the left,
front and right of the rover.
Motors
For the motors you could use any normal DC motor of
preferably lower RPM. Although BO type DC motors are quite popular in robotics
for low torque applications. Get about a 60-100 RPM motor. You will need two of
them (There is one Castor wheel in the middle of the front end).
Theoretical Solution for Obstacle Avoidance
Table 1: Input Table
Sensor Input
L
- F - R
|
Interpretation
|
Output
|
0 - 0 - 0
|
All clear Move ahead
|
Y0
|
0 - 0 - 1
|
Wall to the right
|
Y1
|
0 - 1 - 0
|
Wall at front
|
Y3
|
0 - 1 - 1
|
Wall at front and to the right
|
Y1
|
1 - 0 - 0
|
Wall to the left
|
Y2
|
1 - 0 - 1
|
Wall to the left and to the right
|
Y0
|
1 - 1 - 0
|
Wall at front and to the left
|
Y2
|
1 - 1 - 1
|
Wall at all side
|
Y3
|
Table 2: Output Table
Output
|
Practical Meaning of Output
|
Y0
|
Move
Straight
|
Y1
|
Stop,
move back slightly and take a Left
turn
|
Y2
|
Stop,
move back slightly and take a Right
turn
|
Y3
|
Stop,
move back slightly and turn 180 degree
|
Source Code
Here I present a sample code for the Obstacle Avoiding Rover. The code is written for Atmega 8 Micro-controller, although it could be easily modified for an Atmega 16/32 Micro-controller. After compiling it in AVR STUDIO, you will get the equivalent hex code which you need to flash into the Microcontroller using some AVR programmer hardware.(Click here for the Serial AVR programmer circuit.)
#define F_CPU 1000000UL //set your clock speed
#include <avr/io.h>
#include <util/delay.h>
/*Left Sensor connected to PC 0 of Atmega 8
Right Sensor connected to PC 1 of Atmega 8
Front Sensor connected to PC 2 of Atmega 8
*/
/*A1-->PB0--> + --> +ve of the left motor
A2-->PB1--> - --> -ve of the left motor
B1-->PB2--> + --> +ve of the right motor
B2-->PB3--> - --> -ve of the right motor
*/
int move_backward=0b00000110;
int right_turn=0b00001010;
int move_forward=0b00001001;
int left_turn=0b00000101;
int left_sensor_on=0b0000001;
int right_sensor_on=0b0000010;
int front_sensor_on=0b0000100;
int left_sensor_off=0b0000000;
int right_sensor_off=0b0000000;
int front_sensor_off=0b0000000;
void wait(float x) // Delay function
{
for(int i=0;i<(int)(1302*x);i++)
_delay_loop_1(0);
}
void main ()
{
DDRB = 0xFF; //Output port
DDRC = 0b0000000; //input port
int left_sensor = 0;
int right_sensor = 0;
int front_sensor = 0;
while(1) //create an infinite loop
{
left_sensor = (PINC & 0b0000001);
right_sensor = (PINC & 0b0000010);
front_sensor = (PINC & 0b0000100);
if(( left_sensor==left_sensor_off) & (right_sensor==right_sensor_off) & (front_sensor==front_sensor_on))
{
PORTB = move_backward; //move backward
wait(2.0);
PORTB=right_turn; //take a right turn
wait(1.0);
}
if((left_sensor==left_sensor_off) & (right_sensor==right_sensor_off) & (front_sensor==front_sensor_off))
{
PORTB=move_forward; //move forward
}
if(( left_sensor==left_sensor_on) & (right_sensor==right_sensor_off) & (front_sensor==front_sensor_off))
{
PORTB=move_backward;
wait(2.0);
PORTB=right_turn;
wait(1.0);
}
if(( left_sensor==left_sensor_off) & (right_sensor==right_sensor_on) & (front_sensor==front_sensor_off))
{
PORTB=move_backward;
wait(2.0);
PORTB=left_turn;
wait(1.0);
}
if(( left_sensor==left_sensor_off) & (right_sensor==right_sensor_on) & (front_sensor==front_sensor_on))
{
PORTB=move_backward;
wait(2.0);
PORTB=left_turn;
wait(1.0);
}
if(( left_sensor==left_sensor_on) & (right_sensor==right_sensor_on) & (front_sensor==front_sensor_off))
{
PORTB=move_forward;
}
if(( left_sensor==left_sensor_on) & (right_sensor==right_sensor_off) & (front_sensor==front_sensor_on))
{
PORTB=move_backward;
wait(2.0);
PORTB=right_turn;
wait(1.0);
}
}
}
Can you give programming with only one sensor please URGENTLY NEEDED
ReplyDeleteCan you give programming with only one sensor please URGENTLY NEEDED
ReplyDelete