Vous êtes sur la page 1sur 45

Faculty of Information Engineering & Technology

Electrical & Electronics Department

Line Tracking Robot


Using Infrared cells
For Lane keeping assistant purposes

Bachelor Thesis

By: Mina Fawzy Adly Habib


Supervisor: Dr. Tallal El- Shabrawy
st
Submission Date: February 1 , 2010
This is to certify that:

(i) The thesis comprises only my original work towards the Bachelor Degree.
(ii) Due to acknowledgment has been made in the text to all other material
used.

Mina Fawzy Adly

______________
Abstract:

In road-transport terminology, a lane departure warning system is a


mechanism designed to warn a driver when the vehicle begins to move out of its
lane on freeways and arterial roads. These systems are designed to minimize
accidents by addressing the main causes of collisions: driving error, distraction and
drowsiness.

In 2009 the National Highway Traffic Safety Administration (NHTSA) began studying
whether to mandate lane departure warning systems and frontal collision warning
systems on automobiles.

So the aim of this project is to combine the two features together in one intelligent
vehicle in hope to design a safer mean of transportation to save lives wasted on
roads yearly especially with the increase of the number of cars introduced to the
road each year.

So the need of such security systems in today's intelligent cars is essential.

The project consists of two main phases; First is to design and build a line tracking
circuit that keeps the car moving over its given course and automatically corrects the
car's course when it is accidently deflected away from the track and if it exits the
lane it can remember the last position the line was detected and restore its course,
This circuit is controlled by a microcontroller that gets the track's information by four
infrared cells mounted in the front of the car, and also controls the motors of the
car; in order to gain control to the car's steering and speed. The circuit is built as a
PCB (Printed circuit board) in order to ensure the circuit's reliability and make a
suitable sized circuit, and also to make it possible to direct the infrared cell to face
the track beneath the car.

The second phase is to build a frontal obstacle avoider circuit that automatically
stops the car and trigger the car's front light and horn once an obstacle is detected
among the car's path. Circuit is also built with a PCB technique in order to make it
have a reasonable size to be able to mount it in front of the car, and also to ensure
circuits reliability.

III
Contents

List of figures ……………………………………………………………………………………….VI

Chapter 1 Introduction ……………………………………………………………………..… 1

1.1 Project purpose ………………………………………………………………. 2


1.2 Required knowledge …………………………………………………….…. 2
1.3 Outline …………………………………………………………………………….. 3

Chapter 2 Project basics …………………………………………………………………..…. 4

2.1 Line following robot …………………………………………………………….. 4

2.2 Structure of the robot ………………………………………………………….. 4

2.3 Required components …………………………………………………………. 5

Chapter 3 Line tracking algorithm ………………………………………………………. 6

3.1 Number of cells in the sensors line ………………………………………. 6

3.1.1 Sensors precision ……………………………………………………. 7

3.2 Distance between cells ……………………………………………………….. 8

3.2.1 When robot is centered …………………………………………. 8

3.2.2 Largely spaced cells with devia on ……………………….… 8

3.2.3 Closely spaced cells with devia on …………………………. 9

3.3 Results ……………………………………………………………………………… 10

3.4 Building the cells ………………………………………………………………. 11

3.4.1 Cell implementa on …………………………………………….. 12

3.4.2 Circuit implementa ons of the sensors ………………… 13

Chapter 4 Implementa on of the robot with the microcontroller ……. 14

4.1 Introduc on ……………………………………………………………………… 14


4.2 The 8051 Microcontroller ………………………………………………….. 14

4.3 Program the microcontroller with the ISP …………………………. 15

4.3.1 Architecture of the In System Programmer ………….. 16

4.3.2 Programming the microcontroller ………………………… 18

4.4 Line following robot circuit ………………………………………………… 19

4.4.1 Design and implementa ons ………………………………… 19

4.4.2 Opera on of the robot …………………………………………. 19

4.4.3 Overview ……………………………………………………………… 20

4.4.4 Controlling motors using a motor driver ………………. 21

4.4.5 The full schema c of the circuit ……………………………. 22

4.4.6 PCB design of the circuit ………………………………………. 23

4.5 Func oning of the microcontroller …………………………………… 24

Chapter 5 C code for the microcontroller ………………………………………… 25

5.1 The C code ……………………………………………………………………..... 25

5.2 Genera ng PWM to control motors speed ……………………….. 30

Chapter 6 Obstacle detec on using infrared LEDs ……………………………. 31

6.1 Circuit implementa on ……………………………………………………… 32

6.1.1 Noise effects ………………………………………………………… 32

6.1.2 Stopping the robot when obstacle in range ………….. 33

6.2 PCB design for the obstacle avoider …………………………………… 35

Chapter 7 Conclusion ……………………………………………………………………….. 36

7.1 Possible improvements ……………………………………………………… 36

References ………………………………………………………………………………………… 38
List of figures

Figure 1: Implemented sensors line …………………………………………………… 7

Figure 2: Robot is centered over the line …………………………………………… 8

Figure 3: Largely spaced cells with devia on …………………………………….. 9

Figure 4: Closely spaced cells with deviation …………………………………….. 9

Figure 5: Sensor cell structure ………………………………………………………….. 11

Figure 6: Sensor line readings when robot is centered ……………………… 12

Figure 7: Sensor line readings when robot is on the right …………………. 12

Figure 8: Sensor line readings when robot is on the left ……………………. 12

Figure 9: Circuit of the sensors line ………………………………………………….… 13

Figure 10: Atmel AT89S52 Microcontroller ………………………………………… 15

Figure 11: Structure if the In System Programmer …………………………….. 16

Figure 12A: Connecting the microcontroller with the computer's parallel


port ………………………………………………………………………………………………..…. 17

Figure 12B: The constructed ISP ………………………………………………………… 17

Figure 13: Using of the ISP programmer ……………………………………………. 18

Figure 14: Overview ………………………………………………………………………….. 20

Figure 15: Connec ng motors to the microcontroller using a motor


driver ………………………………………………………………………………………………… 21

Figure 16: Full schema c of the robot …………………………………………….…. 22

Figure 17A-17B: PCB design of the line following robot ……………………. 23

Figure 18: Motor driver (L293D) ………………………………………………………... 24


Figure 19: Rela on between the robot's posi on and the motors
speed ………………………………………………………………………………………………... 30

Figure 20: Obstacle detec on technique …………………………………………… 31

Figure 21: Sensor circuit ……………………………………………………………………. 32

Figure 22: Used NOT gates (74LS04) ……………………………………………….…. 33

Figure 23: Connec ng the sensor circuit to the microcontroller using a


relay ……………………………………………………………………………………………….…. 34

Figure 24A-24B: Obstacle avoider PCB design ……………………….…………… 35

Figure 25: Overall design of the robot ……………………………………………….. 37


Chapter one

Introduction:
The increase of traffic collisions every year around the world has led the
world's largest car manufactures to start developing more intelligent cars. In order to
develop such car new security systems has to be implemented within the car to
automatically correct the driver's fault controls if his/her controls will lead the car to
exit its course or even to avoid possible collision when there is an obstacle is
detected in the car's course.

If every vehicle on the road follows these security systems even in a multi-lane
freeway then the collision possibility will be almost zero percent. And hence
tomorrow's vehicle will be automatically driven with no need for a driver, this will
lead us to develop a line following robot that applies these simple but yet reliable
security systems.

The line follower robot is a self-operated robot that detects and follow the line, the
line of the course that the robot follows is black with white background or vice versa.
The control system senses the line beneath the robot and maneuvers it to stay on
course using feedback system which is simple but yet effective closed loop system.

Such robot also enjoys the ability of detecting any object on its path. If the robot
detects any object within its given course it instantly stalls the whole vehicle and
never continues its course until it is confirmed to the microcontroller that the object
is no longer in the robot's course.

Practical applications of the line follower robot: Lane keeping assistant of cars
running on the road (lane departure warning system), guidance systems for
industrial robots.

1
1.1 Project purpose

In this project the simulation for the lane keeping assistant and the
collision avoider requires to build line following robot that can also avoid
obstacle if present on course as a prototype for tomorrow's intelligent car
systems.

The main purpose of this robot is to follow a line marked on the ground using
infrared sensors. The basic design includes four infrared cells; each cell
consists of infrared emitter and an infrared receiver lying just above the floor.
The analog values of the infrared cells are then read and sent to a
comparator to have a binary value to detect if the robot lie above the line or
not. Depending on the condition of the sensors readings, the microcontroller
takes corrective action on the motors, to keep the robot on the line which
represents the lane in the actual real conditions.

The behavior of the robot largely depends on the algorithm of taking a


corrective action when it gets deflected away from the line and restore its
position on the line if it accidently exits the line, so to be able to implement
this algorithm a simple approach is to switch ON/OFF the motors depending
on which side of the line is applied to the robot. However, this causes the
machine to sway from side to side all the time. Using PWM (Pulse Width
Modulation) to control the individual speed of motors makes the line
following smoother. An even better approach is to implement a Proportional-
Derivative control to further damp the oscillatory behavior. Here, the error is
the offset of the robot from the line read by the infrared sensors and
controlling action takes place by applying PWM of the individual motors.

1.2 Required knowledge:


In order to be able to understand and implement such kind of robot C
Programming knowledge is required for the programming of the Atmel (AT89S52)
microcontroller used in implementing of this robot also Digital system design is an
essential to help in designing and implementing the circuits that controls this robot.
PCB skills (Printed circuit board) may be also required so that the designed circuit
can be manufactured in a way to make it possible to have a well fitted and reliable
circuit perfectly connected to the robot, and of course Electric circuits skills in order
to know how to deal with all of the robot's components and put all phases together.

2
1.3 Outline

Chapter two discusses the main concepts that contribute in the line
tracking/obstacle avoiding robot.
Chapter three will be discussing the robot's line tracking algorithm that was
used in the implementation of the robot that allows the robot to maneuver
over the line.
Chapter four will discuss the implementations of the microcontroller circuit
of the robot.
Chapter five will discuss the source code that controls the microcontroller to
apply the line tracking algorithm that was previously discussed in chapter
two.
Chapter six will discuss the obstacle avoider algorithm and the circuit used to
implement this algorithm.
Chapter seven will basically be about conclusion of this project and possible
future advances.

3
Chapter Two
Project basics
This chapter will basically be all about discussing the concepts that the
project is based on, also to discuss the prototype of the robot that should be
implemented, finally the architecture of the desired robot should be stated with a
briefly discussion of the components that will be used to serve the robot's operation.

2.1 Line following robot


The line following robot is a prototype of a smart vehicle that can differs from
the colors beneath it and take the appropriate decision during its journey according
to its position. It also have the ability to sense obstacles if found in a certain range
and stops completely before it to allow the robot to engage other actions.

To make use of the ability of the robot's capability of differing colors beneath it the
line following robot can be implemented, that robot can keep tracking a black line on
a white background which in real life situations represents the lane and its white
marks

2.2 Structure of the robot


The robot is a three wheeled vehicle, The two back wheels each is attached
to a six volts motor (Right motor and Left motor), and a free wheel is mounted in the
front middle of the vehicle.

The two rear motors are clearly responsible for the robot's steering over the line. For
example if the robot faces a right turn then the right motor slows down and the left
one stays on a certain speed but have to be faster than the right motor, and contrary
if a left turn is faced then the left motor slows down and the right one keeps on a
certain higher speed.

The robot also has an infrared emitter and a receiver that is mounted in front of the
robot, the emitter keeps on sending infrared rays waiting for these rays to be
reflected back to its receiver, and once these rays are detected the robot stops
immediately.

4
2.3 Required components
Since that colored surfaces absorbs the light falling on it, while white surfaces
(uncolored) reflects the light rays, so based on this old physics rules the sensors for
the line following robot should be implemented. Each sensor cell should contain
infrared emitter and receiver, and once the infrared receiver detects the reflected
infra from the sender it feeds a microcontroller connected to it with logic 1 (5 volts)
via a comparator acknowledging the microcontroller with current position of the
robot.

Once the microcontroller becomes aware of the robot's position it can now start
making decisions on how to control the motor's speed by a motor driver.

The motor driver used is a dual channel motor driver that can control the speed of
two motors simultaneously.

On other hand if the robot faces any obstacle during its course it should be detected
also with infrared sensors that also feeds another comparator, but instead of feeding
the microcontroller the comparator feeds a relay that switch of the microcontroller,
and switch it back on when obstacle is no longer in range of the robot.

So the components that should be used for both the line


following and the obstacle avoiding features:

 Microcontroller (AT89S52 or AT89C52)


 A comparator (LM324, LM358)
 Motor driver (L293D)
 Infrared LEDs
 6 volt motors
 5 volts voltage regulator (LM7805)
 5 volts relay (5 pins)

5
Chapter Three
Line tracking algorithm
This chapter will discuss the concept that has been used for the
implementation of the line tracking robot. First section will be discussing the number
of cells in the sensors line. Secondly the distance between each cell that can
extremely affect the robot navigation as the spacing between the cells is one of the
factors for the robot to predict its position over the line. Third section will be
discussing the idea of building the infrared sensor cells. The fourth section will be
basically about the control algorithm for the motors to allow the robot to maneuver
and steer over the line.

3.1 Number of cells in the sensors line


The sensor line used in the robot consists of four cells; each cell consists of an
IR emitter and an IR receiver. The sensor line helps in gathering the information
about the line beneath the robot to provide the microcontroller about the robot's
position and help it to navigate across the line and trace it. The line sensor cells act
as the robot's eyes of course the more the better; the sensors help to provide the
maximum number of information about line beneath the robot.

6
Figure 1

3.1.1 Sensors precision


It is obvious that the sensor line precision and quality is affected by the
number of cells used. For example if only two cell were used the robot will only be
able to define whether the line is on the left or the right so it is clear that this is a
very poor source of information for the robot to know its exact position over the
line, Instead of moving smoothly over the line, the robot will be brutally keep turning
to the right and to the left, hence to make the robot maneuver smoothly over the
line there have to be an increase to the number of the cells.

Four cells sensor line will provide the controller with acceptable amount of
information about the line beneath the robot and give it the opportunity to take
actions to correct the robot's position as much as possible, to result in smooth line
tracking system.

7
3.2 Distance between cells
One of the issues that affect the sensors line is the cells spacing. The closer
cells spaced from each other, the more will be the resolution of the sensors line.

Actually the distance between cells can really affect the robot actions as robot can
perform fault maneuvers over the line if they are not closely distanced from each
other. Following examples will show how distance between cells is a really important
factor that should be taken in to consideration in cells spacing. As it was mentioned
before the robot used consists of four cells numbered from one to four from the left
to the right.

3.2.1 When robot is centered

First situation if the robot is centered over the line then cells two and three
will detect the line, indicating that the robot is perfectly centered over the line. In
this situation spacing is not very critical just as shown in figure two.

Figure 2

3.2.2 Largely spaced cells with deviation

If the robot cells are greatly spaced from each other and got slightly gets
deviated away from the line by an angle of 10 degrees, only cell number four will
detect the line, which is the only source of information for the microcontroller that
the robot is 10 degrees deviated. So the largely spaced cells will not no ce except
large errors, which will be more difficult to correct. This situation is shown clearly in
figure three.

8
Figure 3

3.2.3 Closely spaced cells with deviation

If the sensors line cells are closely placed, this will increase the resolution of the
robot, so if the robot is also deviated by the same 10 degrees just as the previous
situation but with much more closely located cells, the sensors three and four will
notice the line beneath them so the microcontroller can be fed with more
information about the line's position beneath the robot just as the situation shown
in figure four.

Figure 4

9
3.3 Results

In general for this differential steering robot it is important to keep the sensor line as
far away as possible from the center of the steering which is the back of the robot
because this will help to amplify the detected error so the microcontroller can notice
it. Also support the sensors line with sufficient amount of cells to have a reliable
source of information to the microcontroller, and of course it is important to place
the sensor cells as close from each other as possible to gain more resolution for the
robot, in order to feed the microcontroller with right information about the line as
possible.

10
3.4 Building the cells
Cells that are used in this robot are infrared cells, each is basically composed
of IR senders and IR receivers.

The robot consists of 4 cells each cell consists of an emi er and a receiver. The
sender IR diode always transmits Infra (Light), and based on the old physics rules
that state that a colored surface (Black Line) will absorb the light of different colors,
and hence light is reflected over uncolored surfaces. For detecting the reflected IR
light, we are going to use a very original technique: we are going to use another IR-
LED.

This is an electrical property of Light Emitting Diodes (LEDs) which is the fact that a
LED Produce a voltage difference across its leads when it is subjected to light. As if it
was a photo-cell, but with much lower output current. The voltage generated cannot
be used generate electrical power and also it can be barley be detected so that’s why
an operational amplifier will be used to accurately detect very small voltage changes,
and this mechanism is also used for the obstacle avoiding feature of the robot that
will be discussed in details in chapter six.

Figure 5

11
3.4.1 Cell implementation

So based on what was mentioned before about the cell structure, One cell
should be implemented by the use of one sender IR LED and another IR LED as a
receiver to have it connected to a comparator to detect any slight change of voltage
across the LED as an indication for light being reflected ( sensor is over white ),
otherwise nothing is detected, indication for the sensor is over the black line.

Such design means that if sensor detects the black line then logic zero will be fed to
the microcontroller sent from the operational amplifier,

And if the sensor detects the white background then light will be reflected, hence
logic one will be fed to the microcontroller sent from the Op-amp.

So if the sensors are perfectly centered on the black line with the white background
then the microcontroller ports receive as follows in figure 6.

Figure 6

And if the robot is deviated to the right then the microcontroller will receive as
follows in figure 7.

Figure 7

And just as before if the robot is deviated to the left then only the most right sensor
will detect the logic Zero (black line).

19
3.4.2 Circuit implementa on of the sensors
As was mentioned before the designs will two IR LEDs (Senders and
Receivers) and a comparator and a potentiometer to adjust the sensor's
sensitivity. As shown in figure 9 (T1,T2,T3,T4) are the IR transmi ers while
(R1,R2,R3,R4) are the IR receivers that is connected to an op-amp to
maximize any detected voltage to +5 volts to be fed to the microcontroller

Figure 9

13
Chapter four
Implementation of the robot with the microcontroller
4.1 Introduc on
In order to get benefit of the sensors that was designed and implemented in
the previous chapter, circuit with a microcontroller has to be implemented so it can
analyze the information provided to it from the sensors line, and make the decision
on how to maneuver the robot over the line. So this requires the circuit be also in
control of the motors connected to it via a dual channel motor driver in order to
make use of its enables of each channel on each motor (right motor and left motor)
to control the speed of the motors by the PWM waveform.

4.2 The 8051 Microcontroller:


The AT89S52 has low-power consumption, high-performance CMOS 8-bit
microcontroller with 8K bytes of in-system programmable Flash memory. The device
is manufactured using Atmel’s high-density nonvolatile memory technology.

The on-chip Flash allows the program memory to be reprogrammed in-system or by


a conventional nonvolatile memory programmer.

The Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible


and cost-effective solution to many embedded control applications.

h p://www.atmel.com/dyn/products/product_card_mcu.asp?part_id=1918

Since the AT89S52 supports the In System Programming (ISP) this will give the ability
to reprogram the microcontroller without removing it from the circuit which is a very
useful feature for designing and upgrading the programs uploaded to the
microcontroller.

14
Figure 10

4.3 Program the Microcontroller with the ISP


Since the at89s52 has the ISP ability, a parallel ISP programmer is
implemented to be able to program or update the program uploaded on the
microcontroller on the circuit without the need to remove it from the system.

15
Figure 11

4.3.1 Architecture of the In System Programmer


To start using the parallel in system programmer the target device (in this
case it is the at89s52) is connected from four main pins (MISO, MOSI, RESET and CLK)
to four and gates connected to the parallel port that is attached to the computer.
Connec ng both 2 inputs of the AND gates as shown makes it act like a buffer, to
protect the parallel port.

16
Figure 12A

Figure 12B

17
4.3.2 Programming the microcontroller
To program the microcontroller any ISP programmer software can be used to
upload the HEX files to the microcontroller.

The ISP programmer (any version)

Figure 13

18
4.4 Line following robot circuit
The circuit's main job is to analyze what the sensors line reads and control
the motors to make the robot stay on the line and keep correcting any errors that
may occur during the robot's course.

4.4.1 Design and implementa ons


The robot was built using the AT89S52 microcontroller, L293D (Motor Driver),
LM324 (Comparator), IR Sensors, and a plas c chassis or any other material can be
used but the lighter the be er, Two 6 volts DC motors, One free wheel, the Infrared
sensors under the robot detects the black line. According to which of the cells
detects the black line the position of the robot on the track can be predicted, hence
the robot navigation can be controlled according to the information delivered to the
microcontroller.

When the sensors detect a black line the output of the comparator (LM324) will be
low (0 Volt), while for white surface the output will be high (5 Volts).

The output of the comparator is then sent to the microcontroller as an input to


accurately control the steering of the robot. The output of the microcontroller is
used to control the motors via the motor driver (L293D).

4.4.2 Operation of the robot


Capture the position on the line by the use of the infrared sensors, then steer
the robot on the track to keep it accurately on course, during the robot is navigating
if it faces an obstacle with the range of 30 cm, the robot completely stops and
activates its horn and front lights.

19
4.4.3 Overview

Figure 14

20
4.4.4 Controlling motors using a motor driver

Figure 15

28
4.4.5 The Full schema c of the circuit (Figure 16)

22
4.4.6 PCB design of the circuit

PCB design for such schematic is required to have the ability to mount the infra
sensors beneath the robot, in addition to fabricate much reliable circuit and suitable
sized one. (Figure 17A & Figure 17B)

23
4.5 Func oning of the microcontroller

The 4 sensors cells are connected to port 0.

The L293D Motor driver has 4 inputs to control the motion of the motors, and two
enables one for each motor, which are used to turn motors on and off.

To control the speed of the motors a PWM waveform with variable duty cycle is
applied to the enable pins of the motor driver. Rapidly switching the voltage
between Vs and GND gives an effective voltage between Vs and GND whose value
depends on the duty cycle of PWM.

Figure 18

The L293D consists of two channels, each channel consists of two inputs and one
enable which if it was 0 then the channel will be disabled as if the motors are
connected to very high impedance.

But if the enable is fed by logic 1, then channel will be enabled and the motor
should move according to input1 and input 2 or input3 and input 4 for the second
channel.

There have to be difference between the inputs of the channel in order to move the
motors across the the outputs of the channel, for example if the input1 is fed 1 and
input2 is fed 0 the motors moves right and if input 1 is 0 and input 2 is 1 then the
motor moves left otherwise motors stay still.

24
Chapter five
C code for the microcontroller
The code used was written in C language. The code implementation allows
the 8051 microcontroller to read the sensor values and define the robot's posi on
over the line and control the motors speed by the PWM algorithm that is fed to the
motor driver enables to make it maneuver over the line to help it track the line and
keep on correcting the robot's errors along the course.

5.1 The C code


#include <REGX52.h>

#include <math.h>

unsigned char pwm_r,pwm_l,pwm,max_pwm,pwm_r_,pwm_l_,counter;

unsigned char l1,l2,l3,l4;

float line,old_line,speed_amp,line_to_pwm_factor,max_speed;

delay(unsigned int X){

unsigned int i;

for(i=0;i<X;i++){;}

fwd(){

P3_0 = 0 ;

P3_2 = 1 ;

P3_4 = 0 ;

P3_5 = 1 ;

stop(){

P3_0 = 1 ;

P3_2 = 1 ;

25
P3_4 = 1 ;

P3_5 = 1 ;

pivot_right(){

P3_0 = 0 ;

P3_2 = 1 ;

P3_4 = 1 ;

P3_5 = 0 ;

pivot_left(){

P3_0 = 1 ;

P3_2 = 0 ;

P3_4 = 0 ;

P3_5 = 1 ;

setup_timers(){

EA = 1;

TMOD = 0X22;

ET0 = 1; //Enable the Timer/counter 0 interrupt

TR0 = 1; //Enable Timer/counter 0 to count

ET1 = 1; //Enable the Timer/counter 1 interrupt

TR1 = 1; //Enable Timer/counter 1 to count

TH0 = 150; //pwm generator

TH1 = 0;

26
pwm_gen() interrupt 1{

pwm++;

if (pwm > max_pwm){

pwm = 0;

if (pwm <= pwm_r){

P3_3 = 1; //ON cycle

}else{

P3_3 = 0; //OFF cycle

if (pwm <= pwm_l){

P3_1 = 1; //ON cycle

}else{

P3_1 = 0; //OFF cycle

void main(){

max_pwm = 50; // Trial and error, it is relativly slow speed to not have problem
with robot's inertia

pwm_r = 20;

pwm_l = 20;

max_speed = 14;

setup_timers();

while(1){

l1 =~ P0_0;

27
l2 =~ P0_1;

l3 =~ P0_2;

l4 =~ P0_3;

if ((l1+l2+l3+l4) != 0) //one of the sensors if seeing the line

{ old_line = line; // To remember last time line was in range

line_to_pwm_factor = (max_speed) / 2.5;

line = (l1*1) + (l2*2) +(l3*3)+(l4*4);

line = line / (l1+l2+l3+l4);

fwd();

pwm_l_ = floor((line*line_to_pwm_factor+0.5));//Returns the largest integral


value

pwm_r_ = floor(((9-line)*line_to_pwm_factor+0.5));

if (pwm_l_ > (max_speed)){ //limit the motor's speed with the "max speed"

pwm_l_ = (max_speed);

if (pwm_r_ > (max_speed)){

pwm_r_ = (max_speed);

pwm_l = pwm_l_+2;

pwm_r = pwm_r_;

if (old_line == line){

if (counter < 255){

counter++; }

}else

28
counter = 0;

if (counter > 20)

if (max_speed < 35){

max_speed++;

else

if (max_speed > 20){

max_speed--;

}else{

pwm_r = 30;

pwm_l = 30;

if (old_line > 2.5){

pivot_right();

}else{

pivot_left();

}} }}

29
Figure 19

5.2 Genera ng PWM to control motors speed

This figure shows a relation between speed of each motor and the position over the
line according to the sensor line readings which is numbered from 1 to 4 from le to
the right. Therefore the line is considered to be at the center of the robot when it
reads 2.5, which is the average of sensors 2 and 3 when they can detect the line.

30
Chapter six
Obstacle detection using Infrared LEDs
It is the same principle in all Infra-Red sensors used for the line tracking as
before. The basic idea is to send infra-red light through IR-LEDs, which is then
reflected by any object in front of the sensor in range about 20-30 cm.

Such small range is not a big issue as the robot is only used for modeling, but of
course much greater range should be implemented for real life situations.

Figure 20

31
6.1 Circuit implementa on

The sensor should be always ON, meaning that the IR led is constantly emitting Infra
in case the robot is faced by an obstacle during it course.

Figure 21

6.1.1 Noise effects

Due to the presence of indoor ambient light that affects the robot, the output of the
comparator (Red LED that presents the "OUT") will be always high, which means
there will be always +5 Volts at the output. Contrary if the ambient light decreases
(Obstacle in range) then the output of the comparator will be low (Zero Volt).

According to these outputs of the comparator, then it is clear that it is required to


gain the exact different outputs, as it is required to have a +5 volts output when an
obstacle in range and stay Zero if no obstacle is in range.

To be able to gain the required output a NOT gate has to be used to invert the
outputs, hence when obstacle is detected by the robot the output of the comparator
will be zero volt (red LED will be off), but the output of the NOT gate will be +5 volts.

Using more than one NOT gate will allow the robot to do more than one action when
it faces an obstacle.

32
IC 74LS04 will be used for inver ng the output. This device contains six independent
gates each of which performs the logic INVERT function.

Figure 22

IC 74LS04 contains alone six NOT gates, but only three gates will be used, one for the
beamer, and the second for a buzzer, and the third for a relay.

6.1.2 Stopping the robot when obstacle in range

The 5 volt relay is the circle of connec on between the obstacle avoider
circuit and the microcontroller of the line follower robot. The relay is used as a
switch that when it is normally closed it connects the +5 volts generated from the
voltage regulator of the microcontroller circuit with the pin 40 of the microcontroller
(Vcc of the microcontroller). Hence when the relay coil is triggered with 5 volts from
the NOT gate then the normally closed switch of the relay gets opened switching the
relay to normally opened to cut off the 5 volts from the microcontroller's Vcc (pin
40) or in other words "Killing the robot", and once the obstacle is out of range for
the robot the relay is switched back to normally closed providing the microcontroller
again with its essential +5 volts allowing the robot to con nue its course.

33
Figure 23

34
6.2 PCB design for the obstacle avoider

The obstacle avoider circuit was also built in PCB to be well fitted in the robot's front
and have the sensor in face of the obstacle.

Figure 24A

Figure 24B

35
Chapter seven
Conclusion
This line following robot can be used in automated driving systems. It will
allow the vehicle to stay in its lane during its whole course to overcome the input
errors of the driver; this security system will allow the vehicle correct its course if the
driver leaves his lane unintentionally. This security system will also allow the vehicle
be aware of any obstacle found in front of the vehicle by a certain range so it can
stop within the safe distance with the obstacle, it can also perform any other action
such as engaging horn or point a beamer over the obstacle or even change its lane
with a free one (no obstacles in the other lane).

Automotive technology matures, more and more functions of the underlying engine,
gearbox and even the steering wheel are no longer directly controlled by the driver
by mechanical means, but rather via a computer, which receives instructions from
the driver as inputs and delivers the desired effect by means of electronic throttle
control, so it is expected soon to be enjoying a smooth journey in a completely
driverless car that can make its own decisions for any expected or unexpected
situation.

7.1 Possible improvements


 Use Ultrasonic techniques instead of infrared for obstacle avoiding.
 More powerful motors.
 Use single power source instead of several batteries.
 Use low dropout voltage regulator.
 Use lighter chassis.
 Use sharper infrared sensors.
 Apply the project in real car for real life situations.

36
The overall design of the robot

Figure 25

37
References

[1] http://www.kmitl.ac.th/~kswichit/LFrobot/LFrobot.htm

[2] h p://www.sea lerobo cs.org/encoder/200005/jeffspencer.html

[3] h p://www.sea lerobo cs.org/encoder/200104/benny.html

[4] h p://www.sea lerobo cs.org/encoder/200002/karllunt.html

[5] h p://tech.groups.yahoo.com/group/booksbybibin/files/8051_Tutorial.pdf

[6] h p://www.wa4dsy.net/robot/linefollower

[7] h p://www.ermicro.com/blog/?p=1097

[8] h p://www.scribd.com/doc/4662053/Line-Following-Robot

[9] h p://www.botskool.com/tutorials/electronics/8051/line-follower

[10]
h p://ieee.rutgers.edu/robo cs/index.php?op on=com_content&view=ar cle&id=51:line-
following-kit-tutorial-line-sensor-board&ca d=34:line-following-robot-
competition&Itemid=54

[11]
h p://online.physics.uiuc.edu/courses/phys405/P405_Projects/Fall2005/Robot_project_jas
eung_.pdf

[12] http://chaokhun.kmitl.ac.th/~kswichit/ROBOT/Follower.pdf

38

Vous aimerez peut-être aussi