fuzzy pid control with type-凯发k8网页登录
this example compares a type-2 fuzzy pid controller with both a type-1 fuzzy pid controller and conventional pid controller. this example is adapted from [1].
fuzzy pid control
this example uses the following fuzzy logic controller (flc) structure as described in [1]. the output of the controller () is found using the error () and the derivative of the error (). using scaling factors and , inputs and are normalized to and , respectively. the normalized ranges for both inputs are in the range [-1,1]. the fuzzy logic controller also produces a normalized output in the range [-1,1]. additional scaling factors and map the fuzzy logic controller output into .
this example uses a delayed first-order system as the plant model.
here, , , and are the gain, time delay, and time constant, respectively.
the scaling factors , , and are defined as follows, where is the closed-loop time constant.
the input scaling factor is:
where and are the reference and system output values at time . these values correspond to the nominal operating point of the system.
this example compares the performance of type-1 and type-2 sugeno fuzzy inference systems (fiss) using the fuzzy logic controller simulink® block.
construct type-1 fis
create a type-1 fis using sugfis
.
fis1 = sugfis;
add input variables to the fis.
fis1 = addinput(fis1,[-1 1],'name','e'); fis1 = addinput(fis1,[-1 1],'name','dele');
add three uniformly distributed overlapping triangular membership functions (mfs) to each input. the mf names stand for negative (n
), zero (z
), and positive (p
).
fis1 = addmf(fis1,'e','trimf',[-2 -1 0],'name','n'); fis1 = addmf(fis1,'e','trimf',[-1 0 1],'name','z'); fis1 = addmf(fis1,'e','trimf',[0 1 2],'name','p'); fis1 = addmf(fis1,'dele','trimf',[-2 -1 0],'name','n'); fis1 = addmf(fis1,'dele','trimf',[-1 0 1],'name','z'); fis1 = addmf(fis1,'dele','trimf',[0 1 2],'name','p');
plot the input membership functions.
figure subplot(1,2,1) plotmf(fis1,'input',1) title('input 1') subplot(1,2,2) plotmf(fis1,'input',2) title('input 2')
add the output variable to the fis.
fis1 = addoutput(fis1,[-1 1],'name','u');
add uniformly distributed constant
functions to the output. the mf names stand for negative big (nb
), negative medium (nm
), zero (z
), positive medium (pm
), and positive big (pb
).
fis1 = addmf(fis1,'u','constant',-1,'name','nb'); fis1 = addmf(fis1,'u','constant',-0.5,'name','nm'); fis1 = addmf(fis1,'u','constant',0,'name','z'); fis1 = addmf(fis1,'u','constant',0.5,'name','pm'); fis1 = addmf(fis1,'u','constant',1,'name','pb');
add rules to the fis. these rules create a proportional control surface.
rules = [... "e==n & dele==n => u=nb"; ... "e==z & dele==n => u=nm"; ... "e==p & dele==n => u=z"; ... "e==n & dele==z => u=nm"; ... "e==z & dele==z => u=z"; ... "e==p & dele==z => u=pm"; ... "e==n & dele==p => u=z"; ... "e==z & dele==p => u=pm"; ... "e==p & dele==p => u=pb" ... ]; fis1 = addrule(fis1,rules);
plot the control surface.
figure
gensurf(fis1)
title('control surface of type-1 fis')
construct type-2 fis
convert the type-1 fis, fis1
, to a type-2 fis.
fis2 = converttotype2(fis1);
the type-2 sugeno system, fis2
, uses type-2 membership functions for the input variables and type-1 membership functions for the output variables.
define the footprint of uncertainty (fou) for the input mfs as defined in [1]. to do so, set the lower mf scaling factor for each mf. for this example, set the lower mf lag values to 0
.
scale = [0.2 0.9 0.2;0.3 0.9 0.3]; for i = 1:length(fis2.inputs) for j = 1:length(fis2.inputs(i).membershipfunctions) fis2.inputs(i).membershipfunctions(j).lowerlag = 0; fis2.inputs(i).membershipfunctions(j).lowerscale = scale(i,j); end end
plot the type-2 input membership functions.
figure subplot(1,2,1) plotmf(fis2,'input',1) title('input 1') subplot(1,2,2) plotmf(fis2,'input',2) title('input 2')
the fou adds additional uncertainty to the fis and produces a nonlinear control surface.
figure
gensurf(fis2)
title('control surface of type-2 fis')
conventional pid controller
this example compares the fuzzy logic controller performance with that of the following conventional pid controller.
here, is proportional gain, is integrator gain, is derivative gain, and is the derivative filter time constant.
configure simulation
define the nominal plant model.
c = 0.5;
l = 0.5;
t = 0.5;
g = tf(c,[t 1],'outputdelay',l);
generate the conventional pid controller parameters using pidtune
.
pidcontroller = pidtune(g,'pidf');
in this example, the reference ( is a step signal and , which results in as follows.
=1.
ce = 1;
to configure the simulation, use the following nominal controller parameters.
tauc = 0.2; cd = min(t,l/2)*ce; c0 = 1/(c*ce*(tauc l/2)); c1 = max(t,l/2)*c0;
to simulate the controllers, use the comparepidcontrollers
simulink model.
model = 'comparepidcontrollers';
load_system(model)
simulate nominal process
simulate the model at the nominal operating conditions.
out1 = sim(model);
plot the step response of the system for all three controllers.
plottitle = ['nominal: c=' num2str(c) ', l=' num2str(l) ', t=' num2str(t)]; plotoutput(out1,plottitle)
obtain the step-response characteristics of the system for each controller. here, rise time and settling time are in seconds, overshoot is a percentage of the final value, and the absolute error is integrated over the step response.
stepresponsetable(out1)
ans=3×4 table
rise time overshoot settling time absolute error
_________ _________ _____________ ______________
pid 0.62412 11.234 4.5583 1.04
type-1 flc 1.4267 0 4.1023 1.1522
type-2 flc 1.8662 0 5.129 1.282
for the nominal process:
both the type-1 and type-2 fuzzy logic controllers outperform the conventional pid controller in terms of overshoot.
the conventional pid controller, performs better with respect to rise-time and integral of absolute error (iae).
the type-1 flc performs better than the type-2 flc in terms of rise-time, settling-time, and iae.
simulate modified process
modify the plant model by increasing the gain, time delay, and time constant values as compared to the nominal process.
c = 0.85;
l = 0.6;
t = 0.6;
g = tf(c,[t 1],'outputdelay',l);
simulate the model using the updated plant parameters.
out2 = sim(model);
plot the step response of the system for all three controllers.
plottitle = ['modified 1: c=' num2str(c) ',l=' num2str(l) ',t=' num2str(t)]; plotoutput(out2,plottitle)
obtain the step-response characteristics of the system for each controller.
stepresponsetable(out2)
ans=3×4 table
rise time overshoot settling time absolute error
_________ _________ _____________ ______________
pid 0.38464 80.641 29.458 4.7486
type-1 flc 0.47262 24.877 4.6788 1.1137
type-2 flc 0.47262 22.787 3.4561 1.076
for this modified process:
the conventional pid controller exhibits significant overshoot, larger settling-time, and higher iae as compared to the fuzzy logic controllers
for all performance measures, the type-2 flc produces the same or superior performance compared to the type-1 flc.
conclusion
overall, the type-1 flc produces superior performance for the nominal plant as compared to the conventional pid controller. the type-2 flc shows more robust performance for the modified plant.
the robustness of the conventional pid controller can be improved using different methods, such as prediction or multiple pid controller configurations. on the other hand, the performance of a type-2 flc can be improved by using a different:
rule base
number of rules
fou
for example, you can create a type-2 flc that defines the fou using both the lower mf scaling factor and lower mf lag.
for fis2
, set the lower mf scale and lag values to 0.7
and 0.1
, respectively for all input membership functions.
for i = 1:length(fis2.inputs) for j = 1:length(fis2.inputs(i).membershipfunctions) fis2.inputs(i).membershipfunctions(j).lowerscale = 0.7; fis2.inputs(i).membershipfunctions(j).lowerlag = 0.1; end end
plot the updated membership functions.
figure subplot(1,2,1) plotmf(fis2,'input',1) title('input 1') subplot(1,2,2) plotmf(fis2,'input',2) title('input 2')
simulate the model using the nominal plant, and plot the step responses for the controllers.
c = 0.5; l = 0.5; t = 0.5; g = tf(c,[t 1],'outputdelay',l); out4 = sim(model); close_system(model,0) plottitle = ['nominal: c=' num2str(c) ', l=' num2str(l) ', t=' num2str(t)]; plotoutput(out4,plottitle)
obtain the step-response characteristics of the system for each controller.
stepresponsetable(out4)
ans=3×4 table
rise time overshoot settling time absolute error
_________ _________ _____________ ______________
pid 0.62412 11.234 4.5583 1.04
type-1 flc 1.4267 0 4.1023 1.1522
type-2 flc 1.2179 0 3.8746 1.1087
in this case, the updated fou of type-2 flc improves the rise-time of the step response.
however, the lower mf lag values also increase the overshoot in the case of the modified plant.
c = 0.85; l = 0.6; t = 0.6; g = tf(c,[t 1],'outputdelay',l); out5 = sim(model); plottitle = ['nominal: c=' num2str(c) ', l=' num2str(l) ', t=' num2str(t)]; plotoutput(out5,plottitle)
t = stepresponsetable(out5)
t=3×4 table
rise time overshoot settling time absolute error
_________ _________ _____________ ______________
pid 0.38464 80.641 29.458 4.7486
type-1 flc 0.47262 24.877 4.6788 1.1137
type-2 flc 0.47262 26.699 4.6812 1.1278
therefore, to obtain desired step response characteristics, you can vary the lower mf scale and lag values to find a suitable combination.
you can further improve the fuzzy logic controller outputs using a mamdani type fis since it also provides lower mf scale and lag parameters for output membership functions. however, a mamdani type-2 flc introduces additional computational delay due to the expensive type-reduction process.
references
[1] mendel, j. m., uncertain rule-based fuzzy systems: introduction and new directions, second edition, springer, 2017, pp. 229-234, 600-608.
local functions
function plotoutput(out,plottitle) figure plot([0 20],[1 1]) hold on plot(out.yout{1}.values) plot(out.yout{2}.values) plot(out.yout{3}.values) hold off grid minor xlabel('time (sec)') ylabel('output') title(plottitle) legend(["reference","pid","type-1 flc","type-2 flc"],'location',"best") end
function t = stepresponsetable(out) s = stepinfo(out.yout{1}.values.data,out.yout{1}.values.time); stepresponseinfo(1).risetime = s.risetime; stepresponseinfo(1).overshoot = s.overshoot; stepresponseinfo(1).settlingtime = s.settlingtime; stepresponseinfo(1).iae = out.yout{4}.values.data(end); s = stepinfo(out.yout{2}.values.data,out.yout{2}.values.time); stepresponseinfo(2).risetime = s.risetime; stepresponseinfo(2).overshoot = s.overshoot; stepresponseinfo(2).settlingtime = s.settlingtime; stepresponseinfo(2).iae = out.yout{5}.values.data(end); s = stepinfo(out.yout{3}.values.data,out.yout{3}.values.time); stepresponseinfo(3).risetime = s.risetime; stepresponseinfo(3).overshoot = s.overshoot; stepresponseinfo(3).settlingtime = s.settlingtime; stepresponseinfo(3).iae = out.yout{6}.values.data(end); t = struct2table(stepresponseinfo,"rownames",["pid" "type-1 flc" "type-2 flc"]); t.properties.variablenames{1} = 'rise time'; t.properties.variablenames{2} = t.properties.variablenames{2}; t.properties.variablenames{3} = 'settling time'; t.properties.variablenames{4} = 'absolute error'; end
see also
|