Fuzzy Logic and Control

Download Report

Transcript Fuzzy Logic and Control

Fuzzy Logic Control
Feedback Control System
Plant, u, y
Controller, e, u
Reference input, r
Sensor
Classical Controller Design
• Given mathematical model of plant (i.e.
transfer function)
• Given objectives of Feedback Control
System
• Use standard design techniques to
determine controller to meet objectives
(root locus, ITAE, Bode, etc.)
Fuzzy Logic Controllers
• Use Experienced operators
• Construct IF-THEN rules that describe how
the operator uses his knowledge of the
objectives and the measured outputs to
determine inputs to the plant
• Convert the IF-THEN rules into
mathematics (i.e. convert human knowledge
into computer knowledge)
Elements of FL Controller
• Fuzzifier
– Takes measurement data (crisp numbers)
produces fuzzy sets (singleton fuzzifier,
membership functions)
• Rule Base or Knowledge Base
– IF-THEN rules from expert operator
• Inference engine
– Choice of AND, OR, NOT. Determines how to
interpret (implement) IF-THEN statements
• De-fuzzifier
– Produces single crisp output to be sent to plant
IF-THEN rules and Math
• IF antecedent THEN conclusion
– Logical IF-THEN statement
• IF condition THEN action
– Programming IF-THEN statement
• Programming IF-THEN in FL
– To the extent that the condition is true, implement the
action (part of inference engine)
• Collection of rules = Rule Base = Knowledge Base
• Multiple rules are joined by inference engine and
de-fuzzifier
FL implementation of functions
• Any mathematical function can be interpreted as IFTHEN statements
• Crisp logic interpretation of y = x2
–
–
–
–
IF x = 1 THEN y = 1
IF x = 2 THEN y = 4
Etc
One rule active at a time
• FL interpretation of y = x2
–
–
–
–
IF x is close to 1 THEN y is close to 1
IF x is close to 2 THEN y is close to 4
Etc
Many rules active at once. How to blend all active rules?
FL implementation of functions
• FL interpretation of y = x2
– IF x is close to 1 THEN y is close to 1
– IF x is close to 2 THEN y is close to 4
– Many rules active at once. How to blend all active rules?
•
•
•
•
Consider a number between x=1 and x=2.
The extent to which a number, x, is close to 1 is 1 ( x)
2 ( x)
The extent to which a number, x, is close to 2 is
The actions of the two rules needs to be blended together to
get the value of the function for numbers other than 1 and 2
1 ( x) *1  2 ( x) * 2
y
1 ( x)  2 ( x)
Single
Antecedent
Formula
• Consider N fuzzy rules
– IF x is in A1 THEN y is y1
• more similar rules
– IF x is in AN THEN y is yn
• The extent to which x is in Ak is measured by the kth
membership function
• The rules are blended together by
N
y

k 1
N
k

k 1
( x ) yk
k
( x)
Examples/Assignments
•
•
•
•
FL version of y = x2, y = 3x/(x+1)
FL version of y = sin(x), y = cos(x), y = tan(x)
FL version of (you pick a function)
FL version of {(x,y)}  experimental data
(thermocouple data)
• Proportional controller with saturation
• Choices
– Membership functions
Compound Antecedents
• Choose implementation of AND
– Min or * or etc
• IF x1 is A1,k AND x2 is A2,k THEN y is yk
• Two input linguistic variables
• Each LV has its term set
Compound Antecedent formula
Interpret x as a vector with components
N
y
  ( x) y
k 1
N
k
N
k
  ( x)


k
k 1
y
k 1
N
N
k
( x ) yk

k 1

k 1
N

k 1
N
k
( x)

1, k
( x1 )2,k ( x2 ) yk
1, k
( x1 ) 2,k ( x2 )
M
 
k 1 q 1
N M
q ,k
 
k 1 q 1
( xq ) yk
q ,k
( xq )
Examples/Assignments
•
•
•
•
•
•
Heat index formula
Chill factor index formula
PI controller
PD controller
PID controller
You choose a function
More complex consequents
•
•
•
•
Constant consequents
Linear consequents
Quadratic consequents
Generic function consequents
Re-Discussion of FL controller
components
• Fuzzy logic controllers convert an expert’s
collection of IF-THEN rules into a
mathematical function that operates similar
to the expert
• Fuzzifier
• Rule Base
• Inference Engine
• Defuzzifier
Coding Rules in an Array
• Each row in array is a rule
• First N columns
– N LV input variables
– Entries determine term in term set of LV, hence
membership function
• Last few columns
– Determine consequent
• Programming in Sysquake/Matlab
– Persistent variables
Examples/Assignments
• Code the FL functions using arrays
– Array
– Super Membership function for each LV
• Membership function for each term
– Function
• Sum
• Prod
• Random assignment of functions to students
Sysquake Code
function y = muz(x,left,right)
i=find(x<left); y=ones(size(i));
x = x(length(i)+1:length(x));
i=find(x<right); y =[y (right-x(i))/(right-left)];
x = x(length(i)+1:length(x));
y = [y zeros(size(x))];
return;
function y = mus(x,left,right)
i=find(x<left); y=zeros(size(i));
x = x(length(i)+1:length(x));
i=find(x<right); y =[y (x(i)-left)/(right-left)];
x = x(length(i)+1:length(x));
y = [y ones(size(x))];
Return;
function y = mutri(x,left,center,right)
i=find(x<left);
y=zeros(size(i));
x = x(length(i)+1:length(x));
i=find(x<center);
y =[y (x(i)-left)/(center-left)];
x = x(length(i)+1:length(x));
i=find(x<right);
y =[y (right-x(i))/(right-center)];
x=x(length(i)+1:length(x));
y = [y zeros(size(x))];
Return;
function y = mu(LV,T,x) // change LV to name of LV
temp = 1; humidity= 2; //For each LV, something like:
If (LV == temp)
N = 1; Z = 2; P = 3 //term set with 3 terms
left1 = -1; right1 = 0; // term N
left2 = -1 ; center2 = 0; right2 = 1; //term Z
left3 = 0; right3 = 1; //term P
if (T==N) y = muz(x,left1,right1);//muN
if (T==Z) y = mutri(x,left2,center2,right2);//muZ
if (T==P) y = mus(x,left3,right3);//muP
end
//For 2nd LV (similar to first)
if (LV==humidity)
end
return;
function y = fuzzyfn(x)
Rules
as
Arrays
N1 = 1; Z1 = 2; P1 = 3; // term set for LV 1
N2 = 1; Z2 = 2; P2 = 3; // term set for LV 2
nLV = 2; // number of linguistic variables
A = [N1
N2
10
// rule 1
N1
Z2
6
// rule 2
N1
P2
3]; // rule 3
// more rules
num = 0; den = 0
for i = 1:length(A(:,1)); mu = 1;
for LV = 1:nLV; mu=mu*mu(LV,A(i,LV),x(LV));
end
num = num+mu*A(i,nLV+1); sum = sum+mu; //sum =1?
end
y = num/sum; // not needed if sum =1
return
Assignment
• Add rules
• Modify to accommodate linear consequents
P Controller
• u = KPe
• Rules like
– If e = ek then u = uk
D controller
• u =KD (d/dt)e
e(t  t )  e(t ) e
e(t ) 

t
t
• Rules like
– If du = duk Then u = uk
I Controller
 t
u (t )  K I
 t
  tm
0
0
 e( )d   
 e( )d
0
 t tm t
e( )d 


e( )d  I (tm )  e(tm )t
 tm
If I = Ik then u = uk
or
If e = ek then u = u+uk (or du=duk)
PID Controller