Fuzzy Logic Controller For Controlling DC Motor Speed Using Matlab Applications
Fuzzy Logic Controller For Controlling DC Motor Speed Using Matlab Applications
Fuzzy Logic Controller For Controlling DC Motor Speed Using Matlab Applications
NOVEMBER, 2008
i
DECLARATION
“I declare that this thesis entitled ‘Fuzzy Logic Controller for Controlling DC motor
speed using Matlab Application’ is the result of my own research except as cited in
references. The thesis has not been accepted for any degree and is not concurrently
submitted in candidature of any other degree”,
Signature :…………………………….
ii
DEDICATION
Sincerely,
iii
ACKNOWLEDGEMENT
Finally, I would like to thank to my family and all members for their support and
encouragement.
iv
ABSTRACT
v
ABSTRAK
vi
TABLE OF CONTENT
DECLARATION ii
DEDICATION iii
ACKNOWLEDGEMENT iv
ABSTRACT v
ABSTRAK vi
1 INTRODUCTION 1
1.1 Introduction
vii
1.4 Objectives 3
1.5 Scope 4
2 LITERITURE REVIEW 5
2.2 DC motor 7
3 METHADOLOGY 11
3.1.1.1 Preprocessing 12
3.1.1.2 Fuzzification 13
3.1.1.4 Defuzzification 14
3.1.1.5 Postprocessing 14
3.2.1 Introduction 27
3.2.2 Features 27
viii
3.2.3 Specification 28
3.2.6.1 C Compiler 37
3.3.2 Equation 60
3.3.4 Specification 63
4 RESULT 73
4.3 Rules 77
4.5 Discussion 79
5.1.1 Costing 81
5.1.2 Commercialization 82
5.2 Conclusion 83
5.3 Recommendation 83
REFERENCES 84
APPENDIX
D Equipment
Datasheet
i) IR2109
x
ii) IN4148
iii) IRF740
xi
LIST OF TABLE
1 Specification of DC motor 63
2 Rules 77
xii
LIST OF FIGURES
5 FIS Editor 18
6 Membership Editor 19
8 Rule Editor 23
9 Rule Viewer 26
10 DAQ card 28
12 Pin Assignment 31
15 Demos Version 42
xiii
16 Rtvdp model 43
17 External 44
18 Connect to target 44
20 Simulation Result 46
22 Simulink Library 48
23 Figure 23 49
24 New window 49
25 Figure 25 50
27 Board testing OK 52
35 Block Diagram 63
xiv
38 DC motor plant 66
39 Program in M-File 67
41 Preference Window 69
42 Model Explorer 71
47 Without controller 78
48 With controller 78
xv
LIST OF SYMBOL/ABBREVIATIONS
DC – Direct Current
MATLAB
xvi
CHAPTER 1
INTRODUCTION
1.1 Introduction
1.1.1 Fuzzy Logic Controller for Controlling DC Motor speed using MATLAB
applications.
1
efficiency and reliability, reduced noise, longer lifetime and elimination of ionizing
sparks from the commutator.
Fuzzy Logic Controller (FLC) is chosen as a controller for this project because it
consist several advantages compared to the other classical controller. The advantages of
FLC are such as simplicity of control, low cost and the possibility to design without
knowing the exact mathematical model of the process. It is suitable for applications
such as the speed control of DC motor which has nonlinerities.
The structure of FLC consists of the following 3 major components which the
first one is fuzzifier that used for measurement of the input or definition of the fuzzy
sets that will applied. The second one is fuzzy control or rule base which provides the
system with the necessary decision making logic based on the rule base that determine
the control policy. The third method is defuzzifier which combines the action that have
been decided and produce single non-fuzzy output that is the control signal of the
systems.
There are some problem occur while controlling the DC motor, The
problem occur such as losses and efficiency of the motor. To encounter the
problem, the controller is needed and for this project Fuzzy Logic Controller will
be used.
There are too many controllers nowadays but FLC is chosen to interface
with the DC motor because it suitable for application which has nonlinearities
2
such speed of the DC motor. Either than that, it has several advantages such as
low cost and simplicity of control
Problem encountered
Solutions
Objective
Objective of the project is to control the speed of DC motor with the Fuzzy
Logic Controller using MATLAB applications and to compare the result of the
simulation with the experiment.
3
1.4 Scope
4
CHAPTER 2
LITERITURE REVIEW
Data acquisition is the sampling of the real world to generate data that can be
manipulated by a computer. Data acquisition typically involves acquisitions of signals
and waveform and processing the signals to obtain desired information. The components
of data acquisition systems include appropriate sensors that convert any measurement
parameter to an electrical signal, which acquired by data acquisition hardware.[1]
Acquired data are displayed, analyzed and stored on a computer and control can
be developing using various general purposes programming language such as Pascal,
5
Basic C and etc. Specialized programming language used for data acquisitions include
EPICS used to build large scale data acquisition systems, LabView which offers a
graphical programming environment optimized for data acquisition and MATLAB
provides a programming language but also built-in-graphical tools and libraries for data
acquisition and analysis.[1]
Data Acquisition Toolbox provides a complete set of tools for analog input,
analog output, and digital I/O from a variety of PC-compatible data acquisition
hardware. The toolbox lets you configure your external hardware devices, read data into
MATLAB and Simulink for immediate analysis, and send out data. Figure 9 shows
connection between the DAQ toolbox, MATLAB and the hardware. [2]
1. Analog Input
6
-The analog input functions let to acquire signals from the hardware. The
analog input object, add channels to the object, acquire data to memory,
read data into the workspace, and preview the most recently acquired data
can be created by the programmer.[2]
2. Analog Output
-Analog output functions let to send signals out to the hardware. The
analog output object, add channels, queue data sets to be output, and
generate analog signals can be created by the programmer.[2]
Digital I/O
-Digital I/O functions enable to generate or read digital signals using the
hardware. The digital I/O objects, add lines, send data to the hardware,
and read data into the workspace can be created by the programmer.[2]
2.2 DC Motor
The electric motor uses an electrical energy to produce a mechanical energy. The
principles of electrical energy into mechanical energy by electromagnetic means was
demonstrated by the British scientist Michael Faraday and consisted of a free hanging
7
wire dipping into a pool of mercury. A permanent magnet was placed in the middle of
the pool of mercury. When a current passé through the wire, the wire rotated around the
magnet, showing that the current gave rise to a circular magnetic field around the
wire.[3]
There are two divisions of electric motors which is Direct Current (DC) and
Alternating Current (AC). The ongoing trend toward electronic control further muddles
the distinction, as modern drivers moved the commutator out of the motor shell. For this
new breed of motor, driver circuits are relied upon to generate sinusoidal AC drive
currents. The two best examples are: the brushless DC motor and the stepping motor
which both being polyphase AC motors requiring external electronic control.[3]
8
Figure 2: Comparison of motor types
9
Fuzzy Logic Controller (FLC) is based on fuzzy logic controller and constitutes a
way of converting linguistic control strategy into an automatic by generating a rule base
which controls the behavior of the system. Fuzzy control is control method based on
fuzzy logic. Fuzzy provides a remarkably simple way to draw definite conclusions from
vague ambiguous or imprecise information. It suitable for applications such as the speed
control of dc motor which is has non linearities. [5]
The applications of fuzzy logic are usually for household appliance such as
washing machine and rice cooker. Fuzzy also been used in industrial process such as
cement kilns, underground trains and robots. [5]
10
CHAPTER 3
METHODOLOGY
11
Figure 3: Structure of fuzzy logic controller
3.1.1.1 Preprocessing
The inputs are most often hard or crisp measurement from some measuring
equipment rather than linguistic. A preprocessor, the first block in Figure 1 shows the
conditions the measurements before enter the controller.[6]
3.1.1.2 Fuzzification
12
The first block inside the controller is fuzzification which converts each piece of
input data to degrees of membership by a lookup in one or several membership
functions. The fuzzification block matches the input data with the conditions of the rules
to determine. There is degree of membership for each linguistic term that applies to the
input variable.[6]
The collection of rules is called a rule base. The rules are in “If Then”
format and formally the If side is called the conditions and the Then side is called the
conclusion. The computer is able to execute the rules and compute a control signal
depending on the measured inputs error (e) and change in error.(dE). In a rule based
controller the control strategy is stored in a more or less natural language. A rule base
controller is easy to understand and easy to maintain for a non- specialist end user and an
equivalent controller could be implemented using conventional techniques.[6]
3.1.1.4 Defuzzification
13
Defuzzification is when all the actions that have been activated are
combined and converted into a single non-fuzzy output signal which is the control signal
of the system. The output levels are depending on the rules that the systems have and the
positions depending on the non-linearities existing to the systems. To achieve the result,
develop the control curve of the system representing the I/O relation of the systems and
based on the information; define the output degree of the membership function with the
aim to minimize the effect of the non-linearity.[6]
3.1.1.5 Postprocessing
The postprocessing block often contains an output gain that can be tuned
and also become as an integrator.[6]
There are five primary graphical user interface (GUI) tools for building,
editing and observing fuzzy inference systems in the toolbox:-
14
Membership Function editor
Rule Editor
Rule Viewer
Surface Viewer
These GUI are dynamically linked and if the changes make to the FIS to
the one of the toolbox, the effect can be seen in other GUIs. In addition to these five
primary GUIs, the toolbox includes the graphical ANFIS Editor GUI, which is used for
building and analyzing Sugeno-types adaptive neural fuzzy inference systems [7]
15
Figure 4: Fuzzy Inference System
16
3.1.2.1 FIS Editor
The FIS editor handles the high level issues of the system. Fuzzy Logic
toolbox does not limit The FIS editor displays general information about fuzzy inference
systems. There is a simple diagram at the top shows the name of each input variable on
the left and the output on the right. The step below is show how to open the FIS editor:-
[7]
i. To start the system from scratch, type fuzzy at the MATLAB prompt.
ii. Select Edit > Add Variable > Input (if the system need two inputs)
iii. Click the yellow box input1. This box is highlighted with a red outline
iv. Edit the Name field from input1 to service, and press Enter.
v. Click the yellow box input2. This box is highlighted with a red outline/
vi. Edit the Name field from input2 to food, and press Enter.
viii. Edit the Name field from output1 to tip, and press Enter.
17
x. Enter the Workspace variable name tipper, and click OK.
18
The membership function editor shares some features with the FIS editor.
The membership function editor is the tool that lets the programmer displays and edits
all of the membership functions associated with all inputs and output variables for entire
fuzzy inference system. [7]
The step below shows how to open the membership function editor:-
• Within the FIS editor, double click the blue icon called tip
19
Figure 7: FIS Editor for Membership Function variable
The process of specifying the input membership function for two input tipper problem is
a follows:
1. Select input variable, service, double clicking on it. Set both the Range
and the Display Range to the vector [0 10]
2. Select Remove All MFs from Edit menu. It removes all the existing
Membership Function from the Membership Function Editor.
3. Select Add MFs from Edit menu. The following window opens:
20
4. Use tab to choose “gaussmf” for MF Type and 3 Number of MFs. This
choice adds three Gaussian curves to the input variable service.
5. Click once on the curve with the left-most hump. Change the name of the
curve to poor. To adjust the shape of the membership function, click on
the membership function. The desired parameter Params listing for this
will appear. The two inputs of Params represent the standard deviation
and center for the Gaussian curve.
6. After editing all the value and adjusted the membership function, the
system will look similar to the following figure :-
21
3.1.2.3 Rule Editor
22
To call up the Rule Editor, choose Edit menu and select Rules or type ruleedit
at command line.[7]
23
Based on the description of the input and output variable defined with the FIS Editor, the
Rule Editor allows to construct the rule statements automatically. From GUI:-
• Create rules by selecting an item in each input and output variable box and
one Connection item and clicking Add Rule. You can choose none as one of
the variable qualities to exclude that variable from a given rule and choose
not under any variable name to negate the associated quality.
• Delete a rule by selecting the rule and clicking Delete Rule.
• Edit a rule by changing the selection in the variable box and clicking Change
Rule.
• Specify weight to a rule by typing in a desired number between 0 and 1 in
Weight. If you do not specify the weight, it is assumed to be unity (1).
The Rule Viewer displays a roadmap of the whole fuzzy inference process. It
based on the fuzzy inference. The three plots across the top of the Figure 7 represent the
antecedent and consequent of the first rule. Each rule is a row of plots, and each column
is a variable. The rule numbers are displayed on the left of each row. To view the rule in
the status line click the rule number.[7]
24