0% found this document useful (0 votes)
106 views11 pages

Implementation of White Line Following Firebird V Robot

The document describes implementing a white line following robot using a Firebird V robot. It includes hardware details of the robot such as sensors, microcontrollers, communication methods. It also provides the embedded C code to initialize ports, read sensor values, and control motors to follow a white line. Supporting files for LCD initialization and commands are also included.

Uploaded by

rjv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views11 pages

Implementation of White Line Following Firebird V Robot

The document describes implementing a white line following robot using a Firebird V robot. It includes hardware details of the robot such as sensors, microcontrollers, communication methods. It also provides the embedded C code to initialize ports, read sensor values, and control motors to follow a white line. Supporting files for LCD initialization and commands are also included.

Uploaded by

rjv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

GROUP 3: EMBEDDED AND NANOTECHNOLOGY

12. IMPLEMENTATION OF WHITE LINE FOLLOWING FIREBIRD V ROBOT

12.1 AIM:

The aim of this experiment is to get you familiar with the three white line sensors and implement white line following
using Firebird V. In this experiment, you have to write a program to make the robot follow a white line. The three
white line sensors are connected to ADC channel numbers as listed below.

12.2 RESOURCES:

12.2.1 HARDWARE:

• Firebird V robot
• NEX AVR USB ISP STK500V2 Cable
12.2.2 SOFTWARE:

Atmel Studio 6.0

Integrated Development Environment (IDE) to be used to develop and debug your embedded programs.

1
12.3 HARDWARE DESCRIPTION:

12.3.1 Fire Bird V Block Diagram

12.3.2 Fire Bird V ATMEGA2560 technical specification

Microcontroller:

• Atmel ATMEGA2560 as Master microcontroller (AVR architecture-based Microcontroller)


• Atmel ATMEGA8 as Slave microcontroller (AVR architecture-based Microcontroller)

Sensors:

• Three white line sensors (extendable to 7)


• Five Sharp GP2Y0A02YK IR range sensor (One in default configuration)
• Eight analog IR proximity sensors
• Two position encoders (extendable to four)
• Battery voltage sensing

Indicators:

• 2 x 16 Characters LCD
• Buzzer and Indicator LEDs

Control:

• Autonomous Control
• PC as Master and Robot as Slave in wired or wireless mode

2
Communication:

• USB Communication
• Wired RS232 (serial) communication
• Wireless ZigBee Communication (2.4GHZ) (if XBee wireless module is installed)
• Wi-Fi communication (if Wi-Fi module is installed)
• Bluetooth communication (if Bluetooth wireless module is installed)
• Simplex infrared communication (From infrared remote to robot)

Dimensions:

• Diameter: 16cm
• Height: 8.5cm
• Weight: 1100gms

Power:

• 9.6V NiMH battery pack and external Auxiliary power from battery charger.
• On Board Battery monitoring and intelligent battery charger.

Battery Life:

• 2 Hours, while motors are operational at 75% of time

Locomotion:

• Two DC geared motors in differential drive configuration and caster wheel at front as support
• Top Speed: 24 cm / second
• Wheel Diameter: 51mm
• Position encoder: 30 pulses per revolution
• Position encoder resolution: 5.44 mm

3
12.4 Embedded C code :

12.4.1 File name : white line.c

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <math.h>
#include "lcd.c"
void port_init();
void timer5_init();
void velocity(unsigned char, unsigned char);
void motors_delay();
unsigned char ADC_Conversion(unsigned char);
unsigned char ADC_Value;
unsigned char flag = 0;
unsigned char Left_white_line = 0;
unsigned char Center_white_line = 0;
unsigned char Right_white_line = 0;
void lcd_port_config (void)
{
DDRC = DDRC | 0xF7;
PORTC = PORTC & 0x80;
}
void adc_pin_config (void)
{
DDRF = 0x00;
PORTF = 0x00;
DDRK = 0x00;
PORTK = 0x00;
}
void motion_pin_config (void)
{
DDRA = DDRA | 0x0F;
PORTA = PORTA & 0xF0;
DDRL = DDRL | 0x18;
PORTL = PORTL | 0x18;
}
void port_init()
{
lcd_port_config();
adc_pin_config();
motion_pin_config();
}
void timer5_init()
{
TCCR5B = 0x00;
TCNT5H = 0xFF;
TCNT5L = 0x01;
OCR5AH = 0x00;
OCR5AL = 0xFF;
OCR5BH = 0x00;
OCR5BL = 0xFF;
OCR5CH = 0x00;
OCR5CL = 0xFF;
TCCR5A = 0xA9;
4
TCCR5B = 0x0B;
}
void adc_init()
{
ADCSRA = 0x00;
ADCSRB = 0x00;
ADMUX = 0x20;
ACSR = 0x80;
ADCSRA = 0x86;
}
unsigned char ADC_Conversion(unsigned char Ch)
{
unsigned char a;
if(Ch>7)
{
ADCSRB = 0x08;
}
Ch = Ch & 0x07;
ADMUX= 0x20| Ch;
ADCSRA = ADCSRA | 0x40;
while((ADCSRA&0x10)==0);
a=ADCH;
ADCSRA = ADCSRA|0x10;
ADCSRB = 0x00;
return a;
}
void print_sensor(char row, char coloumn,unsigned char
channel)
{
ADC_Value = ADC_Conversion(channel);

}
void velocity (unsigned char left_motor, unsigned char
right_motor)
{
OCR5AL = (unsigned char)left_motor;
OCR5BL = (unsigned char)right_motor;
}
void motion_set (unsigned char Direction)
{
unsigned char PortARestore = 0;
Direction &= 0x0F;
PortARestore = PORTA;
PortARestore &= 0xF0;
PortARestore |= Direction;
PORTA = PortARestore;
}
void forward (void)
{
motion_set (0x06);
}
void stop (void)
{
motion_set (0x00);
}
5
void init_devices (void)
{
cli();
port_init();
adc_init();
timer5_init();
sei(); }
int main()
{
init_devices();
lcd_set_4bit();
lcd_init();
while(1)
{
Left_white_line = ADC_Conversion(3);
Center_white_line = ADC_Conversion(2);
Right_white_line = ADC_Conversion(1);
flag=0;
print_sensor(1,1,3);
print_sensor(1,5,2);
print_sensor(1,9,1);
if(Center_white_line<0x28)
{
flag=1;
forward();
velocity(150,150);
}
if((Left_white_line>0x28) && (flag==0))
{
flag=1;
forward();
velocity(130,50);
}
if((Right_white_line>0x28) && (flag==0))
{
flag=1;
forward();
velocity(50,130);
}
if(Center_white_line>0x28&& Left_white_line>0x28&&
Right_white_line>0x28)
{
forward();
velocity(0,0);
}
}
}

12.4.2 Mandatory Supporting Files:

12.4.2.1 File Name : lcd.h

#ifndef LCD_H_
6
#define LCD_H_

#define RS 0
#define RW 1
#define EN 2
#define lcd_port PORTC

#define sbit(reg,bit) reg |= (1<<bit) // Macro defined for Setting a bit of any register.
#define cbit(reg,bit) reg &= ~(1<<bit) // Macro defined for Clearing a bit of any register.

void init_ports();
void lcd_reset();
void lcd_init();
void lcd_wr_command(unsigned char);
void lcd_wr_char(char);
void lcd_line1();
void lcd_line2();

unsigned int temp;


unsigned int unit;
unsigned int tens;
unsigned int hundred;
unsigned int thousand;
unsigned int million;

#endif

12.4.2.2 File Name : lcd.c

#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h" // user-defined header file - it is included in project folder

//Function to set LCD in 4-bit mode


void lcd_set_4bit()
{
_delay_ms(1);

cbit(lcd_port,RS); //RS=0 --- Command Input


cbit(lcd_port,RW); //RW=0 --- Writing to LCD
lcd_port = 0x30; //Sending 3
sbit(lcd_port,EN); //Set Enable Pin
_delay_ms(5); //Delay
cbit(lcd_port,EN); //Clear Enable Pin

_delay_ms(1);

cbit(lcd_port,RS); //RS=0 --- Command Input


cbit(lcd_port,RW); //RW=0 --- Writing to LCD
lcd_port = 0x30; //Sending 3
sbit(lcd_port,EN); //Set Enable Pin
_delay_ms(5); //Delay
cbit(lcd_port,EN); //Clear Enable Pin

7
_delay_ms(1);

cbit(lcd_port,RS); //RS=0 --- Command Input


cbit(lcd_port,RW); //RW=0 --- Writing to LCD
lcd_port = 0x30; //Sending 3
sbit(lcd_port,EN); //Set Enable Pin
_delay_ms(5); //Delay
cbit(lcd_port,EN); //Clear Enable Pin

_delay_ms(1);

cbit(lcd_port,RS); //RS=0 --- Command Input


cbit(lcd_port,RW); //RW=0 --- Writing to LCD
lcd_port = 0x20; //Sending 2 to initialise LCD 4-bit mode
sbit(lcd_port,EN); //Set Enable Pin
_delay_ms(5); //Delay
cbit(lcd_port,EN); //Clear Enable Pin

//Function to Initialize LCD


void lcd_init()
{
lcd_set_4bit();
_delay_ms(1);

lcd_wr_command(0x28); //LCD 4-bit mode and 2 lines.


lcd_wr_command(0x01);
lcd_wr_command(0x06);
lcd_wr_command(0x0E);
lcd_wr_command(0x80);

//Function to Write Command on LCD


void lcd_wr_command(unsigned char cmd)
{
unsigned char temp;
temp = cmd;
temp = temp & 0xF0;
lcd_port &= 0x0F;
lcd_port |= temp;
cbit(lcd_port,RS);
cbit(lcd_port,RW);
sbit(lcd_port,EN);
_delay_ms(5);
cbit(lcd_port,EN);

cmd = cmd & 0x0F;


cmd = cmd<<4;
lcd_port &= 0x0F;
lcd_port |= cmd;
cbit(lcd_port,RS);
cbit(lcd_port,RW);
8
sbit(lcd_port,EN);
_delay_ms(5);
cbit(lcd_port,EN);
}

//Function to Write Data on LCD


void lcd_wr_char(char letter)
{
char temp;
temp = letter;
temp = (temp & 0xF0);
lcd_port &= 0x0F;
lcd_port |= temp;
sbit(lcd_port,RS);
cbit(lcd_port,RW);
sbit(lcd_port,EN);
_delay_ms(5);
cbit(lcd_port,EN);

letter = letter & 0x0F;


letter = letter<<4;
lcd_port &= 0x0F;
lcd_port |= letter;
sbit(lcd_port,RS);
cbit(lcd_port,RW);
sbit(lcd_port,EN);
_delay_ms(5);
cbit(lcd_port,EN);
}

9
12.5 BURNING THE PROGRAM (HEX FILE) INTO THE FIREBIRD V ATMEGA 2560 ROBOT USING NEX AVR USB ISP
STK500V2

12.5.1 INTRODUCTION

NEX AVR USB ISP STK500V2 is a high-speed USB powered STK500V2 compatible In-System USB programmer for AVR
family of microcontrollers. It can be used with AVR Studio on Win XP platforms. For Windows7 it can be used in HID
mode with Avrdude command prompt as programming interface. Its adjustable clock speed allows programming of
microcontrollers with lower clock speeds. The programmer is powered directly from a USB port which eliminates need
for an external power supply. The programmer can also power the target board from a USB port with limited supply
current of up to 100mA. Note: The USB port of PC provides 5V DC. For 3.3V microcontrollers, please use appropriate
voltage regulators.

12.5.2 INSTALLING DRIVERS FOR HID MODE (WORKS ON ALL WINDOWS OPERATING SYSTEMS)

1. If connected, disconnect programmer from PC and insert HID/CDC jumper. Now reconnect programmer to
PC and observe the task bar for “Found New Hardware” message.
2. HID mode does not require additional drivers. It uses generic windows drivers.
3. Go to Device Manager and observe that new Human Interface Device (HID) is installed. If there are other HID
devices connected to PC, you may optionally identify each device by viewing its properties.

4. Before proceeding ensure that you have AVRDude.exe and AVRDude.conf on your PC. These files are available
in the zip file that was downloaded earlier from Nex Robotics website. (NEX Robotics Pvt. Ltd. www.nex-
robotics.com)
5. Go to Start Menu>Run and type “cmd” to open command prompt.

10
6. On the command prompt, type the path of the folder that contains avrdude.exe and avrdude.conf files.
Eg:
cd C:\AVRDude

7. On the command line type the command as shown in the fig. below. Here -p m2560 refers to the
microcontroller part number. The last section after –U in quotes specifies the location of hex file. In the
command line edit hex file location as required and connect the programmer to the target board using 10 pin
FRC cable provided with the programmer and turn ON the target board.

Syntax:
avrdude -c stk500v2 -p m2560 -P NEX-USB-ISP -U flash:w:"hex-file-location":i

8. Press enter. You should see the programming status in the command prompt window. If there is any error,
recheck ISP connection and command line parameters. (Note: to erase the chip the following command is
used)

avrdude -c stk500v2 -p m2560 -P NEX-USB-ISP -e

12.6 RESULT

Hence , white line follower using Firebird V has been implemented successfully.

11

You might also like