Implementation of White Line Following Firebird V Robot
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:
Integrated Development Environment (IDE) to be used to develop and debug your embedded programs.
1
12.3 HARDWARE DESCRIPTION:
Microcontroller:
Sensors:
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:
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 :
#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);
}
}
}
#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();
#endif
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h" // user-defined header file - it is included in project folder
_delay_ms(1);
7
_delay_ms(1);
_delay_ms(1);
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)
12.6 RESULT
Hence , white line follower using Firebird V has been implemented successfully.
11