How can I utilize the Mamdani fuzzy controller to get better quality of step response for 2nd-order system?

조회 수: 7 (최근 30일)
I want to design a Mamdani fuzzy controller to track step signal.How can I get better quality?
And how can I clear these warnings if I don't use prefilter 1.5/(s+1.5)?

채택된 답변

Sam Chak
Sam Chak 2025년 4월 6일
First, we examine the open-loop plant transfer function, . It is a 2nd-order system with an integrator and thus, the closed-loop system is guaranteed to achieve zero steady-state error.
%% Plant transfer function
Gp = tf(1, [0.2, 1, 0])
Gp = 1 ----------- 0.2 s^2 + s Continuous-time transfer function.
This indicates that we do not need integral action in the PID controller. In fact, the plant can be rearranged by multiplying both the numerator and denominator by 5.
%% Rearrange the plant to become
Gp = minreal(Gp)
Gp = 5 --------- s^2 + 5 s Continuous-time transfer function.
When it is compared with the standard transfer function of a damped harmonic oscillator,
the velocity component () is considered adequately damped, as the damping coefficient 5 is neither too high nor too low. Consequently, we can also omit the derivative action from the PID design for the time being. However, the squared natural frequency term () is missing from the plant . Therefore, the PID design task is reduced to determining the proportional gain, , which is related to .
If no overshoot in the step response is desired, the damping ratio is set to , and the desired natural frequency of the closed-loop system can be determined as, rad/s. The proportional gain does not equal the squared natural frequency term but is scaled by the input gain (see the numerator of ), such that . Since , the proportional gain that ensures a critically damped response is calculated as .
Now, let's evaluate the performance of the closed-loop system.
%% Closed-loop system
Kp = 1.25;
Gcl = feedback(Kp*Gp, 1)
Gcl = 6.25 ---------------- s^2 + 5 s + 6.25 Continuous-time transfer function.
S1 = stepinfo(Gcl);
disp('The Settling Time is: '); disp(S1.SettlingTime)
The Settling Time is: 2.3336
disp('The Max Overshoot is: '); disp(S1.Overshoot)
The Max Overshoot is: 0
The information returned by the stepinfo() command indicates that the settling time is 2.3336 seconds with 0% overshoot. Increasing the gain will not only shorten the settling time but also increase the percent overshoot, making the response more ocillatory, while decreasing the gain will lengthen the settling time, but sluggish response. Since the main control objectives are to achieve zero steady-state error and a settling time of 2 seconds with 0% overshoot, it is unacceptable to lower below 1.25. Thus, in the fuzzy gain scheduling design, will be set as the lower bound.
Before we proceed with the fuzzy gain scheduling design, let us transform the plant transfer function into a state-space model for the purpose of simulating the fuzzy control system using the ode45 solver later. This step is not required in Simulink.
%% Transform the plant transfer function into a state-space model
sys = compreal(Gp);
A = sys.A' % state matrix
A = 2×2
0 1 0 -5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = sys.C' % input matrix
B = 2×1
0 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
C = sys.B' % output matrix (unused, but to show that the plant output, y = x1)
C = 1×2
1 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
A Mamdani FIS is designed below, with one input (error signal) and one output (proportional gain value). Triangular MFs and two linear shoulder MFs (left and right) are used for the fuzzy input, while two singleton MFs are selected to represent the magnitudes of the proportional gain in the fuzzy output. For the sake of simplicity in design, there are only two designer choices. It is important to ensure that each input MF overlaps with adjacent MFs, such that the sum of the membership values for any particular input instance equals 1.
The overlap is determined by the triangle's corner parameter (crn), which is the first designer choice. For symmetric equidistance, the corner parameter is chosen as crn = 0.5. For the singleton outputs, one is set for the lower bound of ​, while the other must be determined for the upper bound of as this constitutes the second designer choice. There are three fuzzy rules, and they must be strictly followed because these rules influence the shape of the fuzzy gain scheduler.
Plotting the fuzzy output will depict a cone-shaped ​ gain scheduler. Why does it resemble a cone? This is because when the error signal approaches zero, the ​ gain value should increase a little in order to meet the settling time requirement. It is essential (and is up to you) to determine the optimal value to be set for the upper bound of ​.
%% Fuzzy Controller
fis = mamfis; % 100% Mamdani type
% Fuzzy Input
crn = 0.5; % Triangle's corner x-coordinate, (1st Designer Choice)
fis = addInput(fis, [-1.5 +1.5], 'Name', 'Err');
fis = addMF(fis, 'Err', 'linzmf', [-crn 0.0 ], 'Name', 'N');
fis = addMF(fis, 'Err', 'trimf', [-crn 0.0 crn], 'Name', 'Z');
fis = addMF(fis, 'Err', 'linsmf', [ 0.0 crn], 'Name', 'P');
% Fuzzy Output
lb = 1.25; % lower bound (((1/0.2)/2)^2)/5
ub = 1.63; % upper bound (2nd Designer Choice)
fis = addOutput(fis, [lb ub], 'Name', 'Kp');
fis = addMF(fis, 'Kp', 'trimf', [lb lb lb], 'Name', 'L');
fis = addMF(fis, 'Kp', 'trimf', [ub ub ub], 'Name', 'H');
% Fuzzy Rules
rules = [
"Err==N => Kp=L" % If Error is Negative, then Kp gain is Low.
"Err==Z => Kp=H" % If Error is Zero, then Kp gain is High.
"Err==P => Kp=L" % If Error is Positive, then Kp gain is Low.
];
fis = addRule(fis, rules);
figure % Fig. 1
numpts = 3001;
tL1 = tiledlayout(2, 1, 'TileSpacing', 'Compact');
nexttile
plotmf(fis, 'input', 1, numpts), grid on,
title('Input fuzzy sets')
nexttile
plotmf(fis, 'output', 1, numpts), grid on, xlim([1.1, 1.8])
title('Output fuzzy sets')
figure % Fig. 2
opt = gensurfOptions('NumGridPoints', numpts);
gensurf(fis, opt); ylim([1.2, 1.7])
title('Mamdani Fuzzy Kp gain scheduler')
The remainder of the work involves running the simulation. I demonstrate this in MATLAB using the ode45 solver, while you should implement the fuzzy controller in Simulink. Although I did not optimize the design parameters, my selections yield a settling time of 2.0047 seconds with a maximum percent overshoot of 0.1005%. Such a brief duration (0.0047 seconds) and the negligible overshoot are subtle and imperceptible to humans in practice.
% Fuzzy Control System
function dx = ode(t, x, A, B, fis)
ref = 1; % Reference setpoint
err = x(1,:) - ref; % Error signal
FKp = evalfis(fis, err); % Fuzzy Kp gain scheduler
u = - FKp.*err; % Proportional action
dx = A*x + B*u; % State-space of the plant
end
% Call ode45 solver and plot the result
[t, x] = ode45(@(t, x) ode(t, x, A, B, fis), [0 5], [0; 0]);
figure % Fig. 3
plot(t, x(:,1)), grid on, grid minor
xlabel('Time / s'), ylabel('x(t)'), title('Step response')
% Check the performances
y = x(:,1);
yfinal = y(end);
S = stepinfo(y, t, yfinal);
disp('The Settling Time is: '); disp(S.SettlingTime)
The Settling Time is: 2.0047
disp('The Max Overshoot is: '); disp(S.Overshoot)
The Max Overshoot is: 0.1005

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fuzzy Logic Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by