28
I have declared “Line Follower Robot Using PID Controller” is the result of my own research except as cited in the references. This thesis has not been accepted for any degree and is not concurrently submitted in candidature of any other degree Signature: __________________________________ Name: AHMAD NOR KASRUDDIN B NASIR Date: 13 NOVEMBER 2008

Document26

Embed Size (px)

Citation preview

Page 1: Document26

I have declared “Line Follower Robot Using PID Controller” is the result of my own research except as cited in the references. This thesis has not been accepted for any

degree and is not concurrently submitted in candidature of any other degree

Signature: __________________________________ Name: AHMAD NOR KASRUDDIN B NASIR Date: 13 NOVEMBER 2008

Page 2: Document26

 

 

 

LINE FOLLOWER ROBOT USING PID CONTROLLER.

ABD AZRIN FIRDAUS A RAHIM

This thesis is submitted as partial fulfillment of the requirement for the

award of the Bachelor Degree of Electrical Engineering (Electronic)

Faculty of Electrical & Electronic Engineering

University Malaysia Pahang

NOVEMBER 2008

Page 3: Document26

ii  

DECLARATION

“All the trademark and copyrights use here in are property of their respective owner.

References of information from other sources are quoted accordingly, otherwise the

information presented in this report is solely work of the author”.

Signature : ____________________________

Author : ABD AZRIN FIRDAUS A RAHIM.

Date : 13 NOVEMBER 2008.

Page 4: Document26

iii  

DEDICATION

Specially dedicate to

My beloved parents, brothers and sisters.

Page 5: Document26

iv  

ACKNOWLEDGEMENT

First, I would like to express my acknowledgment and gratitude to my

supervisor, Encik Ahmad Nor Kasruddin B Nasir for the guidance and co-operation that

been given throughout the progress and to complete this project.

I also deeply thank to my family whose have giving me chance to continue my

study at Universiti Malaysia Pahang and support me for all these year. Thanks for their

encouragement, support, love, my little brother, sister and many more.

ALHAMDULILLAH.

Finally, my great appreciation to my house mate that giving me so many opinion

till I don’t know which one to comprehend, thanks for their brilliant idea and my class

mate whom involve directly or indirectly with this project. Thank You very Much.

 

Page 6: Document26

v  

ABSTRACT

Robot becomes widely used in industrial due to their characteristics. Robot

able to work in 24 hours continuously without feeling tired unlike human that

confine to certain time. The cost to setup the robot nowadays becomes more

affordable and their long term prospect is bright judging from their capacity to

perform. But in reality, there is no robot able to function perfectly and still making

error. A better controller needed here, to allow the robot performs efficiently and

make less error. This project try to implement a PID controller on mobile robot to see

whether the robot perform efficiently. This mobile robot has a line tracking module,

where it will follow the track that made from black tape. This is area where the PID

implemented, the robot will be able to follow the black tape effectively and moving

along the track smoothly.

Page 7: Document26

vi  

ABSTRAK

Robot semakin digunakan secara meluas dalam industri kerana ciri-ciri robot

yang baik untuk keadaan di dalam kilang. Robot boleh melakukan kerja 24 jam

secara berterusan tanpa henti di mana robot tidak pernah merasa letih tidak seperti

manusia yang mempunyai had masa akibat keletihan. Kos untuk memasang robot

menjadi semakin murah dan prospek masa panjang yang baik di mana robot dapat

melakukan kerja dengan baik dan memuaskan. Tetapi secara realitinya, robot tidak

semestinya dapat menjalankan kerja dengan sempurna dan besar kemungkinan

melakukan ralat. Di sini suatu sistem di perkenalkan iaitu sistem kawalan yang dapat

membantu robot melakukan kerja dengan lancer dan kurang melakukan ralat. Projek

ini cuba mengaplikasikan pengunaan kawalan PID ke atas robot untuk menentukan

samaada robot dapat berfungsi dengan baik atau tidak. Robot ini menpunyai modul

mengikut garis, dimana garis diperbuat daripada pita hitam itu dianggap sebagai

landasan untuk diikuti oleh robot. Inilah kawasan dimana pengaplikasian kawalan

PID ke atas modul ini dan dapat dilihat samaada robot dapat mengikuti landasan

tanpa terkeluar di samping dapat mengikutinya dengan lancer.

Page 8: Document26

vii  

TABLE OF CONTENTS

CHAPTER ELEMENTS PAGE

DECLARATION ii

DEDICATION iii

ACKNOWLEDGEMENT iv

ABSTRACT v

ABSTRAK vi

TABLE OF CONTENTS vii

LIST OF TABLES x

LIST OF FIGURES xi

LIST OF ABREVIATIONS xiii

LIST OF APPENDICES xiv

CHAPTER 1 INTRODUCTION

1.1 Overview 1

1.2 Objective 1

1.3 Scope of Project 2

1.4 Problems Statement 2

1.5 Thesis Organization 2

CHAPTER 2 LITERATURE REVIEW

2.1 Introduction 4

Page 9: Document26

viii  

2.2 Electric Motor 5

2.2.1 DC Motor 6

2.2.2 AC Motor 6

2.2.3 Stepper Motor 7

2.2.4 Servo Motor 8

2.2.5 Brushless Servomotor 10

CHAPTER 3 HARDWARE AND SOFTWARE DEVELOPMENT

3.1 Introduction 13

3.2 Basic Design and Requirement 13

3.3 Basic Operation 14

3.4 Input System 14

3.4.1 IR Sensors 15

3.4.2 Comparator 16

3.4.3 LM 324 16

3.4.4 Arrangement of Sensors 18

3.5 Processing System 20

3.5.1 Voltage Regulator 23

3.5.2 IC 7805 23

3.5.3 Oscillator 24

3.6 Output System 25

3.6.1 Use of Driver 25

Page 10: Document26

ix  

3.6.2 IC L293D 26

3.7 Circuit Integration 27

3.8 Pulse Width Modulation (PWM) 28

3.8.1 Use of PWM 29

3.9 PID for Line Following Robot 30

3.9.1 Behavior Following Line 30

3.9.2 PID Hardware Configuration 32

3.9.3 PID Formula 32

3.9.4 PID Implementation 33

3.10 Software Configuration 37

3.10.1 PIC kit 2 Programmer 37

3.10.2 Proteus 7 Simulator 39

3.10.3 Programming 16F877A 40

3.11 Summarization 41

CHAPTER 4 RESULT AND DISCUSSION

4.1 Introduction 42

4.2 Simulation of motor Speed 42

4.2.1 Robot without PID 43

4.2.2 Robot with PID 46

4.3 Costing 50

4.4 Commercialization 50

Page 11: Document26

x  

CHAPTER 5 CONCLUSION AND RECOMMENDATION

5.1 Conclusion 51

5.2 Future Recommendation 51

REFERENCES 53

APPENDIX A 54

APPENDIX B 57

APPENDIX C 58

APPENDIX D 62

APPENDIX E 68

Page 12: Document26

xi  

LIST OF FIGURES

FIGURE NO. TITLE PAGE 2.1 Typical PM servomotors 9

2.2 Permanent magnet 10

2.3 Trapezoidal input voltage and square wave current 11

waveforms

2.4 Three winding waveform 12

3.1 Block diagram of line follower robot using PID controller 14

3.2 IR sensor and surfaces 15

3.3 voltage divider 15

3.4 Comparator schematic 16

3.5 LM324 schematic 18

3.6 Top and side view of sensors 19

3.7 sensors position 19

3.8 IR sensors circuit schematic 20

3.9 PIC 16F877A pins 22

3.10 Voltage Regulator circuits 24

3.11 Oscillator Schematic 24

3.12 PIC basic circuit 25

3.13 L293D schematic 26

3.14 Motor connection 27

3.15 Circuit connection 28

3.16 PWM graph 28

3.17 Circuit analogy 29

3.18 PWM system 29

Page 13: Document26

xii  

3.19 PIC kit 2 Programmer interface 38

3.20 Interface of Proteus 7 Professional Simulator 39

3.21 Programming flow 40

4.1 Sensors detection 43

4.2 Graph PWM 43

4.3 Right sensors 44

4.4 Right PWM 44

4.5 Left sensors 45

4.6 Left PWM 45

4.7 Right sensors 46

4.8 Right PWM 46

4.9 Greater right sensors 47

4.10 Greater right PWM 47

4.11 Left sensors 48

4.12 Left PWM 48

4.13 Greater left sensors 49

4.14 Greater left PWM 49

Page 14: Document26

xiii  

LIST OF ABBREVIATIONS

PWM - Pulse Width Modulation

Page 15: Document26

x  

LIST OF TABLE

TABLE NO. TITLE PAGE 3.1 Binary value and position robot 32

3.2 Binary and numerical values 33

3.3 Port and functions 40

4.1 Straight line 44

4.2 Right PWM 44

4.3 Left PWM 45

4.4 Right PWM 46

4.5 Greater right PWM 47

4.6 Left PWM 48

4.7 Greater left PWM 49

4.8 Cost of components 50

Page 16: Document26

xiv  

LIST OF APPENDICES

APPENDIX TITLE PAGE

A Source codes 54

B Pictures of robot 57

C Datasheets L293 D 58

D Datasheets PIC 16F877 A 62

E Datasheets LM324 D 68

Page 17: Document26

1  

 

CHAPTER 1

INTRODUCTION 1.1 Overview

Robot becomes widely used in industrial due to their characteristics. Robot able

to work in 24 hours continuously without feeling tired unlike human that confine to

certain time. The cost to setup the robot nowadays becomes more affordable and

their long term prospect is bright judging from their capacity to perform. But in

reality, there is no robot able to functions perfectly and still making error. A better

controller needed here, to allow the robot performs efficiently and make less error.

This project try to implement a PID controller on mobile robot to see whether the

robot perform efficiently. This mobile robot has a line tracking module, where it will

follow the track that made from black tape. This is area where the PID implemented,

the robot will be able to follow the black tape effectively and moving along the track

smoothly.

1.2 Objectives

The main objective of this project is to design a line follower robot with PID

controller and compare effect of PID.

Page 18: Document26

2  

 

1.3 Scope of projects This project is focused to design and build the prototype line follower robot and

implement PID controller. Therefore, this prototype will cover scope as followed:

i. Design line follower robot using PIC 16F877A.

ii. PID controller implementation through programming in PIC 16F877A by

using BASIC LANGUAGE.

iii. In the end of project, we compare a robot movement with PID and

without PID controller by inspecting the pattern of movement of the robot

while following the track.

1.4 Problem statements

Line follower robot can be easily designed by using concept on and off. But

this type of design will make robot not be able to follow the smoothly and sometimes

robot tends to move out of the track. So to overcome that problem, we need a better

controller to make robot follow the line smoothly and make less error. In this project,

we are using PID controller because of easy to understand and implement on mobile

robot.

1.5 Thesis organizations

This thesis consists of five chapters. This chapter discuss about overview of

project, objective research, project scope, problem statement and thesis organization.

Chapter 2 contains a detailed description of Line follower robot and PID

controller. It will explain about the concept of algorithm of line follower robot and

PID implementation on robot.

Page 19: Document26

3  

 

Chapter 3 includes the project methodology. It will explain how the project is

organized and the flow of process in completing this project. Also in this topic

discusses the methodology of the system, circuit design, software design and the

mechanical design.

Chapter 4 will be discussing about the result obtained in this project and a

discussion about the result.

Finally, the conclusions for this project are presented in chapter 5. This

chapter also discusses about the recommendation for the project and for the future

development.

Page 20: Document26

4  

 

CHAPTER 2

LITERATURE REVIEW 2.1 Introduction

The line follower robot using PID controller is a self operating that detect and

follows track drawn on floor. The track consists of the black tape on white surface.

The control system used to sense the line and maneuver the robot to stay on course

while constantly correcting the wrong moves using feedback mechanism, thus might

forming effective closed loop system. We have found two scope of system in

developing the robot and PID controller.

(i) The motion control of a two wheel vehicle is more complex than the

balance control. There are some reciprocal relations between the two

wheel vehicle velocity and the tilt angle that are difficult to modify. To

control the two wheel vehicle motion and reduce the NN complexity, a

NN-like PID control method was developed. The proposed control

scheme consists of a self-tuning PID decoupling controller and two self-

tuning PID controllers. As the two wheel vehicle motions are relative to

the tilt angle magnitude, it is necessary to make the tilt angle follow a

designed trajectory. The two wheel vehicle designed tilt angle depends on

the velocity response. In this paper, a self-tuning PID velocity controller

and a self-tuning PID tilt angle controller are presented. The self-tuning

PID controllers guarantee that the two wheel vehicle is stable, traces the

tilt angle command and follows the forward desired velocity. The TWV

rotation motion is dependent upon the velocity difference between the

Page 21: Document26

5  

 

two wheels. The self-tuning PID decoupling controller is an electrical

differential mechanism that distributes the wheel velocity and torque. The

decoupling controller appropriately assigns the current command to two

DC motors to drive the two wheel vehicle. The results of the experiment

demonstrate the feasibility and reliability of the proposed control scheme,

along with the stability issues [1]. Such a design allows the maneuver

robot on the track with the implementation of PID controller.

2.2 Electric motors

Another part that we will be approach is the use of motor. Firstly, we should

know the definition of an electric motor. An electric motor is a device that converts

electrical energy to mechanical energy [2]. For the reverse task, the device converts

mechanical energy to electrical energy. This is not related to electric motor but this

function always known as generator or dynamo. Frequently, an electric motor will

apply the electromagnetism concept. The fundamental principle upon which

electromagnetic motors are based is that there is a mechanical force on any current-

carrying wire contained within a magnetic field. The force is described by the

Lorentz force law and is perpendicular to both the wire and the magnetic field [2].

The motor will have two types. First is rotary motor and second one is linear motor.

However, must of magnetic motor, it will rotate. In a rotary motor, the rotary part is

called as rotor and the stationary part is called as stator. When the rotor rotate, the

torque will be developed based on the rotor’s axis. The motor contains

electromagnets that are wound on a frame. This frame is often called as armature.

Correctly, the armature is that part of the motor across which the input voltage is

supplied. Depending upon the design of the machine, either the rotor or the stator can

serve as the armature.

Page 22: Document26

6  

 

2.2.1 DC motor When the coil is powered, a magnetic field is generated around the armature.

First, the left side of the armature is pushed away from the left magnet and drawn

toward the right, causing rotation. Second, the armature continues to rotate.

Third, when the armature becomes horizontally aligned, the commutator

reverses the direction of current through the coil, reversing the magnetic field. The

process then repeats. If the shaft of a DC motor is turned by an external force, the

motor will act like a generator and produce an Electromotive force (EMF) [2].

During normal operation, the spinning of the motor produces a voltage, known as the

counter-EMF (CEMF) or back EMF, because it opposes the applied voltage on the

motor. This is the same EMF that is produced when the motor is used as a generator

(for example when an electrical load (resistance) is placed across the terminals of the

motor and the motor shaft is driven with an external torque). The CEMF is

proportional to motor speed, when an electric motor is first started or is completely

stalled, there is zero CEMF [2]. Therefore the current through the armature is much

higher. As the motor spins, the CEMF increases until it is equal to the applied

voltage, minus the parasitic voltage drop. Generally, the rotational speed of a DC

motor is proportional to the voltage applied to it, and the torque is proportional to the

current. Speed control can be achieved by variable battery tapping, variable supply

voltage, resistors or electronic controls. The direction of a wound field DC motor can

be changed by reversing either the field or armature connections but not both.

2.2.2 AC motor

A typical AC motor consists of two parts. First is an outside stationary stator

having coils supplied with AC current to produce a rotating magnetic field, and

second is an inside rotor attached to the output shaft that is given a torque by the

rotating field [2]. There are two fundamental types of AC motor, depending on the

type of rotor used. First is the synchronous motor, which rotates exactly at the supply

frequency or a sub multiple of the supply frequency. Second is the induction motor,

Page 23: Document26

7  

 

which turns slightly slower, and typically (though not necessarily always) takes the

form of the squirrel cage motor. Three-phase AC induction motor is commonly used

especially for high powered motor. The phase’s differences between the three phase

of electrical supply create a rotating electromagnetic field in the motor. In the rotor,

the current will be induced by the rotating magnetic field caused by electromagnetic

induction, which in turn sets up a counterbalancing magnetic field that causes the

rotor to turn in the direction the field is rotating.

The rotor must always rotate slower than the rotating magnetic field produced

by the polyphase electrical supply; otherwise, no counterbalancing field will be

produced in the rotor.

2.2.3 Stepper motor

Stepper motors are special motors that are used when motion and position

have to be precisely controlled [3]. The stepper motor is closely related in design to

three-phase AC synchronous motors where an internal rotor containing permanent

magnets or a large iron core [2] with salient poles is controlled by a set of external

magnets that are switched electronically. A stepper motor may also be thought of as a

cross between a DC electric motor and a solenoid. As each coil is energized in turn,

the rotor aligns itself with the magnetic field produced by the energized field

winding. Unlike a synchronous motor, in its application, the motor may not rotate

continuously; instead, it "steps" from one position to the next as field windings are

energized and de-energized in sequence. Depending on the sequence, the rotor may

turn forwards or backwards. Simple stepper motor drivers entirely energize or

entirely de-energize the field windings, leading the rotor to "cog" to a limited number

of positions; more sophisticated drivers can proportionally control the power to the

field windings, allowing the rotors to position "between" the "cog" points and

thereby rotate extremely smoothly. Computer controlled stepper motors are one of

the most versatile forms of positioning systems, particularly when part of a digital

servo-controlled system. Stepper motors can be rotated to a specific angle with ease,

and hence stepper motors are used in computer disk drives, where the high precision

Page 24: Document26

8  

 

they offer is necessary for the correct functioning of, for example, a hard disk drive

or CD drive. Only very old hard drives (from the pre-gigabyte era) use stepper

motors; newer drives use systems based on voice coils. Stepper motors were

upscaled to be used in electric vehicles under the term SRM (switched reluctance

machine). The stepper motor is turned one step at a time or can turn at a specific rate

[4] (specified by the speed in which the steps are executed). In term of hardware

interface, the stepper motor requires a bit more complex to wire and more current.

But this motor has more advantages in software control. A stepper motor can be

controlled by stepper-motor controlled chips, such as the UC1517.

2.2.4 Servo motor Servomotors are available as AC or DC motors. Early servomotors were

generally DC motors because the only type of control for large currents was through

SCRs for many years. As transistors became capable of controlling larger currents

and switching the large currents at higher frequencies, the AC servomotor became

used more often. Early servomotors were specifically designed for servo amplifiers.

Today a class of motors is designed for applications that may use a servo amplifier or

a variable-frequency controller, which means that a motor may be used in a servo

system in one application, and used in a variable-frequency drive in another

application. Some companies also call any closed-loop system that does not use a

stepper motor a servo system, so it is possible for a simple AC induction motor that

is connected to a velocity controller to be called a servomotor.

Some changes that must be made to any motor that is designed as a

servomotor includes the ability to operate at a range of speeds without overheating,

the ability to operate at zero speed and retain sufficient torque to hold a load in

position, and the ability to operate at very low speeds for long periods of time

without overheating. Older-type motors have cooling fans that are connected directly

to the motor shaft. When the motor runs at slow speed, the fan does not move enough

air to cool the motor. Newer motors have a separate fan mounted so it will provide

optimum cooling air. This fan is powered by a constant voltage source so that it will

Page 25: Document26

9  

 

turn at maximum RPM at all times regardless of the speed of the servomotor. One of

the most usable types of motors in servo systems is the permanent magnet (PM) type

motor. The voltage for the field winding of the permanent magnet type motor can be

AC voltage or DC voltage. The permanent magnet-type motor is similar to other PM

type motors presented previously. Figure 2.1 shows a cutaway picture of a PM motor

and Fig. 2.2 shows a cutaway diagram of a PM motor. From the picture and diagram

you can see the housing, rotor and stator all look very similar to the previous type

PM motors. The major difference with this type of motor is that it may have gear

reduction to be able to move larger loads quickly from a stand still position. This

type of PM motor also has an encoder or resolver built into the motor housing. This

ensures that the device will accurately indicate the position or velocity of the motor

shaft.

Figure 2.1: Typical PM servomotors

Page 26: Document26

10  

 

2.2.5 Brushless servomotor

The brushless servomotor is designed to operate without brushes. This means

that the commutation that the brushes provided must now be provided electronically.

Electronic commutation is provided by switching transistors on and off at appropriate

times. Figure 2.3 shows three examples of the voltage and current waveforms that are

sent to the brushless servomotor. Figure 2.4 shows an example of the three windings

of the brushless servomotor. The main point about the brushless servomotor is that it

can be powered by either ac voltage or dc voltage.

Figure 2.3 shows three types of voltage waveforms that can be used to power the

brushless servomotor. Figure 2.3a shows a trapezoidal EMF (voltage) input and a

square wave current input. Figure 2.3b shows a sinusoidal waveform for the input

voltage and a square wave current waveform. Figure ll-85c shows a sinusoidal input

waveform and a sinusoidal current waveform. The sinusoidal input and sinusoidal

current waveform are the most popular voltage supplies for the brushless servomotor.

Figure 2.4 shows three sets of transistors that are similar to the transistors in the

output stage of the variable-frequency drive. In Fig. 2.4a the transistors are connected

Figure 2.2: permanent magnet

Page 27: Document26

11  

 

to the three windings of the motor in a similar manner as in the variable-frequency

drive. In Fig. 2.4b the diagram of the waveforms for the output of the transistors is

shown as three separate sinusoidal waves. The waveforms for the control circuit for

the base of each transistor are shown in Fig. 2.4c. Figure 2.4d shows the back EMF

for the drive waveforms.

Figure 2.3: Trapezoidal input voltage and square wave current waveforms. (b) Sinusoidal input voltage and sinusoidal voltage and square wave output voltage waveforms. (c) Sinusoidal input voltage and sinusoidal current waveforms. This has become the most popular type of brushless servomotor control.

Page 28: Document26

12  

 

Mobile robot have been developed and applied by many company and other

university. Otherwise, the past projects also make their project as their research and

development. This chapter is likely to approach about the technical and engineering

development of mobile robot. Therefore, the study of many issues about past project

is important. To develop this project, the knowledge about the processor and

controller are needed which they will be used for future. This project will use PIC

microprocessor as the processor. Besides that, the implementation should consider

the concept of the project. Past project always give new idea whether it can be used

as improvement or new development for future project.

Figure 2.4: (a) Transistors connected to the three windings of the brushless servomotor. (b) Waveforms of the three separate voltages that are used to power the three motor windings. (c) Waveforms of the signals used to control the transistor sequence that provides the waveforms for the previous diagram, (d) Waveform of the overall back EMF.