51
CHAPTER-1 INTRODUCTION The very essential task of closed loop controlled system is tuning the controller. In order to find the optimal controller parameters, the model of the process is very important. PI controller is the most popular feedback controller commonly used with in process industries. The controller is generally preferred in the modern process industries due to its robustness, excellent control and performance despites the varied dynamic characteristics of process plant .For the effective performance of the PI control loop, it is necessary to get the control loop properly tuned. Standard methods of tuning gives satisfactory for linear process. Generally for nonlinear system adaptive control methods are suggested, but one should be careful with the possible abuses of the adaptive schemes which may produce results worse than that achievable by conventional PI controller. In order to increase the performance of control loops employed with the nonlinear system and modern complex control loops we need modern methods of tuning. In this project, the parameter settings of PI controller are obtained by means of closed loop ZN tuning method, Fuzzy Logic based PI controller and Genetic Algorithm based PI controller. The effectiveness of the optimum settings is verified with the settings of the conventional method using the model of air temperature process. 1

Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Embed Size (px)

Citation preview

Page 1: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

CHAPTER-1

INTRODUCTION

The very essential task of closed loop controlled system is tuning the

controller. In order to find the optimal controller parameters, the model of the

process is very important.

PI controller is the most popular feedback controller commonly used

with in process industries. The controller is generally preferred in the modern

process industries due to its robustness, excellent control and performance

despites the varied dynamic characteristics of process plant .For the effective

performance of the PI control loop, it is necessary to get the control loop

properly tuned. Standard methods of tuning gives satisfactory for linear process.

Generally for nonlinear system adaptive control methods are suggested,

but one should be careful with the possible abuses of the adaptive schemes

which may produce results worse than that achievable by conventional PI

controller. In order to increase the performance of control loops employed with

the nonlinear system and modern complex control loops we need modern

methods of tuning.

In this project, the parameter settings of PI controller are obtained by

means of closed loop ZN tuning method, Fuzzy Logic based PI controller and

Genetic Algorithm based PI controller.

The effectiveness of the optimum settings is verified with the settings of

the conventional method using the model of air temperature process.

1

Page 2: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

1.1 OBJECTIVES

• To identification of model parameter of air temperature process.

• To obtain the mathematical model of the air temperature process.

• To design of conventional PI controller for air temperature process using

ZN tuning rule

• To design of fuzzy logic PI controller for air temperature.

• To design of Genetic Algorithm based optimal PI controller for air

temperature process

1.2 ORGANIZATION OF THE THESIS

Chapter: 2 deals with the Design of controllers

Chapter: 3 deals with process description

Chapter: 4 deals with result and discussion

2

Page 3: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

CHAPTER-2

DESIGN OF CONTROLLER

2.1 INTRODUCTION

Tuning a controller implies setting its adjustable parameters to

appropriate values that provide good control performance. Generally the

methods are classified for linear and non linear system.

2.2 CONVENTIONAL PI CONTROLLER

For linear system synthesis method, Z-N, Coohen-coon methods are

suggested for non linear system. The Ziegler – Nichols’ open loop method is

based on the process step response. The PI parameters are calculated from the

response in the process measurement ym after a step with height U in the control

variable u, see figure 1. The term “process” here means all blocks in the control

except controller. The step response experiment is executed on the uncontrolled

process, so the control loop is open (no feedback).

Figure 1: Ziegler – Nichols’ open loop method is based on the step

response of the uncontrolled process

3

Page 4: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

2.2.1 MODELING FOR AIR TEMPERATURE PROCESS

In order to find the process modeling, the system was put in to open loop

condition. After steady state was reached, the step change of specify magnitude

was given to the process by changing the inflow of air. First fix the operating

region after analyzing the different operating points in the air temperature

process. Then the gain & time constant of the process are determined by giving

the step change to the air temperature process. Now the process is approximated

to first order with dead time delay (FOPDT) as shown in figure 2.

0 2 0 0 4 0 0 6 0 0 8 0 0 1 0 0 0 1 2 0 0 1 4 0 0 1 6 0 0 1 8 0 0 2 0 0 00

5

1 0

1 5

2 0

2 5

3 0

3 5

4 0

4 5

T i m e i n s e c

Tem

pera

ture

(C)

Figure: 2 Open loop curve

Model parameters are identified using two point technique

From the data

KP = ∆output / ∆Input

τ = 1.5 (t2- t1)

Where Kp =gain of the process

τ = Time constant

td = t2 - τ

4

28.3%

63.2%

t1 t2

Page 5: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

The PI controller settings are

Kc = dp tkτ*0.9

Ti = 3.33*td

2.3 FUZZY PI CONTROLLER

The main paradigm of fuzzy control is that the control algorithm is a

knowledge based algorithm, described by methods of fuzzy logic. The fuzzy

logic control system is a kind of expert knowledge – based system that contains

the control algorithm in a simple rule base. The knowledge encoded in the rule

– base is derived from human experience and controlled system. This makes the

fuzzy control special and conceptually different from conventional control. The

operation of approximate reasoning converts the knowledge embedded in the

rule – base (IF – THEN rules) into a crisp (nonfuzzy) control algorithm.

Keeping this in mind, a PI like FLC is designed using fuzzy logic toolbox for

Air Temperature Process and its performances are compared with genetic

algorithm based optimal PI controller. The operation of FLC can be explained

as follows:

If the measured process output is a crisp quantity, it can be fuzzified into

a fuzzy set. This fuzzy output in then considered as the fuzzy input to a fuzzy

controller, which consists of linguistic rule. The output of the fuzzy controller is

then another series of fuzzy sets. Since most physical systems cannot interpret

fuzzy commands (fuzzy sets), the fuzzy controller output must be converted

into crisp quantities using defuzzification methods. These crisp (defuzzified)

control – output values then become the input values to the physical system and

the entire closed – loop cycle is repeated.

5

Page 6: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

2.3.1 PI like FLC

The FLC describes with the aid of fuzzy IF-THEN rules the relationship

between the change in the control output Δu(k) = u(k) – u(k-1) on one hand, and

the error e(k) and its change Δe(k) = e(k) – e(k-1) on the other hand as given by

Δu(k) = F(e(k), Δe(k)) (1)

The internal mechanism of the FLC translates it into a mapping:

Δu(k) = f(e(k), Δe(k)) (2)

This relation is similar to conventional PI controller as

Δu(k) = Kp Δe(k) + Ki e(k) (3)

Where Kp and Ki are the parameters of the PI controller. This FLC is

called as a PI – like FLC. In case of PI controller, the equation (3) is linear,

while in FLC, equation (2) is nonlinear.

2.3.1 Design procedure of FLC

Important steps in the design of FLC are listed as

Step1: Determine the input and output variables of FLC: by appropriate

selection of the input and output variables the controller can be identified as PI

– like, PD – like, or PID- like FLC.

Step2: Define the parameters of FLC: Determine the scaling factors and the

normalized universes of discourse and membership functions of the reference

fuzzy sets associated with the linguistic labels of the main variables like error

(e), change in error (Δe(k)) and output Δu(k).

Step3: Determine the rule – base of the FLC: The rule table is formed using the

three meta rules given by

6

Page 7: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Step4: Computational realization of the FLC : The fuzzy output of the FLC is

converted into a crisp output using defuzzification method.

1. If the error e(k) and its change Δe(k) are zero, then maintain present

control setting.

2. If the error e(k) is tending to zero at a satisfactory rate, then maintain

present control setting.

3. If the error e(k) is not self – correcting, then control action setting Δu(k)

is not zero and depends on the sign and magnitude of e(k).

2.3.2 Fuzzy toolbox commands

1. FIS editor – using this command Mandani or sugeno type FIS can be

selected.

2. Input / output – using this command number of inputs / outputs can be

selected.

3. MF editor – Using this command number of membership functions

(MFs) can added, modified or deleted. Also type of MFs can be selected.

4. Rule editor – using this command rules can be edited, modified or

deleted.

5. Rule viewer – firing strength of the rules can be viewed.

6. Surf viewer – output surface can be viewed.

2.3.3 FLC design for air temperature process

Reference input : r(k)

Process output : y(k)

Error e(k) : r(k) – y(k)

7

Page 8: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Change in error Δe(k) : e(k) – e(k-1)

Input variables : Error e and change of error Δe

Output variables : Change of Δu

Membership function type : Triangular with 50% overlapping

Defuzzification method : Center Of Gravity (OCG) method

The range of error : [-1 1]

The range of change in error: [-1 1]

The range of change in output: [-0.01 0.01]

The membership diagrams of e, Δe and Δu are shown in figures 3, 4, 5

the fuzzy control rule table for the given process is given in table1.

Table: 1 FAM (control rules) table

Δee

NB NM NS ZE PS PM PB

NB NB NB NM NM NS NS ZE

NM NB NM NM NS NS ZE PS

NS NM NM NS NS ZE PS PS

ZE NM NS NS ZE PS PS PM

PS NS NS ZE PS PS PM PM

PM NS ZE PS PS PM PM PB

PB ZE PS PS PM PM PB PB

8

Page 9: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Figure: 3 Membership diagram for error

Figure: 4 Membership diagram for change in error

Figure: 5 Membership diagram for change in output

9

Mem

bers

hip

valu

e (µ

)M

embe

rshi

p va

lue

(µ)

Mem

bers

hip

valu

e (µ

)

Page 10: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

2.4 GENETIC ALGORITHM

Genetic Algorithms (GA) are stochastic global search methods based on

the mechanics of natural selection and natural genetics. They are iterative

methods, widely used in optimization problems in several branches of the

Science and Technologies. Contrary to what happens in other methods, in this

methodology. In each iteration (generation), not only one point in the search

space is taken into account, but a set of solutions defining a population or

populations of individuals is considered. Genetic Algorithm loop as shown in

figure 6.

Figure: 6 Genetic Algorithm loop

10

Page 11: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

1. Initial population

2. Selection individuals for mating

3. Mate individuals to generate offspring

4. Mutate offspring

5. Insert new individuals into population

6. Are criteria satisfied?

7. End of searching

As we can notice above a loop of evolution is closed. Replication starts

from base point again and the best individuals are chosen. The selection of

chromosomes is a random process, but it is very strongly directed for choosing

the best individuals for reproduction. A common practice is to terminate the GA

after number of generation and then test the quality of the best number of the

population against the problem definition. If no acceptable solutions are found,

the may be restarted or a fresh initiated.

2.4.1 Chromosomal representation

Individuals are encoded as strings, chromosomes composed over some

alphabet, so that the genotypes are uniquely mapped onto the decision variable

domain. The most often used for representation in Gas is the binary alphabet.

Here each decision variable in the parameter set is encoded as a binary string

and these are concatenated to form a chromosome.

The chromosomes are seen as binary strings of given length, and

decoded into real numbers over a specified interval using either standard binary

or gray coding. The use of gray coding for binary chromosome representation is

recommended as the regular Hamming distance between intervals reportedly

makes the genetic search less deceptive.

11

Page 12: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

2.4.2. Population

The population size is the number of chromosomes in the population.

Having decided the representation, the first step is to create an initial

population. This is usually achieved by generating the required number of

individuals using a random number generator that uniformly distributes number

in the desired range. For example, with the binary population of Nind individuals

whose chromosomes are Lind bits long, Nind x Lind random numbers uniformly

distributed from the set {0, 1} would be produced.

There exist three main variations of genetic algorithms: simple, steady –

state and struggle population.

2.4.3 Simple GA

The simple genetic algorithm is one of the common genetic algorithm

implementations. The simple genetic algorithm uses non – overlapping

population. In each generation, the entire population is replaced with new

individuals. Typically the best individual is carried over from one generation to

the next so that the genetic algorithm does not inadvertently forget the best that

it found. Since the entire population is replaced each generation, the only

“memory” the algorithm has from performance of the crossover operator.

2.4.4 Steady state GA

The study state genetic algorithm uses overlapping population. In each

generation, the newly generated individuals replace a portion of the population.

At one extreme, only one or two algorithm can became a simple genetic

algorithm when the whole entire population is replaced. Since the algorithm

only replaced a portion of the population of each generation, the best

individuals are more likely to be selected and the population quickly converges

to a single individual.

2.4.5 Struggle GA

12

Page 13: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

The struggle genetic algorithm is similar to steady – state GA. However,

rather that replacing the worst individual, a new individual replaced the

individual most similar to it, but only if the new individual has a score better

than that which is the most similar.

2.4.6 Fitness function

A fitness function must be devised for each problem, given a particular

chromosome, the fitness function returns a single numerical fitness value, which

is proportional to the ability, or utility, of individual represented by that

chromosome.

For many problems deciding upon the fitness function is very straight

forward, for example for a function optimization search, the fitness is simply

the value of the function. However there are cases where may be performance

measured to optimize.

Ideally, the fitness function should be smooth and regular so those

chromosomes with reasonable fitness are closer in the search space, to

chromosomes with slightly better fitness. However, it is not always possible to

construct such an ideal fitness function. For any type of search to be successful,

the fitness function must not have many local maximums, or a vary isolated

global maximum.

2.4.7 Genetic Algorithms Operations

2.4.7.1 Selection

The purpose of parent selection in a GA is to given more reproductive

changes to those individuals that are the fit. There are many ways to do it, but

one commonly used technique is roulette wheel parent selection (RWS), which

contains three basic steps:

1. Sum the fitness of all population members and name the result total

fitness,

2. Generate n, a random number between 0 and total fitness,

13

Page 14: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

3. Return the first population members whose fitness, added to the fitness

of preceding population members, is greater or equal to n.

The effect of roulette wheel parent selection is to return a randomly

selected parent. Using this selection algorithm, each parent’s chance of being

selected is directly proportional to its fitness, but its possible also exists to

choose the worst population member.

A second very popular way of selection is stochastic universal sampling

(SUS). This way is a single – phase algorithm with minimum spread and zero

bias.

2.4.7.2 Crossover (Recombination)

The basic operator for producing new chromosomes in the GA is that of

crossover. Like in nature, crossover produces new individuals, which have some

parts of both parents genetic material. The simplest form of crossover is that of

single – point crossover.

Figure: 7 Single point crossover

Of course there exist other crossover variations such as dual point,

multipoint, uniform, shuffle, asexual crossover, and single child crossover.

2.4.7.3 Mutation

Mutation causes the individual genetic representation to be changed

according to some probabilistic rule. In binary string representation, mutation

case a random bit to change its stat (0 1 or 1 0) and it illustrated in figure

below. In natural evaluation, mutation is randomly applied with low probability,

typically in the range 0.001 and 0.01 and modifies element in the chromosomes.

Given that mutation is generally applied uniformly to an entire population of

14

Page 15: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

string, it is possible that a given binary string may be mutated at more than one

point.

Figure: 8 Binary Mutations

2.4.7.4 Reinsertion

Once selection and recombination of individuals from the old population

have produced a new population, the fitness of the individuals in the new

population may be determinate. If fewer individuals are produced by

recombination than the size of the original population, than the fractional

difference between the new and old population sizes in termed a generation gap.

To maintain the size of the original population, the new individuals have

to be reinserted into the old population. Similarly, if not all the new individuals

are to be used at each generation or if more offspring are generated than size of

old population then a reinsertion scheme must be used to determine which

individuals are to exist in the new population. When selecting which members

of the old population should be relocated the most apparent stratyegy is to

replace the least fit members deterministically. The replacement should select

and replace the oldest members of the population.

2.4.8 Genetic Algorithm code in MATLAB

The genetic algorithm toolbox tries to maximize a function using a

simple (haploid) genetic algorithm to find a maximum of the fitness function.

This toolbox consist of net ten files

B10TO2 Converts base 10 to base 2

DECODE Converts from binary to variable representation

15

Page 16: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

ENCODE Converts from variable to binary representation, this script

demonstrates the use of the simple genetic algorithm

GENETIC Tries to maximize a function using a simple genetic

algorithm

GENPLOT Graphing routine for genetic algorithm

MATE Randomly reorders (mates) OLD_GEN

MUTATE Change a gene of the OLD_GEN with probability Pm

REPRODUC Selects individuals proportional to their fitness

TESTGEN Tests genetic algorithm code with f(x) = x10

XOVER Creates a NEW_GEN from OLD_GEN using crossover

2.5 Conclusion

In this chapter the design of various tuning techniques for non linear

process were discussed.

16

Page 17: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

CHAPTER- 3

PROCESS DESCRIPTION

3.1 INTRODUCTION

The developed of controller tuning scheme for non linear air

temperature process is tested by using developing a mathematical model of the

system.

3.2 PROCESS IDENTIFICATION

The processes used in our control systems have been described by

transfer functions that were derived by applying fundamental principles of

physics and chemical engineering (e.g., Newton’s law, material balance, heat

transfer, fluid mechanics, reaction kinetics, etc.) to well defined processes. In

practice, many of the industrial processes to be controlled are too complex to be

described by the application of fundamental principles. Either the task requires

too much time and effort or the fundamentals of the process are not understood.

By means of experimental tests, one can identify the dynamical nature of such

process and from the results obtain a process model which is at least satisfactory

for use in designing control systems. The experimental determination of the

dynamic behavior of a process is called process identification.

The need for process models arises in many control applications, as we

have seen in the use of tuning methods. Process models are also needed in

17

Page 18: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

developing feed forward control algorithms, self-tuning algorithms, and internal

model control algorithms.

Process identification provides several forms that are useful in process

control; some of these forms are

Process reaction curve (obtained by step input)

Frequency response diagram (obtained by sinusoidal input)

Pulse response (obtain by pulse input)

3.3 CLOSED LOOP CONTROL OF AIR TEMPERATURE PROCESS

The process medium used there is air. The temperature of the air is to be

controlled and is allowed to flow through a polypropylene tube. The air is

heated by the heating chamber.

The temperature of the air is sensed by a suitable sensor (RTD- 2) whose

output (4 – 20 mA) is given to the PI controller. The controller compares this

measured variable with its set point value and the error produced is manipulated

through PI circuitry as controllers output (4 – 20 mA). This signal is given as

input to the triac driver circuit.

Triac driver in turn supplies variable AC voltage in the range of 0 – 230

V to the heater which is proportional to controller output. The final control

element is the Triac driver. The input to the heater controls the chamber

temperature which in turn maintains the desired temperature of the air media to

be controlled.

In this project, PI controller modes are implemented and Kc and Ti can

be returned to the desired values so as to achieve the desired closed loop

performance.

18

Page 19: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

3.4 WORKING PRINCIPLE

The schematic diagram of the laboratory air temperature process taken

for project is shown in figure 9. The process supplies air at constant temperature

and at constant rate. The constant flow rate of air is maintained by an air

blower. The dry air follow thought the polypropylene type and is heated by the

heating chamber consisting of two heater elements. The temperature of the

following air is to be controlled.

The temperature of the air is sensed by three RTDs. Output of the RTDs

is given to the PC through (i) a suitable signal conditioner and (ii) an analog to

digital converter (ADC). The signal conditioning circuit converts the entire

range of temperature into the range 0 – 5V dc. The ADC converts the process

variable into its equivalent digital value and feeds to the PC. Here the PC is

used as an IMC controller. The controller compares it with the set point 4 – 20

mA which is given to thyristor power controller (TPC) via digital to analog

converter (DCA). The TPC manipulates the power supplies to the heater

element. In this way the closed loop control is achieved.

19

Page 20: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Figure: 9 Schematic (P&I) diagram of laboratory Air Temperature Process

20

Page 21: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Figure: 10 Laboratory Air Temperature Process

21

Page 22: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

3.4.1 Precautions

The following precautions should be taken care before turning ON

process

1. Manual value (MV!) should be half open. MV1 and MV3 should be

fully open.

2. PID controller should be in manual mode

3. During start up sequence, first the blower should be turned ON and then

the heater should be ON.

4. To turn OFF the system, first the heater should be turned OFF and then

the blower should be turned OFF.

3.5 CALCULATION OF PI CONTROLLER SETTING

The general from of a first order process with dead time is given by

Where Kp – process gain

τ – Time constant

td – time delay of the process

The identified model for air temperature process is given by

22

Page 23: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

The PI controller setting for air temperature process using the Zeigler

Nicholas tuning rules

Kc = dp tkτ*0.9

Ti = 3.33*td

3.6 CONCLUSION

The nonlinear air temperature system identified model in obtained

23

Page 24: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

CHAPTER- 4

RESULTS AND DISCUSSIONS

4.1 INTRODUCTION

The tuning results for the parameter settings from the various techniques

are obtained and the behavior of the non-linear air temperature is observed by

implementing the controller parameter settings in the non linear air temperature

process control scheme.

4.2 IDENTIFICATION OF TUNING PARAMETERS (ZN – METHOD)

Consider the air temperature process,

The controller parameters Kc and Ti are obtained from transfer function

using ZN- tuning method

Kc = dp tkτ*0.9

Kc = 63*7.91

567*0.9

Kc = 1.024

Ti = 3.33*td

Ti = 3.33*63 = 209.79

24

Page 25: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

4.3 GENETIC ALGORITHM OPTIMAL PI CONTROLLER

4.3.1 PID Controller Optimizer

PID Controller Optimizer is a MATLAB based interface written by the

author and it can be used to optimize PID parameters for the plant model

defined by the user. In the package, Simulink is used in modelling the plant,

which can be SISO continuous/discrete/hybrid, and linear/nonlinear systems of

any complexity. The optimization criteria are ITAE, ISE, IAE and others, which

will be defined later in the tutorial.

One may install the package to a MATLAB directory and include the

path with "File/Set Path" menu item. Then type pid_optimizer under

MATLAB prompt, the design interface will be displayed below.

This is Version 2 of PID Controller Optimizer Interface, released in Sept

2011. The first version was developed in 2008, mainly by the student Dong

Wenbin, and the new one is completely rewritten, with much simpler coding,

due to the release of the PID controller block in Simulink since 2009b. This

version works ONLY for MATLAB R2009b onward and was fully tested in

MATLAB R2011a.

4.3.2 Meaningful Optimization Criteria

The block diagram of the controlled system is shown below, where the

sophistigated PID controller block in the new version of MATLAB/Simulink is

used as the kernel, such that the controller can be tuned with the easy-to-use

manner. The interface is fully tested under MATLAB R2011a, and may work

well with the versions where PID controller block is provided.

25

Page 26: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Figure: 11 Plant Model

The user may construct the plant model with Simulink. The optimized

controller parameters can be obtained by minimizing one of the following

criteria

The ITAE criterion is recommended for a good controller.

4.3.3 To run PID Controller Optimizer

To run the interface, one can issue the command "optimpid" to start the

PID Controller Optimizer program. The interface shown below will be

displayed. An internal Simulink main model is opened and hidden. The plant

model should be created before the interface can be used. If the model created

is "air_temp_tran.mdl", the file name should be entered into the "Plant model

name" edit box. To display the plant model, the button "Show Model" can be

clicked.

26

Page 27: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Figure: 12 PID Controller optimizer

One may use the following essential procedures to design the controller

Step: 1 Enter the Simulink file name in the edit box "Plant model

name", and if a linear plant is involved, one can fill in in the edit box the pre-

composed Simulink model name "air_temp_tran.mdl". The plant model can

also be specified with the dialog box braught in by the file opening icon.

Figure: 13 “air_temp_tran.mdl”

27

Page 28: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Step: 2 Specify the terminate time in the "Terminate Time" edit box.

Step: 3 Click "Create Files" can be used to generate the objective

function in MATLAB.

Step: 4 Click "Optimize" button to design the controller and meanwhile

visualing the optimization process by displaying the relevant curves with the

Scope.

The type of PID type controller can be specified in the group

"Controller Type", where different forms of PID controllers are supported.

The available controller structure can be selected from the

"P/PI/PD/PID/I" controllers list, also "anti-windup PI and PID" controllers

are also supported. The actuator saturation of the controller can be assigned, if

applicable, but the "Actuator Saturation" group. The currently allowed

criterion can be selected from the "ISE/ITAE/IAE/ITSE/IT^2SE/IT^2AE"

list box.

The button "Show Model" can be used to show the plant model in

Simulink.

The "Show File" button can be used to display the objective function

generated.

The "Refresh" button can be used to delete all the existing plant model files, if

any. And also the initial values.

The "Simulation" button can evaluate multi-stairs simulation, and the

driven signal and terminating time can be specified with the "Multi-stairs

Signal" group. The "Hold" checkbox can be used to design optimal controller

under multi-stairs signal instead.

28

Page 29: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

The optimized controller parameters can be returned in "Tuned

Controller" edit box, while the allowed lower and upper bounds in the

optimization process. These parameters can be set in the "Controller

Parameters" group.

Controller parameters are obtained by PID controller optimizer:

Kc = 0.9157

Ti = 0.0037

29

Page 30: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Simulation runs of air temperature process are carried out with GA

based PI values. Initially the air temperature is maintained at 40 % operating

temperature, after that, a step size of ±5% of temperature is applied to control

loop. Similar test runs of fuzzy based PI and conventional PI are carried out and

the responses are recorded in figure 15, figure 17 and figure19. From the

results, the performance indices are analyzed in terms of ISE are tabulated in

table 2. The results proven that GA based PI controller gives better performance

than the others.

Figure: 14 Simulink diagram of conventional PI controller

30

Page 31: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

0 5 0 0 1 0 0 0 1 5 0 0 2 0 0 0 2 5 0 0 3 0 0 00

1 0

2 0

3 0

4 0

5 0

6 0

7 0

T i m e i n s e c

Tem

pera

ture

(C

)

i n p u t

o u t p u t

Figure: 15 Typical response of conventional PI controller

Figure: 15 Shows the closed loop responses for nonlinear air

temperature process using conventional PI controller. The simulation sequences

are: at time=0, a set point step change of 40oC is initiated and at time = 1500sec,

disturbance 5oC applied on the process.

31

Page 32: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Figure: 16 Simulink diagram of fuzzy logic PI controller

32

Page 33: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

0 5 0 0 1 0 0 0 1 5 0 0 2 0 0 0 2 5 0 0 3 0 0 00

1 0

2 0

3 0

4 0

5 0

6 0

7 0

T i m e i n s e c

Tem

pera

ture

(C

)

i n p u t

o u t p u t

Figure: 17 Typical response of Fuzzy Logic PI controller

Figure 17 Shows the closed loop responses for nonlinear air temperature

process using fuzzy logic PI controller. The simulation sequence are: at time=0,

a set point step change of 40oC is initiated and at time = 1500sec, disturbance

5oC applied on the process.

33

Page 34: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Figure: 18 Simulink diagram of Genetic Algorithm optimal PI controller

0 5 0 0 1 0 0 0 1 5 0 0 2 0 0 0 2 5 0 0 3 0 0 00

1 0

2 0

3 0

4 0

5 0

6 0

7 0

T i m e i n s e c

Tem

pera

ture

(C

)

i n p u t

o u t p u t

Figure: 19 Typical response of Genetic Algorithm optimal PI controller

Figure: 19 Shows the closed loop responses for nonlinear air

temperature process using genetic algorithm optimal PI controller. The

simulation sequence are: at time=0, a set point step change of 40oC is initiated

and at time = 1500sec, disturbance 5oC applied on the process.

34

Page 35: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Table.2. Performance analysis based on ISE operating range of 40% of temperature

METHOD ISE ts (secs)

Conventional PI controller 204767.95 1350

Fuzzy logic PI controller 206025.29 1470

Genetic algorithm optimal PI

controller

184767.95 1185

4.5 Conclusion

In this chapter the controller parameters were obtained and implemented

for the non linear air temperature process.

35

Page 36: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

CHAPTER- 5

CONCLUSION

In this project, a new method is developed and implemented for the

design of the PI controller based on a GA approach. This approach is related to

process control applications with a large dead time. A GA scheme repetitively

changes the control signal to achieve error convergence. The GA based PI is

implemented in a Temperature control of Air temperature process. A

comparison of the GA based PI mode controller with Fuzzy based PI mode and

ZN based PI mode control is made. Simulations results are furnished to

illustrate the efficiency of the proposed method.

36

Page 37: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

REFERENCES

[1].K. K. Tan, R. Ferdous, S. Huang.(2002). Closed-loop automatic tuning

of PID controller for nonlinear systems. Chemical Engineering Science

57 ,3005 – 3011

[2].Astrom, K. J., & Hagglund, T. (1988). Automatic tuning of PID

controllers. Research Triangle Park, NC: Instrument Society of America.

[3].Astrom, K. J., & Hagglund, T. (1995). PID controllers: Theory, design

and tuning. Research Triangle Park, NC: Instrument Society of America.

[4].Gawthrop, P. J. (1986). Self-tuning PID controllers: Algorithms and

implementations IEEE Transaction on Automatic Control, 31(3), 201.

[5].Ho, W. K., Hang, C. C., & Cao, L. S. (1995). Tuning of PID controllers

based on gain and phase margin speci2cation. Automatica, 31, 497–

502.

[6].Ordonez, R., & Passino, K. M. (2001). Adaptive control for a class of

nonlinear systems with a Time varying structure. IEEE Transactions on

Automatic Control, 46(1), 152–155.

[7].Zeigler, J.G., and Nichols, N.B.(1942).Optimum setting for automatic

controllers.Transactions of the ASME,64,759-768.

[8].George stephanopoulos, “chemical process control-An introduction to

Theory and practice,” Prentice Hall India, New Delhi. 1999.

[9].Donald R. Coughanowr, Process Systems Analysis and Control, Mc

GRAW – HILL international editions, second edition 1991.

[10]. www.mathwork.com

37

Page 38: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

APPENDIXES

Appendix A m-file

Genetic_algorithm.mfunction varargout = optimpid(varargin)% OPTIMPID Optimal PID controller design interface.% MATLAB code for optimpid.figf% Last Modified by GUIDE v2.5 05-Nov-2011 01:00:59% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @optimpid_OpeningFcn, ... 'gui_OutputFcn', @optimpid_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end function optimpid_OpeningFcn(hObject, eventdata, handles, varargin)v=version; i=findstr(v,'R'); s1=v(i:i+5); pause(0.0001)if eval(v(i+1:i+4))>2011, s1='R2011a'; endtry str=which(['pidctrl_model' s1 '.mdl']); i=findstr(str,'pidctrl_model'); fpath=[str(1:i-1),'models\']; if length(str)==0 errordlg({'Sorry, the current version is NOT supported,'; 'please try a later one'},'Error in MATLAB version') else copyfile(str,'pidctrl_model.mdl','f'); copyfile([fpath,'mod_1' s1 '.mdl'],'mod_1.mdl','f') copyfile([fpath,'mod_2' s1 '.mdl'],'mod_2.mdl','f') copyfile([fpath,'mod_3' s1 '.mdl'],'mod_3.mdl','f') copyfile([fpath,'mod_lti' s1 '.mdl'],'mod_lti.mdl','f') end

38

Page 39: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

catch errordlg({'Sorry, the current folder is a read-only one,'; 'please try another one'},'Error in working folder')endhandles.output = hObject;guidata(hObject, handles);assignin('base','t_seq',0); assignin('base','y_seq',1); assignin('base','keyCriterion',1); assignin('base','Kp',1); assignin('base','Ki',1); assignin('base','Kd',1);set(handles.hEdtConPars,'String','');str='pidctrl_model.mdl.autosave'; h=dir; for i=3:length(h) if strcmp(str,h(i).name), delete(str); break; endendload_system('pidctrl_model')mod_name=get_param('pidctrl_model/Plant Model','ModelNameDialog');set(handles.hEdtPlant,'String',mod_name); % --- Outputs from this function are returned to the command line.function varargout = optimpid_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function hEdtPlant_Callback(hObject, eventdata, handles)mod_name=get(handles.hEdtPlant,'String');set_param('pidctrl_model/Plant Model','ModelNameDialog',mod_name);load_system(mod_name);set_param(mod_name,'InlineParams','on'); % --- Executes on selection change in hListCriterion.function hListCriterion_Callback(hObject, eventdata, handles)assignin('base','keyCriterion',get(handles.hListCriterion,'Value')); function hBtnShowModel_Callback(hObject, eventdata, handles)open_system(get(handles.hEdtPlant,'String')); function hBtnFile_Callback(hObject, eventdata, handles)[FileN,PathN]=uigetfile('*.mdl','Select a plant model');set(handles.hEdtPlant,'String',FileN);hEdtPlant_Callback(hObject, eventdata, handles); function hBtnShow_Callback(hObject, eventdata, handles)str=get(handles.hBtnCreate,'UserData'); edit(str)

39

Page 40: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

function hBtnOptim_Callback(hObject, eventdata, handles)set_param('pidctrl_model/Scope','Open','on');str=get(handles.hBtnCreate,'UserData');if length(str)==0 | exist(str)~=2 errordlg({'Error: No objective function file existing. Click ''Create '; 'File'' button to create it first.'},'Error in objective function file'); returnendff=msgbox({'Optimization process is going on. Go back to the Command Window'; 'for optimalization results. Please wait ...'},'Optimizing ...');options=optimset(...%'Display','iter', 'Jacobian','off','LargeScale','off','MaxIter',20);str=get(handles.hBtnCreate,'UserData'); kTool=get(handles.hLstAlgorithm,'Value'); n=get(handles.hLstPIDType,'UserData'); X1=ones(n,1);if get(handles.hChkHold,'Value')==1 set(handles.hEdtTerm,'String',get(handles.hEdtEnd,'String')) hBtnCreate_Callback(hObject, eventdata, handles) assignin('base','t_seq',eval(get(handles.hEdtTSeq,'String'))); assignin('base','y_seq',eval(get(handles.hEdtYSeq,'String')));else assignin('base','t_seq',0); assignin('base','y_seq',1);endx0s=get(handles.hEdtConPars,'String'); y0=1e10; yy=1e5;if length(x0s)==0, x0=rand(n,1); else, x0=eval(x0s); endxa=get(handles.hEdtConLow,'String'); kLBounds=0;if length(xa)==0, if kTool==3, xm=0.01*X1; else, xm=-inf*X1; endelse, xm=eval(xa); kLBounds=1; if prod(size(xm))==1, xm=xm*X1; end endxa=get(handles.hEdtConUp,'String');if length(xa)==0, if kTool==3, xM=10*X1; else, xM=inf*X1; endelse, xM=eval(xa); kLBounds=1; if prod(size(xM))==1, xM=xM*X1; end endx0=[x0(:); rand(2,1)]; x0=x0(1:n);switch kTool case 1 tol=eval(get(handles.edtTol,'String')); while abs(y0-yy)>tol, y0=yy; if kLBounds==0

40

Page 41: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

eval(['[x0,yy]=fminsearch(@',str,',x0,options)']) else eval(['[x0,yy]=fmincon(@',str,',x0,[],[],[],[],xm,xM,[],options)']) end set(handles.hTxtCrit,'String',num2str(yy)); if get(handles.chkLoop,'Value')==0, break; end end case 2 if kLBounds==0 eval(['[x0,yy]=ga(@' str ',n)']); else eval(['[x0,yy]=ga(@' str ',n,[],[],[],[],xm,xM)']); end eval([str '(x0)']) case 3 if kLBounds==0, xm=-xM; end x0=gaopt([xm xM],str), eval([str '(x0(1:end-1))']), yy=-x0(end); case 4 if kLBounds==0 eval(['x0=pso_Trelea_vectorized(''' str ''',n)']); else eval(['x0=pso_Trelea_vectorized(''' str ''',n,4,[xm xM])']); end eval(['yy=' str '(x0)']) case 5 if kLBounds==0 eval(['[x0,yy]=simulannealbnd(@',str,',x0)']) else eval(['[x0,yy]=simulannealbnd(@',str,',x0,[xm xM])']) end eval([str '(x0)']) case 6 if kLBounds==0 eval(['[x0,yy]=patternsearch(@',str,',x0)']) else eval(['[x0,yy]=patternsearch(@',str,',x0,[],[],[],[],[xm xM])']) end eval([str '(x0)'])endset(handles.hEdtConPars,'String',['[' num2str(x0(:).') ']']);set(handles.hTxtCrit,'String',num2str(yy));pause(0.0001); delete(ff); function hBtnRefresh_Callback(hObject, eventdata, handles)set(handles.hEdtConPars,'String','');

41

Page 42: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

for i=0:1000 try str=['optpidfun_' int2str(i)]; if exist(str)==2, delete([str '.m']); end catch errordlg({'Error deleting files ';lasterr},'Error'); endend function hBtnSimulation_Callback(hObject, eventdata, handles)try t_seq=eval(get(handles.hEdtTSeq,'String')); y_seq=eval(get(handles.hEdtYSeq,'String')); t_end=eval(get(handles.hEdtEnd,'String'))catch errordlg('Syntax errors in the multi-stairs vectors','Error...')endif length(t_seq)~=length(y_seq) errordlg('Lengths mismatch in the multi-stairs vectors','Error...')endassignin('base','t_seq',t_seq);assignin('base','y_seq',y_seq);set_param('pidctrl_model/Scope','Open','on');[tt,xx,yy]=sim('pidctrl_model',[0,t_end]);set(handles.hTxtCrit,'String',num2str(yy(end,1))) function hEdtLower_Callback(hObject, eventdata, handles)set_saturation(handles) function hEdtUpper_Callback(hObject, eventdata, handles)set_saturation(handles) function hRadioCon_Callback(hObject, eventdata, handles)set(handles.hRadioDis,'Value',0)set(handles.hRadioCon,'Value',1)set([handles.hTxtSamp,handles.hEdtSamp],'Visible','off');set_param('pidctrl_model/PID Controller','TimeDomain','Continuous-time'); function hRadioDis_Callback(hObject, eventdata, handles)set(handles.hRadioCon,'Value',0)set(handles.hRadioDis,'Value',1)set([handles.hTxtSamp,handles.hEdtSamp],'Visible','on');T=get(handles.hEdtSamp,'String');set_param('pidctrl_model/PID Controller','TimeDomain','Discrete-time');set_param('pidctrl_model/PID Controller','SampleTime',T);

42

Page 43: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

function hEdtSamp_Callback(hObject, eventdata, handles)set_param('pidctrl_model/PID Controller','SampleTime',get(handles.hEdtSamp,'String')); function hBtnInfty_Callback(hObject, eventdata, handles)set(handles.hEdtUpper,'String','inf');set_saturation(handles) function hBtnNInfty_Callback(hObject, eventdata, handles)set(handles.hEdtLower,'String','-inf');set_saturation(handles) function hBtnCreate_Callback(hObject, eventdata, handles)k=0;while 1 str=['optpidfun_' int2str(k)]; if ~any([2 3 5 6]==exist(str)), break; end k=k+1;endtry fid=fopen([str,'.m'],'w'); kTool=get(handles.hLstAlgorithm,'Value'); if kTool==3 % if GAOT is used, rewrite the objective function fprintf(fid,'function [x,y]=%s(x,opts)\r\n',str); else fprintf(fid,'function y=%s(x)\r\n',str); end t_end=eval(get(handles.hEdtTerm,'String')); fprintf(fid,'%% %s An objective function for optimal PID controller tuning\r\n',upper(str)); fprintf(fid,'%% It describes the relationship between the PID controller parameters\r\n'); fprintf(fid,'%% and the chosen performance index.\r\n\r\n'); fprintf(fid,'%% The function is automatically created by PID Controller Optimizer.\r\n'); fprintf(fid,'%% Date of creation %s\r\n',date); strP=['Kp';'Ki';'Kd']; fprintf(fid,'opt=simset(''OutputVariables'',''y'');\r\n'); switch get(handles.hLstPIDType,'Value') case 1, vv=1; n=1; case {2,6}, vv=[1,2]; n=2; case 3, vv=[1,3]; n=2; case {4,7}, vv=[1,2,3]; n=3; case 5, vv=[2]; n=1; end set(handles.hLstPIDType,'UserData',n); ss='';

43

Page 44: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

if kTool==4 fprintf(fid,'for i=1:size(x,1)\r\n'); ss=' '; end for i=1: length(vv) if kTool==4 fprintf(fid,' assignin(''base'',''%s'',x(i,%d));\r\n',strP(vv(i),:), i); else fprintf(fid,'assignin(''base'',''%s'',x(%d));\r\n',strP(vv(i),:), i); end end fprintf(fid,[ss,'try\r\n']); fprintf(fid,[ss,' [~,~,y_out]=sim(''pidctrl_model'',[0,%f],opt);\r\n'],t_end); fprintf(fid,[ss,'catch, y_out=1e10; end\r\n']); switch kTool case {1,2,5,6}, fprintf(fid,'y=y_out(end,1);\r\n'); if get(handles.chkOvershoot,'Value')==1 ss=eval(get(handles.edtOvershoot,'String'))*0.01+1; fprintf(fid,'if any(y_out(:,2)>%5.2f*y_out(:,4)), ',ss) fprintf(fid,'y=1.5*y; end\r\n') end case 3, fprintf(fid,'y=-y_out(end,1);\r\n'); case 4, fprintf(fid,' y(i,1)=y_out(end,1);\r\n'); fprintf(fid,'end\r\n'); end fclose(fid); set(handles.hBtnCreate,'UserData',str); edit(str); figure(handles.hMainPID)catch errordlg('The current working folder is read-only, try another one','Error...')end function hBtnHelp_Callback(hObject, eventdata, handles)web(['file:' which('pid_optimizer.htm')]) function hBtnExit_Callback(hObject, eventdata, handles)close_system('pidctrl_model',0); delete(gcf) function hMainPID_CloseRequestFcn(hObject, eventdata, handles)close_system('pidctrl_model',0); delete(gcf) function hLstPIDType_Callback(hObject, eventdata, handles)

44

Page 45: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

key=get(handles.hLstPIDType,'Value'); contype={'P','PI','PD','PID','I','PI','PID'};set_param('pidctrl_model/PID Controller','Controller',contype{key});if key<=5 set_param('pidctrl_model/PID Controller','AntiWindupMode','none');else set_param('pidctrl_model/PID Controller','AntiWindupMode','clamping');end function set_saturation(handles)v1s=get(handles.hEdtLower,'String'); v1=isfinite(eval(v1s));v2s=get(handles.hEdtUpper,'String'); v2=isfinite(eval(v2s)); v1v2=v1|v2;set_param('pidctrl_model/PID Controller','LimitOutput',onoff(v1v2));set_param('pidctrl_model/PID Controller','UpperSaturationLimit',v2s)set_param('pidctrl_model/PID Controller','LowerSaturationLimit',v1s) function hLstAlgorithm_Callback(hObject, eventdata, handles)kAlgorithm=get(hObject,'Value'); key=0; str={'Global Optimization'; 'GAOT'; 'PSOt'};switch kAlgorithm case {2,5,6} if exist('ga')~=2, key=1; end case 3 if exist('gaopt')~=2, key=1; end case 4 if exist('pso_Trelea_vectorized')~=2, key=1; endendif key==1 set(hObject,'Value',1); errordlg({['Warning: The ' str{kAlgorithm-1} ' Toolbox is not available on your path.']; 'The default toolbox is selected instead.'},'Warning')end function hChkHold_Callback(hObject, eventdata, handles)set(handles.hEdtTerm,'String',get(handles.hEdtEnd,'String')) function hEdtYSeq_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

45

Page 46: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

endfunction hLstPIDType_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtTerm_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtTSeq_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtSamp_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hListCriterion_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hLstAlgorithm_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtUpper_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtLower_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtPlant_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtEnd_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

46

Page 47: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

set(hObject,'BackgroundColor','white');endfunction hEdtConLow_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtConUp_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction hEdtConPars_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction chkLoop_Callback(hObject, eventdata, handles)function edtTol_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction chkOvershoot_Callback(hObject, eventdata, handles)function edtOvershoot_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end function hEdtYSeq_Callback(hObject, eventdata, handles)evaluation_check(hObject, eventdata, handles) function hEdtTSeq_Callback(hObject, eventdata, handles)evaluation_check(hObject, eventdata, handles) function hEdtEnd_Callback(hObject, eventdata, handles)evaluation_check(hObject, eventdata, handles) function hEdtTerm_Callback(hObject, eventdata, handles)evaluation_check(hObject, eventdata, handles) function hEdtConLow_Callback(hObject, eventdata, handles)evaluation_check(hObject, eventdata, handles) function hEdtConUp_Callback(hObject, eventdata, handles)evaluation_check(hObject, eventdata, handles) function hEdtConPars_Callback(hObject, eventdata, handles)

47

Page 48: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

evaluation_check(hObject, eventdata, handles) function edtOvershoot_Callback(hObject, eventdata, handles)evaluation_check(hObject, eventdata, handles) function edtTol_Callback(hObject, eventdata, handles)evaluation_check(hObject, eventdata, handles) function evaluation_check(hObject, eventdata, handles)try vs=get(hObject,'String'); if length(vs)>0, v=eval(vs); endcatch errordlg('Error in the Edit Box, try again','Error...')endfunction str=onoff(val)if val==0, str='off'; else, str='on'; end

48

Page 49: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Appendix B

Conventional_PID.m

% This Matlab code simulates a PID controller for a fisrt order time delay system % G(s) = (K*e(-theta*s))/(T*s+1) % Derick Suranga Widanalage% Graduate Student% Faculty of Engineering and Applied Sciences% Memorial University of Newfoundland% St John's, NL, A1B3X5% Canada clear all; clc; T=567; K=7.91; theta= 63; % System Parametersrefe = 40; % Reference to followTf = 2000; % Simulation timeyold = 0;yold1=0;yp = []; ys_prime = [];er = refe; % Error (Initial error = Reference) er1 = 0; % First derivative of errorer2 = 0; % Second derivative of erroreold = refe; eold2 = 0;dt = 1;for i=1:dt:Tf dtspan = [i i+dt]; eold2 = eold ; eold = er; er = refe - yold; er2 = er + eold2 - 2*eold; er1 = er - eold; init_con = [yold ; (yold-yold1)]; % Initial conditions for the diffirential equations options = []; [t,y] = ode45(@pid_ctrl,dtspan,init_con,options,er,er1,er2); yold1 = yold; ys = y(length(y),1); if i <= theta ys_prime = [0 ys_prime]; else ys_prime = [ys ys_prime]; end

49

Page 50: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

yold = ys_prime(1); yp = [yp yold];end plot(yp);xlabel('Time');ylabel('Output');title('Output of the system with PID Controller');grid on;

50

Page 51: Identification and Optimization of Pi Parameters Based on Genetic Algorithm for Non Linear System Using Matlab

Appendix C

Conventional_PID_call .m

function yprime = pid_ctrl(t,y,er,er1,er2) T=567; K=7.91; % System parametrsKp = 1.095; Ki = 0.005; Kd = 0; % PID Controller parametrs yprime = [y(2); ((1/T)*(-y(2)+ K*Kd*er2 + K*Kp*er1 + K*Ki*er))];

51