Maze solver Robot

Maze solver autonomous Robot :






 Task :To make a autonomous line following robot which is capable to follow black line over white surface and which can solve given maze and reach up to end point and stop. Robot is capable to take sharp 90 degree turns and is able to stop at end in black square.Task is to programme  a robot to reach to end point on random arena i.e arena can be changed it is not fixed , we have to develop general code for solving it.

overview : This project were presented in" Axis - technical festival of VNIT " And won first prize in "auto bot event" . The problem statement is to sove the random given maze and reach to end point taking proper 90 degree turns and navigating through 'T' junctions .

Components :
 For this project we require :
  • ATMEGA 16 micro controller development board.
  • 5 element array sensor grid, and one single sensor
  • Linux platform with AVR-dude programmer installed.
  • text editor program "nano" in ubutu linux.
  • motor, chasis and other robot building assembly.
  • motor driver circuit with L293D etc.
Logic used :
   In order to solve the maze logic of "hand rule " is used . That is robot will prefer to take turn on left side whenever option arrives this will finally lead to end point of arena in all mazes.Throughout the maze following type of conditions should be considered.
   In order to achieve this 5 array sensor grid(say s) is used with one extra sensor(say iv) , and one more sensor stop_sensor ,some distance ahead of it to sense the following conditions :

  1. 90 degree turn : It should move sharp.in this case either leftmost or rightmost s is 1 and iv is 0 . Proper decision code can be written for it.
  2. T junction : It should go left .in this case s are all 0 and only iv sensor is 1 so proper code for turning left can be written for it.
  3. |--- junction : in this case the bot should move straight according to left hand rule. In this case our five sensor grid s is 10000 ans sensor iv = 0 . So using this conditions code can be written to move forward.Here sensor iv is able to differentiate between condition 1 and 3 .
  4.  ---| junction : in this case sensor grid s = 00001 and iv = 0 . Using this condition code can be written to turn left.
  5. stop square : This is black square box at end of the maze . Bot is expected to stop at it. Here our sensors s and iv and stop_sensor all will be 0 . Thus using this conditions of sensor code to stop can be written.
  6. ---|---  cross junction : In this case s = 00000 . using this condition we can code to move left .
  7. dead end |  : in this case all sensors s and iv are 1 . so using this condition code can be written to take sharp left turn and bot will move until black line is detected again. i.e 180 turn at dead end.
Code :
 Code is written on AVR ATMEGA16 MCU using AVR-GCC compiler and AVR-dude program.

Here enable input is used to enable or disable left hand rule or right hand rule.
so that just by seeing arena we can decide whether to use left or right hand rule to complete maze in minimum path.
 
--------------------------------------------------------------------------------------------------------------------
#include<avr/io.h>

#define forward PORTB = 0b00001010;
#define stop PORTB = 0b00000000;
#define right PORTB = 0b00001000;
#define left PORTB = 0b00000010;
#define sharp_right PORTB = 0b00001001;
#define sharp_left PORTB = 0b00000110;

void main(void){
unsigned int iv;   // our 5 sensor grid
unsigned int s;   // one extra sensor ahead to differentiate with conditions
unsigned int enable;  // enable input to enable either left hand or right hand rule
unsigned int stop_sensor;
DDRB = 0xFF;    // motor output
DDRA = 0x00;    // sensor grid input
DDRD = 0x00;   // sensor iv input
PORTD = 0x00;
PORTA = 0x00;
DDRC = 0x00;
PORTC = 0x00;
while(1){        // start of main infinite while loop
iv = PIND&0b01000000;  // masking
s = PINA&0b00111110;  //masking
enable = PIND&0b00100000;   // masking
stop_sensor = PINC&0b00000001; // sensor used to stop at the end

if(enable == 0b00000000){  // left hand rule
switch(s){
case 0b00100010 : forward;break; // line following
case 0b00110000 : right; break;
case 0b00111000 : right; break;
case 0b00111100 : right; break;
case 0b00000110 : left ; break;
case 0b00001110 : left ; break;
case 0b00011110 : left ; break;
case 0b00100110 : left; break;
case 0b00110010 : right;break;
case 0b00111110 : sharp_right;break; // dead end
case 0b00001000 : left;break;

//case 0b00100000 : right;break; // commaon condition1 modify
//case 0b00000010 : left; break;
//case 0b00000000 : sharp_left;break;
         }

if(s == 0b00100000 && iv == 0b01000000){right;}  // 90 degree turn
if(s == 0b00000010 && iv == 0b01000000){left;}    // 90 degree left turn
if(s == 0b00100000 && iv == 0b00000000){forward;} //  |-- junction
if(s == 0b00000010 && iv == 0b00000000){left;}  //  ---| junction

if(s == 0b00000000 && stop_sensor == 0b000000001){sharp_left;}
if(s == 0b00000000 && stop_sensor == 0b00000000){stop;}  //stopping condition

if(s == 0b00000000 && iv == 0b01000000){sharp_left;}
} // end of first run

if(enable == 0b00100000){  // using right hand rule
switch(s){
case 0b00100010 : forward;break;
case 0b00110000 : right; break;
case 0b00111000 : right; break;
case 0b00111100 : right; break;
case 0b00000110 : left ; break;
case 0b00001110 : left ; break;
case 0b00011110 : left ; break;
case 0b00100110 : left; break;
case 0b00110010 : right;break;
case 0b00111110 : sharp_right;break;
case 0b00001000 : right;break;
//case 0b00100000 : right;break; // commaon condition1 modify
//case 0b00000010 : left; break;
//case 0b00000000 : sharp_right;break;
         }

if(s == 0b00100000 && iv == 0b01000000){right;}
if(s == 0b00000010 && iv == 0b01000000){left;}
if(s == 0b00100000 && iv == 0b00000000){right;}
if(s == 0b00000010 && iv == 0b00000000){forward;}

if(s == 0b00000000 && stop_sensor == 0b00000001){sharp_right;}
if(s == 0b00000000 && stop_sensor == 0b00000000){stop;} //stopping condition

} //end of second run with right hand rule

}

}
--------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment