0% found this document useful (0 votes)
172 views

Tuning of Fuzzy Logic Controller Using Genetic Algorithm

This document discusses tuning a fuzzy logic controller for a DC motor using genetic algorithms. It begins with an abstract that outlines using a genetic algorithm to tune the parameters of a fuzzy logic controller designed for speed control of a DC motor. It then provides background on genetic algorithms and fuzzy logic controllers before describing the materials and methods used, including modeling the system with a PID controller, designing a fuzzy logic controller with error and change in error as inputs and control voltage as the output, and defining the fuzzy rules and inference mechanism.

Uploaded by

Awadalla Taifour
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
172 views

Tuning of Fuzzy Logic Controller Using Genetic Algorithm

This document discusses tuning a fuzzy logic controller for a DC motor using genetic algorithms. It begins with an abstract that outlines using a genetic algorithm to tune the parameters of a fuzzy logic controller designed for speed control of a DC motor. It then provides background on genetic algorithms and fuzzy logic controllers before describing the materials and methods used, including modeling the system with a PID controller, designing a fuzzy logic controller with error and change in error as inputs and control voltage as the output, and defining the fuzzy rules and inference mechanism.

Uploaded by

Awadalla Taifour
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

TUNING OF FUZZY LOGIC CONTROLLER

USING GENETIC ALGORITHM

Mohammed Almurtada Elzein Ahmed 1, Dr. Awadalla Taifor Ali Ismail 2

ABSTRACT
This paper presents the speed control of dc motor using fuzzy logic controller (FLC)
based on Genetic algorithm. the fuzzy controller is tuned using Genetic Algorithm
(GA) technique in MATLAB environment. The controller is designed based on the
expert knowledge of the system. For the proposed Direct Current (DC) motor case,
there are nine fuzzy rules designed for Fuzzy Logic Controller (FLC). GA is the
search technique being applied in this research to determine the parameters of the
controller. The output response of the system is obtained by using three types of
controllers, namely, Proportional Integral Derivative (PID), FLC and FLC with GA.
The results showed the better performance achieved with GA.

Keywords: fuzzy logic controller, genetic algorithm, PID controller

INTRODUCTION
The life cycle of a control system demands several optimizations in
several steps. Probably the most demanding steps are those in the phases
of process modeling and controller design. Sometimes these
optimizations are very simple, based on experiences, tuning rules or
simulation trials. Sometimes better results are obtained by conventional
optimization techniques. This approach is extremely important for control
system with lower number loops and with called parametric controllers.
However more advanced control algorithms contain usually much more
parameters, which must be appropriately tuned. More complex control
algorithms result in better efficiency, when systems are complex,
nonlinear or time varying, multivariable, highly oscillating, with
significant delays etc. Conventional optimization algorithms are not able
to properly handle such problems, so there is a constant search for new
and better methods [1].

DESCRIPTION OF GENETIC ALGORITHM


Genetic algorithms are search algorithms that use operations found
in natural genetics to guide the trek through a search space. GAs use a
direct analogy of natural behaviour. They work with a population of
chromosomes, each one representing a possible solution to a given
problem. Each chromosome has assigned a fitness score according to how
good a solution to the problem it is. GAs are theoretically and empirically
proven to provide robust search in complex spaces, giving a valid
approach to problems requiring efficient and effective searching.
Any GA starts with a population of randomly generated solutions,
chromosomes, and advances toward better solutions by applying genetic
operators, modelled on the genetic processes occurring in nature. In these
algorithms to maintain a population of solutions for a given problem; this
population undergoes evolution in a form of natural selection. In each
generation, relatively good solutions reproduce to give offspring that
replace the relatively bad solutions which die. An evaluation or fitness
function plays the role of the environment to distinguish between good
and bad solutions. The process of going from the current population to
the next population constitutes one generation in the execution of a GA.
Although there are many possible variants of a simple GA, the
fundamental underlying mechanism operates on a population of
chromosomes and consists of three operations:
 Evaluation of individual fitness.
 Formation of a gene pool (intermediate population).
 Recombination and mutation.
The procedure of a simple GA shown in Figure 1. A fitness function
must be devised for each problem to be solved. Given a particular
chromosome, a solution, the fitness function returns a single numerical
fitness, which is supposed to be proportional to the utility or adaptation of
the individual which that chromosome represents.
There are a number of ways of making this selection. Population
may be viewed as mapping onto a roulette wheel, where each
chromosome is represented by a space that proportionally corresponds to
its fitness. By repeatedly spinning the roulette wheel, chromosomes are
chosen using "stochastic sampling with replacement" to fill the
intermediate population. The selection procedure proposed is called
stochastic universal sampling is one of the most efficient, where the
number of offspring of any structure is bound by the floor and ceiling of
the expected number of offspring. After selection has been carried out the
construction of the intermediate population is complete, then the genetic
operators, crossover and mutation, can occur [2].

begin (1)
t=0;
initialize P(t);
evaluate P(t);
While (NOT termination-condition) do
begin (2)
t=t+1
select P(t) from P(T-1)
recombine P(t)
evaluate P(t)
end (2)
end (1)
Figure 1: A procedure of simple GA

DESCRIPTION OF FUZZY LOGIC CONTROLLER


Fuzzy logic has rapidly become one of the most successful of
today's technologies for developing sophisticated control systems. Fuzzy
logic control technology has been widely and successfully utilized in
industrial applications. Fuzzy Logic is a multi-valued logic, that allows
intermediate values to be defined between conventional evaluations like
true/false, yes/no, high/low and emerged as a tool to deal with uncertain,
imprecise, or qualitative decision making problems. Fuzzy logic is a way
to make machines more intelligent to reason in a fuzzy manner like
humans.
A fuzzy logic model is a logical-mathematical procedure based on
an “IF-THEN” rule system that mimics the human way if thinking in
computational form. Generally, a fuzzy rule system has four modules as
shown in Figure 2.
 Fuzzification
 Fuzzy Inference
 Rule base
 Defuzzification
Figure 2: Structure of fuzzy logic controller

 Fuzzification
The process of converting a numerical variable (real number or crisp
variables) into a linguistic variable (fuzzy number) is called Fuzzification.
In others words, means the assigning of linguistic value, defined by
relative small number of membership functions to variable.
 Fuzzy Inference
Under inference, the truth value for the premise of each rule is computed,
and applied to the conclusion part of each rule. This results in one fuzzy
subset to be assigned to each output variable for each rule. Mostly MIN or
PRODUCT is used as inference rules. In MIN inference, the output
membership function is clipped off at a height corresponding to the rule
premise's computed degree of truth (fuzzy logic AND). In PRODUCT
inference, the output membership function is scaled by the rule premise's
computed degree of truth.
 Rule Base
For the rule bases a classic interpretation of Mamdani was used. Under
rule base, rules are constructed for outputs. The rules are in “If Then”
format and formally the If side is called the conditions and the Then side is
called the conclusion. 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.
 Defuzzification
Defuzzification is a process in which crisp output is obtained by the fuzzy
output. In other words, process of converting fuzzy output to crisp
number. There is more Defuzzification methods in which two of the more
common techniques are the CENTROID and MAXIMUM methods. In the
CENTROID method, the crisp value of the output variable is computed by
finding the variable value of the centre of gravity of the membership
function for the fuzzy value. In the MAXIMUM method, one of the
variable values at which the fuzzy subset has its maximum truth value is
chosen as crisp value for the output variable [3].

MATERIALS AND METHODS


PID Controller
The Simulink model of the PID controller is shown in Figure 3. The
difference between the desired speed and the output feedback is passed as
input into the PID controller subsystem. The PID Controller subsystem
(Figure 4) contains the proportional gain scaling factor (Kp), the derivative
gain scaling factor (Kd) and the integral gain scaling factor (Ki). The
derivative gain factor and the integral gain factor are both passed through
a derivative block and an integral block respectively before being summed
up with the proportional gain factor. The output of the PID controller
subsystem serves as an input to the DC motor block. The DC motor block
is simply the transfer function of the DC motor. The speed of the motor is
also monitored from the scope connected to the output of the DC motor
block. The desired speed of the motor is set to a unit constant value to
serve as a step response input to the system. The error signal of the system
is also monitored using a scope.
Figure 3: Simulink model of the PID controller

Figure 4: PID controller subsystem

The step response of the system where controller parameters are


adjusted using Ziegler—Nichols method shown below Figure 5.
Figure 5: Speed response of the system with PID controller

Fuzzy Logic Controller


First, set the error e(t) and the error variation de(t) of the angular
velocity to be the input variables of the fuzzy logic controller. The control
voltage u(t) is the output variable of the fuzzy logic controller.
The linguistic variables are defined as {L,M,H}, where L means low,
M means medium , H high. The fuzzy rules are summarized in Table 1.
The type of fuzzy inference engine is Mamdani. The fuzzy inference
mechanism in this study follows as shown in Figures (6-8).

Table 1: Fuzzy rules


e ec L M H
L L M M
M L M H
H M M H
Figure 6: Membership function editor for error

Figure 7: Membership function editor for change in error


Figure 8: Membership function editor for control

The Simulink model of the fuzzy controller is shown in Figure 9.

Figure 9: Fuzzy controller design

The system output response after considerable hand tuning of FLC


shown in Figure 10.
Figure 10: Speed response of the system with FLC

Fuzzy Controller With GA


The fuzzy controller for a motor speed is re-implemented but the
only difference this time is that is optimized. The GA is employed to
perform a comprehensive and complete search in finding an optimal
solution for scaling gains which minimizes the fitness function for the
specified fuzzy logic controller. A diagram of the simulink model that is
used is shown in Figure 11 The source code is given in Appendix A.

Figure 11: Fuzzy controller design with GA


Running the simulation process for the system the resulting
optimized scaling gains are listed:
 Proportional error input scale: 1.7795
 Error derivative input scale: 0.7702
 Integral gain :1.7204
 Output scale: 2.7708
The step response of the system as shown in Figure 12.

Figure 12: Speed response of the system with fuzzy controller using GA

The results obtained from different tuning method are shown in the
Table 2.
Table 2: Comparison of results
Title PID Controller FLC FLC
(Z-N Tuning) (Hand Tuning) (GA Tuning)
Rise Time (sec.) 0.0458 0.14 0.16
Settling Time (sec.) 0.21 0.6 0.25
Overshoot (%) 40.8 19 4.7
CONCLUSION
This study has succeeded in the design of an optimal fuzzy logic
controller using genetic algorithm technique. MATLAB/SIMULINK is
used to simulate and fine-tune the controller models. the proper optimized
gain values of controller are obtained with GA. By comparing the results
of the performance metrics in Table 2, it can be noted that the GA-
optimized fuzzy logic controller produces better more desirable
performance compared with other controllers. The simulation results
show that the optimal fuzzy logic controller is functioning better than
other in term of the overshoot.

REFERENCES
[1] Gregory K. McMillan, "Tuning and Control Loop Performance",
Momentum Press, 2014.
[2]Beasley D, Bull D and Martin R, "An Overview of Genetic
Algorithms", university computing, 1994.
[3] Jan Jantzen, ''Design of Fuzzy Controllers'', Technical University of
Denmark, 1998.

APPENDIX A: MATLAB SOURCE CODE


clc
clear all
close all
%% Now tune the FLC controller I/O scale factor
disp('Tuning the FLC')
LB = 0.01*ones(1,4); % Lower bound
UB = 1e2*ones(1,4); % Upper bound
X_min = LB;
X_max = UB;

[X,best_obj]=GA(X_min,X_max,@costs)
best_obj

disp(['The value of Kp is:' num2str(X(1))])


disp(['The value of Ki is:' num2str(X(2))])
disp(['The value of Kd is:' num2str(X(3))])
disp(['The value of Ku is:' num2str(X(4))])
assignin('base','Kp',X(1))
assignin('base','Ki',X(2))
assignin('base','Kd',X(3))
assignin('base','Ku',X(4))
sim('Fuzzy controller design with GA');

function [cost_value] = costs(x)

% Assign Kp, Ki, Kd and Ku


% Kp = x(1);
% Ki = x(2);
% Kd = x(3);
% Ku = x(4);
assignin('base','Kp',x(1))
assignin('base','Ki',x(2))
assignin('base','Kd',x(3))
assignin('base','Ku',x(4))
% Run Model
sim('Fuzzy controller design with GA');
err=reference-output;
[n,~]=size(err);
cost_value=0;
for i=1:n
% cost_value=cost_value+(err(i))^2 ; % ISE
% cost_value=cost_value+abs(err(i)); % IAE
cost_value=cost_value+t(i)*abs(err(i)); % ITAE
% cost_value=cost_value+t(i)*(err(i))^2; % ITSE
% cost_value=cost_value/t(n); % MSE
end
end

function [X_best , obj_optimal] = GA(X_min,X_max,CostFun)


Para_No=size(X_min,2);
costs = CostFun; % Cost function

%Algorithm Parameters
Ngmax=100; %Maximum number of generations
Tourn_Prob_f =0.8; %Tournament propability factor
Cro_Prob=0.7; %Crossover propability
alpha=0.5; %Crossover coefficient
Mut_Prob=0.01; %Mutation propability
b=2; %Mutation constant
N=200; %Number of solutions (Population size)

% t=1; %Generation counter


Nps = N/4 ; % Number of selected population

%***** Initialize population **** %


disp('->Initialize population')
old_pop=zeros(N,Para_No);
i=1;
h = waitbar(0,'Initializing population...');
while (i<=N)
waitbar(i/N,h)
for j=1:Para_No
old_pop(i,j) = X_min(j) + (X_max(j)-X_min(j))*rand;
end
i=i+1;
end
delete(h);
%***** Objective function evaluation ***** %
disp('->Calculating the cost function of the initial
population')
h = waitbar(0,'Cost function evaluation of the initial
population...');
fitness = zeros(N,1);
for i =1:size(old_pop,1)
waitbar(i/size(old_pop,1),h)
fitness(i) = costs(old_pop(i,:));
end
delete(h);
Jbest = min(fitness);
Best_index = find(Jbest==fitness);
Xbest = old_pop(Best_index(1),:);

%%%%%%%%%%%%%%%% The below section is repeated for different


generations %%%%%%%%%%%%%%%%%%%%%%%
obj_opt = zeros(Ngmax,1);
best_sol_gen = zeros(Ngmax,Para_No);

h = waitbar(0,'Please wait...');
for t=1:Ngmax
waitbar(t/Ngmax,h)
%Tournament selection
selected_parent_index =
Tourn_Select(N,fitness,Nps,Tourn_Prob_f);

%**** BLX-a Crossover ********%


child1= zeros(Nps,Para_No);
child2= zeros(Nps,Para_No);
i=1;
while i<=Nps
for j =1:Para_No
p1=old_pop(selected_parent_index(i,1),j);
p2=old_pop(selected_parent_index(i,2),j);
if rand <= Cro_Prob
cmax=max(p1,p2);
cmin=min(p1,p2);
I=cmax-cmin;
child1(i,j)=(cmin-I*alpha)+
(rand*((cmax+I*alpha)-(cmin-I*alpha)));
child2(i,j)=(cmin-I*alpha)+
(rand*((cmax+I*alpha)-(cmin-I*alpha)));

else
child1(i,j)=p1;
child2(i,j)=p2;
end
if (child1(i,j)>X_max(j))
child1(i,j)=X_max(j);
end
if (child2(i,j)<X_min(j))
child2(i,j)=X_min(j);
end
end

i = i+1;
end
children=[child1 ;child2];
%Non-Uniform Mutation
para_min=X_min; para_max=X_max;
childrenm = zeros(N/2,Para_No);
i = 1;
while (i<=N/2)
for j=1:Para_No
if rand <= Mut_Prob
deltap=(para_max(j)-children(i,j))*(1-rand^((1-(t-
1/Ngmax))^b));
deltan=(children(i,j)-para_min(j))*(1-rand^((1-(t-
1/Ngmax))^b));
if rand < 0.5
childrenm(i,j)=children(i,j)+deltap;
else
childrenm(i,j)=children(i,j)-deltan;
end
else
childrenm(i,j)=children(i,j);
end
if (childrenm(i,j)>para_max(j))
childrenm(i,j)=para_max(j);
end
if (childrenm(i,j)<para_min(j))
childrenm(i,j)=para_min(j);
end
end
i = i+1;
end
%combining parents with new children solutions to form the new
generation
parents=zeros(N/2,Para_No);
for i=1:N/2
parents(i,:)=old_pop(selected_parent_index(i),:);
end
new_pop=[parents;childrenm];
% Objective function evaluation
for i =1:size(new_pop,1)
fitness(i) = costs(new_pop(i,:));
end
Jmin = min(fitness);
Min_index = find(Jmin==fitness);
Xmi = new_pop(Min_index(1),:);
if (Jmin<=Jbest)
Jbest = Jmin;
Xbest = Xmi;
end
obj_opt(t)=Jbest;
%best_sol_index=find(fitness==obj_opt(t));
best_sol_gen(t,:)=Xbest;
old_pop=new_pop;
end
delete(h);
obj_optm = obj_opt;

obj_optimal=min(obj_optm);
op_sol_index=find(obj_optm==obj_optimal);
X_best=best_sol_gen(op_sol_index(1),:);

return

% This function is responsible for the tournament selection operation


it
% receives the following arguments:
% The number of solution (population) (N)
% The fitness value of each solution (fitness)
% The number of selected solution (Nps)
% The tournament selection probability (Tourn_Prob_f)
% Then it produces the selected parant index (Selected_Parent_index)

function Selected_Parent_index =
Tourn_Select(N,fitness,Nps,Tourn_Prob_f)
Selected_Parent_index=zeros(Nps,2);
for i=1:Nps
ti1=randi([1 N],1); %Random Tournament index 1
ti2=randi([1 N],1); %Random Tournament index 2
if rand <= Tourn_Prob_f
if fitness(ti1)<fitness(ti2)
pi1=ti1; %Parent index 1
else
pi1=ti2;
end
else
if fitness(ti1)<fitness(ti2)
pi1=ti2;
else
pi1=ti1;
end
end

ti1=randi([1 N],1); %Random Tournament index 1


ti2=randi([1 N],1); %Random Tournament index 2
if rand()<= Tourn_Prob_f
if fitness(ti1)<fitness(ti2)
pi2=ti1; %Parent index 2
else
pi2=ti2;
end
else
if fitness(ti1)<fitness(ti2)
pi2=ti2;
else
pi2=ti1;
end
end
Selected_Parent_index(i,:)=[pi1 pi2]; %Parent index vector
end
return
Fig.10

esnopseR petS
6.1

4.1

2.1

8.0
edutilpmA

6.0

4.0

2.0

0
0 1 2 3 4 5 6 7 8 9 01
)ces( emiT
Fig.12

You might also like