EXPLANATION:-
The robot uses IR sensors to sense the line, an array of 8 IR LEDs (Tx) and sensors (Rx), facing
the ground has been used in this setup. The output of the sensors is an analog signal which
depends on the amount of light reflected back, this analog signal is given to the comparator to
produce 0s and 1s which are then fed to the uC.
Left Center Right
Sensor Array
Starting from the center, the sensors on the left are named L1, L2, L3, L4 and those on the right
are named R1, R2, R3, R4.
Let us assume that when a sensor is on the line it reads 0 and when it is off the line it reads 1
The uC decides the next move according to the algorithm given below which tries to position the
robot such that L1 and R1 both read 0 and the rest read 1.
L4 L3 L2 L1 R1 R2 R3 R4
1 1 1 0 0 1 1 1
Desired State L1=R1=0, and Rest=1
Algorithm:
1. L= leftmost sensor which reads 0; R= rightmost sensor which reads 0.
If no sensor on Left (or Right) is 0 then L (or R) equals 0;
Ex:
Left Center Right
Here L=3 R=0
Left Center Right
Here L=2 R=4
2. If all sensors read 1 go to step 3,
else,
If L>R Move Left
If L<R Move Right
If L=R Move Forward
Goto step 4
3. Move Clockwise if line was last seen on Right
Move Counter Clockwise if line was last seen on Left
Repeat step 3 till line is found.
4. Goto step 1.
L4 L3 L2 L1 R1 R2 R3 R4
1 0 0 1 1 1 1 1
L4 L3 L2 L1 R1 R2 R3 R4
1 1 0 0 0 0 0 0
will be updated soon...............................................
#include <avr/io.h>
#include <util/delay.h>
#define lcd_port PORTD
#define rs 0
#define rw 1
#define en 2
void lcd_init();
void lcd_cmnd(unsigned char);
void lcd_data(unsigned char);
void dis_cmnd(unsigned char);
void dis_data(unsigned char);
void lcd_init()
{
dis_cmnd(0x28);//4-bit mode
dis_cmnd(0x02);//home position
dis_cmnd(0x0c);//no cursor
dis_cmnd(0x06);//auto increment
dis_cmnd(0x01);//clear
_delay_ms(1);
}
dis_cmnd(unsigned char abc)
{
char div;
div=((0xf0)&abc);
lcd_cmnd(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_cmnd(div);
}
dis_data(unsigned char abc)
{
char div;
div=((0xf0)&abc);
lcd_data(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_data(div);
}
lcd_cmnd(unsigned char abc)
{
lcd_port=abc;
lcd_port&=~(1<<rs);//rs=0
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0
}
lcd_data(unsigned char abc)
{
lcd_port=abc;
lcd_port|=(1<<rs);//rs=1
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0
}
void string1(unsigned char abc[])
{
int i=0;
while (abc[i]!='\0')
{
char c;
c=abc[i];
if(i==16)
{
dis_cmnd(0xc0);
}
dis_data(abc[i]);
i++;
}
}
*********make a HEADER FILE named lcd1 and paste it in util folder of avr
*********LFR WITH LCD CONNECTED ON PORT D*********88
#include <avr/io.h>
#include <util/lcd1.h>
#include <util/delay.h>
void main(void)
{
DDRD=0b11111111;//lcd output
lcd_init();
DDRA=0b00000000;//sensor
DDRB=0b11111111;//motor
while(1)
{
if((PINA&0b00000011)==0b00000011)
{
dis_cmnd(0X01);
_delay_ms(10);
string1("FORWARD");
PORTB=0b00001010;//forward
_delay_ms(10);
}
if((PINA&0b00000011)==0b00000010)
{
dis_cmnd(0X01);
_delay_ms(10);
string1("RIGHT");
PORTB=0b00001000;//right
_delay_ms(10);
}
if((PINA&0b00000011)==0b00000001)
{
dis_cmnd(0X01);
_delay_ms(10);
string1("LEFT");
PORTB=0b00000010;//left
_delay_ms(10);
}
if((PINA&0b00000011)==0b00000000)
{
dis_cmnd(0X01);
_delay_ms(10);
string1("STOP");
PORTB=0b00000000;//stop
_delay_ms(10);
}
}
}
//in next post telepathic line follower (one robot follows other through rf)
No comments:
Post a Comment