Fire Fighting Robot

July 5, 2015

Using ATmega2560 and ATmega8

 

 


Done By

 

  • NAVEEN MURALI, IIIYR ECE
  • NAVEEN G, IIIYR ECE
  • A MUHAMMED SADUL HASAN, IIIYR ECE
  • KARTHIK NATARAJAN, IIIYR ECE

 

ABSTRACT


 

The aim of this project is to build an automated fire fighting robot that checks for the presence of fires, simulated using leds, in a room and extinguishes them. It must go to four rooms and check for fires in all of them. The robot is to finish the job within given time and space constraints as time plays a major role these days.

 

The bot checks for fire led, if it detects one then a buzzer is sounded and and a magnet is dropped to extinguish the fire.

 

 

INTRODUCTION


 

Firefighting is the act of extinguishing fires with precedence to saving life, property and nature.

In urban India, there has been an exponential increase in population density which has resulted in congestion and numerous high-rises. In these cities, the complexity of advanced lifestyle has increased the threat caused by fire hazards. These include weak implementation of development guidelines, old buildings, haphazard constructions, compromised and old electrical infrastructure and so on. Even a minor fire in a single apartment, if not contained in a timely manner, can jeopardize the lives of hundreds of civilians, in and around a building. Such extreme demands of firefighting operations within enclosed spaces stretch the capability of human firefighters, making the job severe and often lethal.

Automated robotic technology will obviate risking the lives of human firefighters. Furthermore, robotic firefighters will be better than their human counterparts at enduring the toxic environments of combusting material. Due to such reasons, robotic  firefighting technology holds great promise in the future.

 

 

BUILDING MODULES USED IN THIS PROJECT


 

Electronic Components

Microcontroller
  • The major controller used is ATmega 2560. It is used as the master controller
  • The auxillary controller used is ATmega 8. This is used as the slave controller

 

Sensors
  • Sharp IR sensors: these are used for detecting if a door is present and for the wall following algorithm.
  • White Line Sensor: This is used to make the firebird bot move on a specific line of path. This can be achieved using the highly directional white line sensor. It has a bright red LED, whose light gets reflected back if it is on white surface and gets reflected a little if it is on black line. Hence, localization can be achieved. It is also used to detect the fire led.
  • Precision encoder: used to move the bot accurately through given distance or rotate a certain angle.

 

Indicators
  • LCD: LCD is used to display any message on the run. It can be used to display any error or exception messages or it can be used to display “successful” message after the task is over
  • Buzzer: According to our task, buzzer must be on, if the bot finds a black object and also there must be a long buzzer after the task is completely over. For these reasons, a 3 KHz piezo buzzer is used.

 

Mechanical Components

 

  • Mechanism to drop magnets

The servo motor which will be used in our mechanism to drop magnets and put out fires. For controlling it, we will connect the servo to one of the servo slots provided in the firebird kit. It has an internal power supply which is provided by the “5V servo supply”. For controlling the angle through which it rotates we shall write the appropriate code getting help from the sample code provided.

 

  • Diagram of the mechanism

fire_1

 

  • Power Management                                         

For this project, we use Fire Bird V bot. Fire Bird V is powered by 9.6V rechargeable on-board intelligent Nickel Metal Hydride battery pack. The battery should be charged by providing a voltage supply between 12V (fully charged) to 8V (discharged). Avoid using external charger for accidental damage to the batteries and may even cause permanent damage.

The Fire Bird V Power Management block performs the following functions:

  1. Battery voltage monitoring and Smart battery charging
  2. Regulated supply for on-board payload
  3. Battery current sensing (optional).

The power is supplied to:

  1. The processing unit requires 5V, 1A of regulated power supply
  2. DC motors require 12V and 300mA current. (Provided by motor driver L293D).
  3. White line sensors and IR proximity sensors are 3.3V sensor.
  4. Sharp IR sensors require 5V of power supply.
  5. Servo motor pod requires 5V.

 

 

ARENA ANALYSIS


 

Navigation Scheme/Algorithm 

  • First the bot moves forward and checks if a door is present.
  • If present the bot enters the room.
  • Inside the room black line follower is used.
  • It follows the line and checks for presence of fire.
  • If detected, the mechanism drops the magnet and the bot makes a 180 degree turn.
  • On exiting the room, wall following algorithm is used to reach the central point.
  • The above steps are repeated till all four rooms are checked.

 

 

CONCLUSION


 

Over the period of the project, we faced many difficulties. These included dropping the magnets correctly into the depostion slot to put out fires. The most difficult challenge we faced, however, was interfacing the white line sensor with the bot for detection of the fire leds.  We overcame these difficulties and completed this project, which can be used for fire fighting.

 


 

 

CODE:

#define F_CPU 14745600

#include <avr/io.h>

#include <avr/interrupt.h>

#include <util/delay.h>

 

#include <math.h> //included to support power function

#include “lcd.h”

 

void port_init();

void timer5_init();

void velocity(unsigned char, unsigned char);

void motors_delay();

 

unsigned char ADC_Conversion(unsigned char);

int c=0,angle=0,LED=1;

unsigned char ADC_Value;

unsigned char flag = 0, fl=0,count=0;

unsigned int sharp9 = 0,sharp11=0,sharp13=0;

unsigned char Left_white_line = 0;

unsigned char Center_white_line = 0;

unsigned char Right_white_line = 0;

volatile unsigned long int ShaftCountLeft = 0; //to keep track of left position encoder

volatile unsigned long int ShaftCountRight = 0; //to keep track of right position encoder

volatile unsigned int Degrees; //to accept angle in degrees for turning

 

void timer1_init(void)

{

TCCR1B = 0x00; //stop

TCNT1H = 0xFC; //Counter high value to which OCR1xH value is to be compared with

TCNT1L = 0x01;    //Counter low value to which OCR1xH value is to be compared with

OCR1AH = 0x03;  //Output compare Register high value for servo 1

OCR1AL = 0xFF;    //Output Compare Register low Value For servo 1

OCR1BH = 0x03;  //Output compare Register high value for servo 2

OCR1BL = 0xFF;    //Output Compare Register low Value For servo 2

OCR1CH = 0x03;  //Output compare Register high value for servo 3

OCR1CL = 0xFF;    //Output Compare Register low Value For servo 3

ICR1H  = 0x03;

ICR1L  = 0xFF;

TCCR1A = 0xAB; /*{COM1A1=1, COM1A0=0; COM1B1=1, COM1B0=0; COM1C1=1 COM1C0=0}

For Overriding normal port functionality to OCRnA outputs.

{WGM11=1, WGM10=1} Along With WGM12 in TCCR1B for Selecting FAST PWM Mode*/

TCCR1C = 0x00;

TCCR1B = 0x0C; //WGM12=1; CS12=1, CS11=0, CS10=0 (Prescaler=256)

}

void servo1_pin_config (void)

{

DDRB  = DDRB | 0x20;  //making PORTB 5 pin output

PORTB = PORTB | 0x20; //setting PORTB 5 pin to logic 1

}

unsigned int Sharp_GP2D12_estimation(unsigned char adc_reading)

{

float distance;

unsigned int distanceInt;

distance = (int)(10.00*(2799.6*(1.00/(pow(adc_reading,1.1546)))));

distanceInt = (int)distance;

if(distanceInt>800)

{

distanceInt=800;

}

return distanceInt;

}

void motion_pin_config (void)

{

DDRA = DDRA | 0x0F;

PORTA = PORTA & 0xF0;

DDRL = DDRL | 0x18;   //Setting PL3 and PL4 pins as output for PWM generation

PORTL = PORTL | 0x18; //PL3 and PL4 pins are for velocity control using PWM.

}

 

//Function to configure INT4 (PORTE 4) pin as input for the left position encoder

void left_encoder_pin_config (void)

{

DDRE  = DDRE & 0xEF;  //Set the direction of the PORTE 4 pin as input

PORTE = PORTE | 0x10; //Enable internal pull-up for PORTE 4 pin

}

 

//Function to configure INT5 (PORTE 5) pin as input for the right position encoder

void right_encoder_pin_config (void)

{

DDRE  = DDRE & 0xDF;  //Set the direction of the PORTE 4 pin as input

PORTE = PORTE | 0x20; //Enable internal pull-up for PORTE 4 pin

}

 

//Function to initialize ports

void port_init()

{

motion_pin_config(); //robot motion pins config

left_encoder_pin_config(); //left encoder pin config

right_encoder_pin_config(); //right encoder pin config

lcd_port_config();

adc_pin_config();

motion_pin_config();

servo1_pin_config();

}

 

void left_position_encoder_interrupt_init (void) //Interrupt 4 enable

{

cli(); //Clears the global interrupt

EICRB = EICRB | 0x02; // INT4 is set to trigger with falling edge

EIMSK = EIMSK | 0x10; // Enable Interrupt INT4 for left position encoder

sei();   // Enables the global interrupt

}

 

void right_position_encoder_interrupt_init (void) //Interrupt 5 enable

{

cli(); //Clears the global interrupt

EICRB = EICRB | 0x08; // INT5 is set to trigger with falling edge

EIMSK = EIMSK | 0x20; // Enable Interrupt INT5 for right position encoder

sei();   // Enables the global interrupt

}

 

//ISR for right position encoder

ISR(INT5_vect)

{

ShaftCountRight++;  //increment right shaft position count

}

 

 

//ISR for left position encoder

ISR(INT4_vect)

{

ShaftCountLeft++;  //increment left shaft position count

}

 

 

//Function used for setting motor’s direction

void motion_set (unsigned char Direction)

{

unsigned char PortARestore = 0;

 

Direction &= 0x0F;                               // removing upper nibbel for the protection

PortARestore = PORTA;                       // reading the PORTA original status

PortARestore &= 0xF0;                        // making lower direction nibbel to 0

PortARestore |= Direction; // adding lower nibbel for forward command and restoring the PORTA status

PORTA = PortARestore;                       // executing the command

}

 

void forward (void) //both wheels forward

{

motion_set(0x06);

}

 

void back (void) //both wheels backward

{

motion_set(0x09);

}

 

void left (void) //Left wheel backward, Right wheel forward

{

motion_set(0x05);

}

 

void right (void) //Left wheel forward, Right wheel backward

{

motion_set(0x0A);

}

 

void soft_left (void) //Left wheel stationary, Right wheel forward

{

motion_set(0x04);

}

 

void soft_right (void) //Left wheel forward, Right wheel is stationary

{

motion_set(0x02);

}

 

void soft_left_2 (void) //Left wheel backward, right wheel stationary

{

motion_set(0x01);

}

 

void soft_right_2 (void) //Left wheel stationary, Right wheel backward

{

motion_set(0x08);

}

 

void stop (void)

{

motion_set(0x00);

}

 

 

//Function used for turning robot by specified degrees

void angle_rotate(unsigned int Degrees)

{

float ReqdShaftCount = 0;

unsigned long int ReqdShaftCountInt = 0;

 

ReqdShaftCount = (float) Degrees/ 4.090; // division by resolution to get shaft count

ReqdShaftCountInt = (unsigned int) ReqdShaftCount;

ShaftCountRight = 0;

ShaftCountLeft = 0;

 

while (1)

{

if((ShaftCountRight >= ReqdShaftCountInt) | (ShaftCountLeft >= ReqdShaftCountInt))

break;

}

stop(); //Stop robot

}

 

//Function used for moving robot forward by specified distance

 

void linear_distance_mm(unsigned int DistanceInMM)

{

float ReqdShaftCount = 0;

unsigned long int ReqdShaftCountInt = 0;

 

ReqdShaftCount = DistanceInMM / 5.338; // division by resolution to get shaft count

ReqdShaftCountInt = (unsigned long int) ReqdShaftCount;

 

ShaftCountRight = 0;

while(1)

{

if(ShaftCountRight > ReqdShaftCountInt)

{

break;

}

}

stop(); //Stop robot

}

 

void forward_mm(unsigned int DistanceInMM)

{

forward();

linear_distance_mm(DistanceInMM);

}

 

void back_mm(unsigned int DistanceInMM)

{

back();

linear_distance_mm(DistanceInMM);

}

 

void left_degrees(unsigned int Degrees)

{

// 88 pulses for 360 degrees rotation 4.090 degrees per count

left(); //Turn left

angle_rotate(Degrees);

}

 

 

 

void right_degrees(unsigned int Degrees)

{

// 88 pulses for 360 degrees rotation 4.090 degrees per count

right(); //Turn right

angle_rotate(Degrees);

}

 

 

void soft_left_degrees(unsigned int Degrees)

{

// 176 pulses for 360 degrees rotation 2.045 degrees per count

soft_left(); //Turn soft left

Degrees=Degrees*2;

angle_rotate(Degrees);

}

 

void soft_right_degrees(unsigned int Degrees)

{

// 176 pulses for 360 degrees rotation 2.045 degrees per count

soft_right();  //Turn soft right

Degrees=Degrees*2;

angle_rotate(Degrees);

}

 

void soft_left_2_degrees(unsigned int Degrees)

{

// 176 pulses for 360 degrees rotation 2.045 degrees per count

soft_left_2(); //Turn reverse soft left

Degrees=Degrees*2;

angle_rotate(Degrees);

}

 

void soft_right_2_degrees(unsigned int Degrees)

{

// 176 pulses for 360 degrees rotation 2.045 degrees per count

soft_right_2();  //Turn reverse soft right

Degrees=Degrees*2;

angle_rotate(Degrees);

}

void servo_1(unsigned char degrees)

{

float PositionPanServo = 0;

PositionPanServo = ((float)degrees / 1.86) + 35.0;

OCR1AH = 0x00;

OCR1AL = (unsigned char) PositionPanServo;

}

void servo_1_free (void) //makes servo 1 free rotating

{

OCR1AH = 0x03;

OCR1AL = 0xFF; //Servo 1 off

}

//Function to initialize all the devices

void init_devices_1()

{

cli(); //Clears the global interrupt

port_init();  //Initializes all the ports

left_position_encoder_interrupt_init();

right_position_encoder_interrupt_init();

sei();   // Enables the global interrupt

 

}

 

void init_devices_2()

{

cli(); //Clears the global interrupts

port_init();

adc_init();

timer5_init();

timer1_init();

sei();   //Enables the global interrupts

}

 

 

//Function to configure LCD port

void lcd_port_config (void)

{

DDRC = DDRC | 0xF7; //all the LCD pin’s direction set as output

PORTC = PORTC & 0x80; // all the LCD pins are set to logic 0 except PORTC 7

}

 

//ADC pin configuration

void adc_pin_config (void)

{

DDRF = 0x00;

PORTF = 0x00;

DDRK = 0x00;

PORTK = 0x00;

}

 

 

//Function to Initialize PORTS

/*void port_init()

{

lcd_port_config();

adc_pin_config();

motion_pin_config();

}*/

 

// Timer 5 initialized in PWM mode for velocity control

// Prescale:256

// PWM 8bit fast, TOP=0x00FF

// Timer Frequency:225.000Hz

void timer5_init()

{

TCCR5B = 0x00;    //Stop

TCNT5H = 0xFF;     //Counter higher 8-bit value to which OCR5xH value is compared with

TCNT5L = 0x01;     //Counter lower 8-bit value to which OCR5xH value is compared with

OCR5AH = 0x00;   //Output compare register high value for Left Motor

OCR5AL = 0xFF;     //Output compare register low value for Left Motor

OCR5BH = 0x00;   //Output compare register high value for Right Motor

OCR5BL = 0xFF;     //Output compare register low value for Right Motor

OCR5CH = 0x00;   //Output compare register high value for Motor C1

OCR5CL = 0xFF;     //Output compare register low value for Motor C1

TCCR5A = 0xA9;    /*{COM5A1=1, COM5A0=0; COM5B1=1, COM5B0=0; COM5C1=1 COM5C0=0}

For Overriding normal port functionality to OCRnA outputs.

{WGM51=0, WGM50=1} Along With WGM52 in TCCR5B for Selecting FAST PWM 8-bit Mode*/

 

TCCR5B = 0x0B;    //WGM12=1; CS12=0, CS11=1, CS10=1 (Prescaler=64)

}

 

void adc_init()

{

ADCSRA = 0x00;

ADCSRB = 0x00;                    //MUX5 = 0

ADMUX = 0x20;                    //Vref=5V external — ADLAR=1 — MUX4:0 = 0000

ACSR = 0x80;

ADCSRA = 0x86;                    //ADEN=1 — ADIE=1 — ADPS2:0 = 1 1 0

}

 

//Function For ADC Conversion

unsigned char ADC_Conversion(unsigned char Ch)

{

unsigned char a;

if(Ch>7)

{

ADCSRB = 0x08;

}

Ch = Ch & 0x07;

ADMUX= 0x20| Ch;

ADCSRA = ADCSRA | 0x40;                  //Set start conversion bit

while((ADCSRA&0x10)==0);                //Wait for conversion to complete

a=ADCH;

ADCSRA = ADCSRA|0x10; //clear ADIF (ADC Interrupt Flag) by writing 1 to it

ADCSRB = 0x00;

return a;

}

 

//Function To Print Sesor Values At Desired Row And Coloumn Location on LCD

void print_sensor(char row, char coloumn,unsigned char channel)

{

 

ADC_Value = ADC_Conversion(channel);

lcd_print(row, coloumn, ADC_Value, 3);

}

 

//Function for velocity control

void velocity (unsigned char left_motor, unsigned char right_motor)

{

OCR5AL = (unsigned char)left_motor;

OCR5BL = (unsigned char)right_motor;

}

 

 

 

/*void init_devices (void)

{

cli(); //Clears the global interrupts

port_init();

adc_init();

timer5_init();

sei();   //Enables the global interrupts

}*/

void A (void)

{

while(1)

{

 

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);          //Getting data of Right WL Sensor

sharp11=ADC_Conversion(11);

sharp11=Sharp_GP2D12_estimation(sharp11);

//sharp9=ADC_Conversion(9);

//sharp9=Sharp_GP2D12_estimation(sharp9);

LED=ADC_Conversion(7);

 

flag=0;

 

print_sensor(1,1,3);             //Prints value of White Line Sensor1

print_sensor(1,5,2);             //Prints Value of White Line Sensor2

print_sensor(1,9,1);             //Prints Value of White Line Sensor3

//lcd_print(2,1,sharp9,3);

//             lcd_print(2,5,sharp11,3);

 

 

 

if(Center_white_line>0x10)//black

{

flag=1;

forward();

velocity(150,150);

}

 

if((Left_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(130,50);

}

 

if((Right_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(50,130);

}

 

if(Center_white_line<0x10 && Left_white_line<0x10 && Right_white_line<0x10)

{

forward();

 

velocity(130,50);

}

//if((Center_white_line>0x10 && Left_white_line>0x10 && c>=2) || (Center_white_line>0x10 && Right_white_line>0x10 && c>=2))

//{

if (LED<0x20 & sharp11<275)

{

 

stop();

_delay_ms(750);

angle+=45;

servo_1(angle);

_delay_ms(1000);

//soft_right_degrees(89.4);

stop();

_delay_ms(1000);

left_degrees(90);

_delay_ms(750);

 

c=0;

break;

}

if(sharp11<100)

{

stop();

_delay_ms(1000);

left_degrees(180);

_delay_ms(750);

break;

}

 

//}

if((Center_white_line>0x10 && Left_white_line>0x10 && c<2) || (Center_white_line>0x10 && Right_white_line>0x10 && c<2))

{

++c;

_delay_ms(750);

}

}

fl=0;

while(1)

{

 

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);          //Getting data of Right WL Sensor

sharp11=ADC_Conversion(11);

sharp11=Sharp_GP2D12_estimation(sharp11);

sharp9=ADC_Conversion(9);

sharp9=Sharp_GP2D12_estimation(sharp9);

 

flag=0;

 

print_sensor(1,1,3);             //Prints value of White Line Sensor1

print_sensor(1,5,2);             //Prints Value of White Line Sensor2

print_sensor(1,9,1);             //Prints Value of White Line Sensor3

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

if(Center_white_line>0x10)

{

flag=1;

forward();

velocity(150,150);

}

 

if((Left_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(130,50);

}

 

if((Right_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(50,130);

}

 

if(Center_white_line<0x10 && Left_white_line<0x10 && Right_white_line<0x10)

{

forward();

 

velocity(50,130);

}

if(sharp9>700)

fl=1;

if(Center_white_line>0x10 && sharp11>700 && fl==1)

{

 

break;

}

}

while(1)

{

 

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);          //Getting data of Right WL Sensor

sharp11=ADC_Conversion(11);

sharp11=Sharp_GP2D12_estimation(sharp11);

//sharp9=ADC_Conversion(9);

//sharp9=Sharp_GP2D12_estimation(sharp9);

 

flag=0;

 

print_sensor(1,1,3);             //Prints value of White Line Sensor1

print_sensor(1,5,2);             //Prints Value of White Line Sensor2

print_sensor(1,9,1);             //Prints Value of White Line Sensor3

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

if(Center_white_line>0x10)

{

flag=1;

forward();

velocity(150,150);

}

 

if((Left_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(130,50);

}

 

if((Right_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(50,130);

}

 

if(Center_white_line<0x10 && Left_white_line<0x10 && Right_white_line<0x10 && sharp11>400)

{

forward();

 

velocity(50,130);

}

 

if(Center_white_line<0x10 && Left_white_line<0x10 && Right_white_line<0x10 && sharp11<=400)

{

break;

}

 

}

while (sharp11>200)

{

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

sharp11=ADC_Conversion(11);

sharp11=Sharp_GP2D12_estimation(sharp11);

forward();

velocity(180,180);

}

soft_right_degrees(90);

while(1)

{

sharp9=ADC_Conversion(9);

sharp9=Sharp_GP2D12_estimation(sharp9);

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

if (sharp9>200)

{

forward();

velocity(50,130);

}

if (sharp9<200)

{

forward();

velocity(130,50);

}

if (sharp9==200)

{

forward();

velocity (255,255);

}

if (Center_white_line>0x10 || Left_white_line>0x10 || Right_white_line>0x10)

{

break;

}

 

}

 

while(1)

{

 

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);          //Getting data of Right WL Sensor

//sharp11=ADC_Conversion(11);

//sharp11=Sharp_GP2D12_estimation(sharp11);

//sharp9=ADC_Conversion(9);

//sharp9=Sharp_GP2D12_estimation(sharp9);

 

flag=0;

 

print_sensor(1,1,3);             //Prints value of White Line Sensor1

print_sensor(1,5,2);             //Prints Value of White Line Sensor2

print_sensor(1,9,1);             //Prints Value of White Line Sensor3

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

if(Center_white_line>0x10)

{

flag=1;

forward();

velocity(150,150);

}

 

if((Left_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(130,50);

}

 

if((Right_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(50,130);

}

 

 

if(Center_white_line>0x10 && Left_white_line>0x10 && Right_white_line>0x10)

{

soft_left_degrees(92);

_delay_ms(1000);

stop();

_delay_ms(1000);

count++;

break;

}

}

}

 

void B (void)

{

while(1)

{

 

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);          //Getting data of Right WL Sensor

sharp11=ADC_Conversion(11);

sharp11=Sharp_GP2D12_estimation(sharp11);

sharp9=ADC_Conversion(9);

sharp9=Sharp_GP2D12_estimation(sharp9);

LED=ADC_Conversion(7);

 

flag=0;

 

print_sensor(1,1,3);             //Prints value of White Line Sensor1

print_sensor(1,5,2);             //Prints Value of White Line Sensor2

print_sensor(1,9,1);             //Prints Value of White Line Sensor3

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

if(Center_white_line>0x10)

{

flag=1;

forward();

velocity(150,150);

}

 

if((Left_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(130,50);

}

 

if((Right_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(50,130);

}

 

if(Center_white_line<0x10 && Left_white_line<0x10 && Right_white_line<0x10)

{

forward();

 

velocity(50,130);

}

//if((Center_white_line>0x10 && Left_white_line>0x10 && c>=2) || (Center_white_line>0x10 && Right_white_line>0x10 && c>=2))

//{

if (LED<0x20 && sharp11<275)

{

 

stop();

_delay_ms(750);

angle+=45;

servo_1(angle);

_delay_ms(1000);

//soft_left_degrees(89.3);

stop();

_delay(1000);

right_degrees(90);

_delay_ms(750);

c=0;

break;

}

if(sharp11<100)

{

stop();

_delay_ms(1000);

right_degrees(180);

_delay_ms(750);

break;

}

//}

if((Center_white_line>0x10 && Left_white_line>0x10 && c<2) || (Center_white_line>0x10 && Right_white_line>0x10 && c<2))

{

++c;

_delay_ms(750);

}

 

 

}

fl=0;

while(1)

{

 

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);          //Getting data of Right WL Sensor

sharp11=ADC_Conversion(11);

sharp11=Sharp_GP2D12_estimation(sharp11);

sharp13=ADC_Conversion(13);

sharp13=Sharp_GP2D12_estimation(sharp13);

 

flag=0;

 

print_sensor(1,1,3);             //Prints value of White Line Sensor1

print_sensor(1,5,2);             //Prints Value of White Line Sensor2

print_sensor(1,9,1);             //Prints Value of White Line Sensor3

//lcd_print(2,1,sharp9,3);

//             lcd_print(2,5,sharp11,3);

 

 

if(Center_white_line>0x10)//black

{

flag=1;

forward();

velocity(150,150);

}

 

if((Left_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(130,50);

}

 

if((Right_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(50,130);

}

 

if(Center_white_line<0x10 && Left_white_line<0x10 && Right_white_line<0x10)

{

forward();

 

velocity(130,50);

}

if(sharp13==800)

fl=1;

if(Center_white_line>0x10 && sharp11==800 && fl==1)

{

break;

}

}

 

while(1)

{

 

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);          //Getting data of Right WL Sensor

sharp11=ADC_Conversion(11);

sharp11=Sharp_GP2D12_estimation(sharp11);

//sharp9=ADC_Conversion(9);

//sharp9=Sharp_GP2D12_estimation(sharp9);

 

flag=0;

 

print_sensor(1,1,3);             //Prints value of White Line Sensor1

print_sensor(1,5,2);             //Prints Value of White Line Sensor2

print_sensor(1,9,1);             //Prints Value of White Line Sensor3

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

if(Center_white_line>0x10)

{

flag=1;

forward();

velocity(150,150);

}

 

if((Left_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(130,50);

}

 

if((Right_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(50,130);

}

 

if(Center_white_line<0x10 && Left_white_line<0x10 && Right_white_line<0x10 && sharp11>400)

{

forward();

 

velocity(50,130);

}

 

if(Center_white_line<0x10 && Left_white_line<0x10 && Right_white_line<0x10 && sharp11<=400)

{

break;

}

 

}

while (sharp11>200)

{

sharp11=ADC_Conversion(11);

sharp11=Sharp_GP2D12_estimation(sharp11);

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

forward();

velocity(130,130);

}

soft_right_degrees(90);

while(1)

{

 

sharp9=ADC_Conversion(9);

sharp9=Sharp_GP2D12_estimation(sharp9);

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

if (sharp9>200)

{

forward();

velocity(50,130);

}

if (sharp9<200)

{

forward();

velocity(130,50);

}

if (sharp9==200)

{

forward();

velocity (255,255);

}

if (Center_white_line>0x10 || Left_white_line>0x10 || Right_white_line>0x10)

{

break;

}

 

}

 

while(1)

{

 

Left_white_line = ADC_Conversion(3);             //Getting data of Left WL Sensor

Center_white_line = ADC_Conversion(2);        //Getting data of Center WL Sensor

Right_white_line = ADC_Conversion(1);          //Getting data of Right WL Sensor

//sharp11=ADC_Conversion(11);

//sharp11=Sharp_GP2D12_estimation(sharp11);

//sharp9=ADC_Conversion(9);

//sharp9=Sharp_GP2D12_estimation(sharp9);

 

flag=0;

 

print_sensor(1,1,3);             //Prints value of White Line Sensor1

print_sensor(1,5,2);             //Prints Value of White Line Sensor2

print_sensor(1,9,1);             //Prints Value of White Line Sensor3

//lcd_print(2,1,sharp9,3);

//lcd_print(2,5,sharp11,3);

if(Center_white_line>0x10)

{

flag=1;

forward();

velocity(150,150);

}

 

if((Left_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(130,50);

}

 

if((Right_white_line<0x10) && (flag==0))

{

flag=1;

forward();

velocity(50,130);

}

 

if(Center_white_line>0x10 && Left_white_line>0x10 && Right_white_line>0x10)

{

soft_left_degrees(92);

_delay_ms(1000);

stop();

_delay_ms(750);

count++;

break;

}

}

}

 

 

 

 

 

//Main Function

int main()

{

 

 

init_devices_1();

init_devices_2();

lcd_set_4bit();

lcd_init();

 

servo_1(0);

_delay_ms(1000);

forward_mm(195);

while(count<4)

{

c=0;

 

forward_mm(270); //Moves robot forward 100mm

stop();

_delay_ms(750);

 

 

sharp9=ADC_Conversion(9);

sharp9=Sharp_GP2D12_estimation(sharp9);

 

/*forward_mm(30); //Moves robot forward 100mm

stop();

_delay_ms(750);*/

 

if(sharp9>200)

{

soft_left_degrees(83); //Rotate (soft turn) by 90 degrees

stop();

_delay_ms(750);

A();

}

 

else

{

forward_mm(400); //Moves robot forward 100mm

stop();

_delay_ms(750);

soft_left_degrees(83); //Rotate (soft turn) by 90 degrees

stop();

_delay_ms(750);

B();

}

}

DDRC = DDRC | 0x08;                          //Setting PORTC 3 as output

PORTC = PORTC & 0xF7;                     //Setting PORTC 3 logic low to turnoff buzzer

unsigned char port_restore = 0;

port_restore = PINC;

port_restore = port_restore | 0x08;

PORTC = port_restore;

_delay_ms(1000);                                //delay

port_restore = PINC;

port_restore = port_restore & 0xF7;

PORTC = port_restore;

_delay_ms(1000);                                //delay