Design And Development Of Fuzzy Logic Based Level Controller.

(1)

DESIGN AND DEVELOPMENT OF FUZZY LOGIC BASED LEVEL CONTROLLER

AHMAD HATTA BIN ABDULLAH

This Report Is Submitted In Partial Fulfillment Of Requirements For The Bachelor Of Electrical Engineering (Industrial Power)

Faculty of Electrical Engineering Universiti Teknikal Malaysia Melaka


(2)

“I hereby declared that this report is a result of my own work except for the excerpts that have been cited clearly in references”

Signature : ………

Name : Ahmad Hatta bin Abdullah


(3)

To my beloved parents,


(4)

ACKNOWLEDGEMENTS

Alhamulillah and very great thankful to Allah for this completion my final project report. Firstly I would like to take this opportunity to express my deepest regards to Faculty of Electrical Engineering, Universiti Teknikal Malaysia Melaka for this opportunity and co-operative during my completion of this final project. I would like to extent my thanks to my supervisor, En Saifulaza bin Suhaimi @ Alwi @ for his contributions to my final year project where he had guided me, contribute ideas, theories, suggestions for improvement and problem solutions. To my family, this appreciation also dedicated to them as they always give me moral support, inspirations and prayer everyday. I am especially grateful and thankful to my friends and other lectures that had spent considerable time and effort for my understanding in electrical engineering field. Last but not least my thank goes to the person who directly and indirectly involved and contributed in completing this project.


(5)

ABSTRACT

This project will focus on design and development of water controller for small scale hydro generating units based on fuzzy logic approach. Fuzzy logic is a problem solving methodology that lends itself to implementation system ranging from simple, small, embedded micro controller to large, networked and controllable system. In this project, method of fuzzy logic will be applied to water level controller for small scale hydro generating units. Small scale hydro generating units, typically under 10MW, generate electricity or mechanical power by converting the power available in flowing water in rivers, canals or streams. The principle requirements of small scale hydro generating unit are suitable rainfall catchments area, transporting water from intake to the turbine, such as a pipe. Application of fuzzy logic is based on the control strategy that can be written in IF-THEN rule form, which is highly conformable to the human logic. The condition of the water level will be expressed by fuzzy set. Model analysis is given to demonstrate the effectiveness of the fuzzy logic control. A series of simulations will be carried out to show the performance of fuzzy logic approach for water level controller. The water level will be controlled and maintained at a certain value to make sure the hydro generating unit functioning properly.


(6)

ABSTRAK

Tujuan projek ini adalah untuk mencipta dan membina pengawal air untuk janakuasa air berskala kecil menggunakan logik kabur. Logik kabur adalah kaedah penyelesaian masalah yang menggunakan kaedah peraturan IF-THEN bagi pengawalan sistem yang mudah, kecil dan pengawal mikro kepada besar, berjaringan dan sistem yang terkawal. Dalam projek ini, kaedah logik kabur akan digunakan oleh pengawal aras air di janakuasa air berskala kecil. Biasanya janakuasa air berskala kecil menghasilkan tenaga elektrik dibawah 10MW dimana penghasilan tenaga elektrik dan tenaga mekanikal dengan menukar tenaga berkaitan dari arus sungai yang mengalir, parit atau kali. Antara keperluan janakuasa electrik berskala kecil ialah kawasan hujan yang sesuai dan pengaliran air ke turbin seperti paip. Penggunaan logik kabur adalah berdasarkan kepada strategi pengawal yang akan ditulis dalam bentuk peraturan „IF-THEN‟, dimana ia berdasarkan kepada logik manusia. Keadaan aras air akan ditunjukkan dengan set kabur. Analisis model akan dibina untuk membuktikan kecekapan pengawal logik kabur. Satu simulasi akan dijalankan untuk menunjukkan kebaikkan penggunaan logik kabur untuk pangawal aras air. Aras air akan dikawal dan diselaraskan pada satu tahap untuk memastikan janakuasa berfungsi dengan baik.


(7)

TABLE OF CONTENTS

CHAPTER TITLE PAGE

ACKNOWLEDGEMENTS iv

ABSTRACT v

TABLE CONTENTS vii

LIST OF TABLES x

LIST OF FIGURES xi

1 INTRODUCTION

1.1 Project Background 1

1.2 Project Objective 2

1.3 Problem Statements 2

1.4 Scope of Work 3

2 LITERATURE REVIEW

2.1 Introduction to Fuzzy Logic 4

2.1.1 Fuzzification 5

2.1.2 Inference Mechanism 6

2.1.3 Defuzzification 8

2.2 Fuzzy Logic Toolbox 9

2.3 Servo Motor 13

2.4 PIC 16F877 14

2.5 Ultrasonic Sensor 18

2.5.1 Fundamental Ultrasonic Properties 19 2.5.2 Speed of Sound in Air as a Function of

Temperature 19

Wavelength of Sound as a Function


(8)

Attenuation of Sound as a Function of

Frequency and Humidity 21

Relative Echo Levels from a Flat Surface

for Different Ultrasonic Frequencies 23

3 THEORY AND BACKGROUND

3.1 Control Theory 25

3.2 Types of Controller 25

3.3 Fuzzy Control in Detail 27

4 PROJECT METHODOLOGY

4.1 Background 34

4.2 Study and Research of the Project 34

4.3 Project Flow 35

4.4 FL Control System Design Methodology 37

4.5 Hardware Development 38

4.5.1 Design Circuit 38

4.5.2 Circuit Simulation 39

4.5.3 Circuit Constructions 39

4.5.4 Testing and Troubleshooting 40

5 PRELIMINARY RESULT AND DISCUSSION

5.1 Overview 41

5.2 Fuzzification 41

5.3 Inference Mechanism 42

5.4 Defuzzification 45

5.5 Simulation Using Fuzzy Toolbox 48

5.6 Circuit Simulation Result 52

5.6.1 Ultrasonic Sensor Circuit 52

5.6.2 Voltage Divider Circuit 53


(9)

5.6.4 Full Circuit 55

5.7 Hardware Implementation Result 62

5.8 Discussion 65

6 CONCLUSION AND SUGGESTION

6.1 Conclusion 66

6.2 Suggestions 67

REFERENCES 68


(10)

LIST OF TABLES

NO TITLE PAGE

4.1 Problem and solution in testing process 40


(11)

LIST OF FIGURES

NO TITLE PAGE

2.1 The features of a membership function 6 2.2 The horizontal coordinate of the centeriod 8

is taken as the crisp output

2.3 FIS Editor 9

2.4 Membership Function Editor 10

2.5 Rule Editor 11

2.6 Rule Viewer 12

2.7 Duration of Pulse Width Signal 13

2.8 Servos Turn Rate 14

2.9 PIC 16F877 pin diagram 16

2.10 PIC 16F877 block diagram 17

2.11 The speed of sound versus temperature 20

2.12 The wavelength versus frequency 21

2.13 Frequency over all humidities 22

2.14 Variations in the attenuation of sound in

air at room temperature 22

2.15 A sound beam reflected from a flat surface 23

2.16 The relative echo levels 24

3.1 Max min interfacing 29

3.2 Fuzzy set mapping 30

3.3 Rule 2 evaluated 31

3.4 Rule 3 evaluated 32


(12)

4.1 The flow chart methodology of this project 36

4.2 Fuzzy logic methodology 37

4.3 Complete soldering 39

5.1 Membership function for input 1 43

5.2 Membership function for input 2 43

5.3 Membership function for output 44

5.4 Input 1 (water level) 48

5.5 Input 2 (velocity) 48

5.6 Output (opening gate) 49

5.7 Rules 49

5.8 Simulation result 50

5.9 Ultrasonic circuit 52

5.10 Voltage divider circuit 53

5.11 Servo motor circuit 54

5.12 Very high condition 56

5.13 High condition 56

5.14 Medium condition 57

5.15 Low condition 57

5.16 Very low condition 58

5.17 Ultrasonic circuit construction 59

5.18 Control circuit construction 59

5.19 Complete circuit 60


(13)

CHAPTER 1

INTRODUCTION

1.1 Project Background

The past few years have witnessed a rapid growth in the number and variety of applications of fuzzy logic. The applications range from consumer products such as cameras, camcorders, washing machines, and microwave ovens to industrial process control, medical instrumentation, decision-support systems, and portfolio selection. In contrast to conventional control techniques, fuzzy logic control is best utilized in complex process that can be control by a skilled human operator without much knowledge or their understanding dynamics.

Nowadays, level controller based on fuzzy logic controller is widely use in industry field. But to apply in reservoir for hydro generating unit is a new idea in this field. Hopefully this invention will solve the problem occur in hydro generating unit, which is to maintain a level of water in reservoir.


(14)

1.2 Project Objectives

The project objectives are:

 To design a mechanism of water flow in and out  To design a water level controller in reservoir

 To create a programming that suitable for motor servo controller for chock open and off.

1.3 Problem Statement

The difficulty of small scale hydro generating system is the small capacity of reservoir and they often operate under strict water level control by a feedback control [1]. However the adjustment of the feedback control is difficult because of non-linearity and disturbance. Besides that, a small scale hydro generating unit needs to maintain level water in a constant level. Why hydro generating unit need to maintain level water in constant level? This is because hydro generating wants to produce constant electricity. The water flow out from the reservoir must in constant velocity to rotate the turbine in constant speed.

By application of fuzzy logic, the control strategy can be written in the IF-THEN rule form, which is highly conformable to the human logic for a proper maintenance of the water level and the conventional logic control by a programmable logic controller, which often covers all the function necessary to operate hydro generating units including the water level.


(15)

1.4 Scope of Work

In this project, we have a limitation task that we call scope of work. For this project, the scopes of work are:

i. Design a prototype of water flow in and out for reservoir which is capacity is not more than 15 liters

ii. Design a water level controller for reservoir using fuzzy logic method. The fuzzy logic rule can be written in the IF-THEN rule form.

iii. Set up programming for motor servo controller for chock open and off using PIC 16F877


(16)

CHAPTER 2

LITERATURE REVIEW

This chapter reviews existing project created to get an idea about the project design, concepts, specification and any information that related to improve the project. In later of this chapter, some review about proposed fuzzy logic approach to complete this project will also be explained.

2.1 Introduction to Fuzzy Logic

The concept of Fuzzy Logic was conceived by Lotfi Zadeh, a professor at the University of California at Berkley, and presented not as a control methodology, but as a way of processing data by allowing partial set membership rather than crisp set membership or non-membership. This approach to set theory was not applied to control systems until the 70's due to insufficient small-computer capability prior to that time. Professor Zadeh reasoned that people do not require precise, numerical information input, and yet they are capable of highly adaptive control. If feedback controllers could be programmed to accept noisy, imprecise input, they would be much more effective and perhaps easier to implement [2].

Fuzzy logic is a problem-solving control system methodology that lends itself to implementation in systems ranging from simple, small, embedded micro-controllers to large, networked, multi-channel PC or workstation-based data acquisition and control


(17)

systems. It can be implemented in hardware, software, or a combination of both. Fuzzy logic provides a simple way to arrive at a definite conclusion based upon vague, ambiguous, imprecise, noisy, or missing input information.

The benefits of fuzzy logic are [3]:

1. Suitable for complex system where mathematical modeling or plant is to abstract such as complex chemical plant.

2. Able to design along linguistic line – usage of rules based on experience. 3. Better performance than conventional PID controllers.

4. Simple to design

2.1.1 Fuzzification

Fuzzification is process of making a crisp quantity fuzzy. We do this by simply recognizing that many quantities that we consider to be crisp and deterministic are actually not deterministic at all. They carry considerable uncertainly. If the form of uncertainly happens to arise because of imprecision, ambiguity or vagueness then the variable is probably fuzzy can be represented by a membership function [4].

The membership function is a graphical representation of the magnitude of participation of each input. It associates a weighting with each of the inputs that are processed, define functional overlap between inputs, and ultimately determines an output response. The rules use the input membership values as weighting factors to determine their influence on the fuzzy output sets of the final output conclusion. Once the functions are inferred, scaled, and combined, they are defuzzified into a crisp output which drives the system. There are different memberships functions associated with each input and output response.


(18)

Triangular is common shape for membership function but bell, trapezoidal, haversine and, exponential have been used. More complex functions are possible but require greater computing overhead to implement... HEIGHT or magnitude (usually normalized to 1) WIDTH (of the base of function), SHOULDERING (locks height at maximum if an outer function. Shouldered functions evaluate as 1.0 past their center) CENTER points (center of the member function shape) OVERLAP (N&Z, Z&P, typically about 50% of width but can be less)[2]

Figure 2.1: The features of a membership function

2.1.2 Inference Mechanism

The inference mechanisms provide the mechanism for invoking or referring to the rule base such that the appropriate rules are fired. Two most common methods used in fuzzy logic control are the max-min composition and max-algebraic product composition. The inference or firing with this fuzzy relation is performed via the operations between the fuzzified crisp input and the


(19)

fuzzy relation representing the meaning of the overall set of rules. As a result of the composition, one obtains the fuzzy set describing the fuzzy value of the overall control output [4].

The MAX-MIN method tests the magnitudes of each rule and selects the highest one. The horizontal coordinate of the "fuzzy centroid" of the area under that function is taken as the output. This method does not combine the effects of all applicable rules but does produce a continuous output function and is easy to implement.

The MAX-DOT or MAX-PRODUCT method scales each member function to fit under its respective peak value and takes the horizontal coordinate of the "fuzzy" centroid of the composite area under the function(s) as the output. Essentially, the member function(s) are shrunk so that their peak equals the magnitude of their respective function ("negative", "zero", and "positive"). This method combines the influence of all active rules and produces a smooth, continuous output

The AVERAGING method is another approach that works but fails to give increased weighting to more rule votes per output member function. For example, if three "negative “rules fire, but only one” zero rules does, averaging will not reflect this difference since both averages will equal 0.5. Each function is clipped at the average and the "fuzzy" centroid of the composite area is computed.

The ROOT-SUM-SQUARE (RSS) method combines the effects of all applicable rules, scales the functions at their respective magnitudes, and computes the "fuzzy" centroid of the composite area. This method is more complicated mathematically than other methods, but was selected for this example since it seemed to give the best weighted influence to all firing rules.


(20)

2.1.3 Defuzzification

Defuzzification is a mapping from a space of fuzzy control actions defined over an output universe of discourse into a space of non-fuzzy (crisp) control action. This process is necessary because in many practical applications crisp control action is required to actuate the plant. The defuzzier also performs an output denormalization if normalization is performed in the fuzzification module. There are many method of defuzzification that has been proposed in recent years. Unfortunately, there is no systematic procedure for choosing a defuzzification strategy [2].

The most common defuzzification method is center of gravity method‟ this procedure is the most prevalent and physically appealing of all the defuzzification methods. For example:

Figure 2.2: The horizontal coordinate of the centeriod is taken as the crisp output

(neg_center * neg_strength + zero_center * zero_strength + pos_center * pos_strength) = OUTPUT (neg_strength + zero_strength + pos_strength


(21)

2.2 Fuzzy Logic Toolbox

The Fuzzy Logic Toolbox is a collection of functions built on the MATLAB® numeric computing environment. It provides tools for to create and edit fuzzy inference systems within the framework of MATLAB or integrate the fuzzy systems into simulations with Simulink®. It also can even build stand-alone C programs that calls on fuzzy systems have been build with MATLAB. This toolbox relies heavily on graphical user interface (GUI) tools to help accomplish any work [5].

Step to using fuzzy toolbox in matlab

1. In common window, type fuzzy. The FIS editor will show in the screen. 2. In FIS editor, select add variable input from the Edit menu.

Figure 2.3: FIS Editor

3. Double click at the input graph; the Membership Function Editor will come out. Set the desire value for input one. Repeat this step for input two and output.


(22)

(23)

4. Back to FIS editor. Select simulate ( mamdani ). The Rule Editor will shown. Then fill the fuzzy rule in Rule Editor.


(24)

5. Go back to FIS editor and select rules from View menu. The desire output will shown Rule Viewer.


(1)

fuzzy relation representing the meaning of the overall set of rules. As a result of the composition, one obtains the fuzzy set describing the fuzzy value of the overall control output [4].

The MAX-MIN method tests the magnitudes of each rule and selects the highest one. The horizontal coordinate of the "fuzzy centroid" of the area under that function is taken as the output. This method does not combine the effects of all applicable rules but does produce a continuous output function and is easy to implement.

The MAX-DOT or MAX-PRODUCT method scales each member function to fit under its respective peak value and takes the horizontal coordinate of the "fuzzy" centroid of the composite area under the function(s) as the output. Essentially, the member function(s) are shrunk so that their peak equals the magnitude of their respective function ("negative", "zero", and "positive"). This method combines the influence of all active rules and produces a smooth, continuous output

The AVERAGING method is another approach that works but fails to give increased weighting to more rule votes per output member function. For example, if three "negative “rules fire, but only one” zero rules does, averaging will not reflect this difference since both averages will equal 0.5. Each function is clipped at the average and the "fuzzy" centroid of the composite area is computed.

The ROOT-SUM-SQUARE (RSS) method combines the effects of all applicable rules, scales the functions at their respective magnitudes, and computes the "fuzzy" centroid of the composite area. This method is more complicated mathematically than other methods, but was selected for this example since it seemed to give the best weighted influence to all firing rules.


(2)

2.1.3 Defuzzification

Defuzzification is a mapping from a space of fuzzy control actions defined over an output universe of discourse into a space of non-fuzzy (crisp) control action. This process is necessary because in many practical applications crisp control action is required to actuate the plant. The defuzzier also performs an output denormalization if normalization is performed in the fuzzification module. There are many method of defuzzification that has been proposed in recent years. Unfortunately, there is no systematic procedure for choosing a defuzzification strategy [2].

The most common defuzzification method is center of gravity method‟ this procedure is the most prevalent and physically appealing of all the defuzzification methods. For example:

Figure 2.2: The horizontal coordinate of the centeriod is taken as the crisp output

(neg_center * neg_strength + zero_center * zero_strength + pos_center * pos_strength) = OUTPUT (neg_strength + zero_strength + pos_strength


(3)

2.2 Fuzzy Logic Toolbox

The Fuzzy Logic Toolbox is a collection of functions built on the MATLAB® numeric computing environment. It provides tools for to create and edit fuzzy inference systems within the framework of MATLAB or integrate the fuzzy systems into simulations with Simulink®. It also can even build stand-alone C programs that calls on fuzzy systems have been build with MATLAB. This toolbox relies heavily on graphical user interface (GUI) tools to help accomplish any work [5].

Step to using fuzzy toolbox in matlab

1. In common window, type fuzzy. The FIS editor will show in the screen. 2. In FIS editor, select add variable input from the Edit menu.

Figure 2.3: FIS Editor

3. Double click at the input graph; the Membership Function Editor will come out. Set the desire value for input one. Repeat this step for input two and output.


(4)

(5)

4. Back to FIS editor. Select simulate ( mamdani ). The Rule Editor will shown. Then fill the fuzzy rule in Rule Editor.


(6)

5. Go back to FIS editor and select rules from View menu. The desire output will shown Rule Viewer.