How can i calculate the PI controller gains from my plant transfer function
172 views (last 30 days)
Show older comments
Mads Olesen
on 1 Dec 2022
Commented: Siddharth Jawahar
on 22 Nov 2024 at 21:21
I am doing a project where I am using a synchronous bidirectional buck-boost converter too handle to powerflow between a battery and a dc bus. I have spend some time figuring out and understanding how to find the transfer function of my converter with state space modelling and have think I finally understand the whole process. My next step is to use that transfer function to calculate some gain values for the PI controller which i want to control converter with.
I have found my transfer function with state space modelling by following the example in a guide from texas instruments Guide (at the bottom of the guide they have attached a matlab script to copy in order to get the transfer function yourself). I have some other values for the components than texas, but taking initiative in the result from the guide is a good start, I think.
I think my biggest problem is that i don't know where to start. I know these definitions for PI controller, but I just can't see how it is connected.
omegaK = 1/ti
Gs = Kp *(1+1/ti) (PI controller)
Sorry for maybe not being too specific, I am not the strongest in control theory and really hope someone have time to give me an answer or show how to do it.
Best regards Mads
clear all;
clc;
s = tf('s');
% Values below is from an example made by texas instruments
% Input Voltage
Vp= 200;
% Input resistance
Rp=2.75*10^-3*200;
% Input capacitance
ci=1*10^-3;
% Input capacitance ESR
Rci=74*10^-3;
% DCR of the inductor
Rl=9.6*10^-3;
% Inductance
l=130*10^-6;
% Output Capacitance
co=15*10^-3;
% Output Capacitance ESR
Rco=5*10^-3;
% Output Load
Io=80;
% Duty cycle
D=0.5;
% The matrice for solving of inductor current transfer function
C = [0 0 1];
Dm = 0;
% state vector expressions
iL=Io/(1-D);
vci=Vp-Io*Rp/(1-D);
vco=(Vp/(1-D))-((Io*(Rp+Rl+D*(1-D)*Rco))/(1-D)^2);
% determining the state and input matrices for the converter in ON and OFF
A1 = [0 0 0; 0 -1/(ci*(Rp+Rci)) -Rp/(ci*(Rp+Rci)); 0 Rp/(l*(Rp+Rci)) (-(Rl*Rp+Rl*Rci+Rci*Rp))/(l*(Rp+Rci))];
B1 = [-1/co 0; 0 1/(ci*(Rp+Rci)); 0 Rci/(l*(Rp+Rci))];
A2 = [0 0 1/co; 0 -1/(ci*(Rp+Rci)) -Rp/(ci*(Rp+Rci)); -1/l Rp/(l*(Rp+Rci)) (-(Rl*Rp+Rl*Rci+Rci*Rp+Rp*Rco+Rco*Rci))/(l*(Rp+Rci))];
B2 = [-1/co 0; 0 1/(ci*(Rp+Rci)); Rco/l Rci/(l*(Rp+Rci))];
% Determining the state and input vectors
X = [vco; vci; iL];
U = [Io; Vp];
A_avg = A1*D+A2*(1-D);
B_avg = B1*D+B2*(1-D);
% Finding the transfer function
% (sI-A)
SIminusA = s*eye(3)-A_avg;
% (sI-A)^-1
inv_SIminusA = inv(SIminusA);
% (A1-A2)X+(B1-B2)U
A1minusA2XPlusB1minusB2U = (A1-A2)*X+(B1-B2)*U;
% Inductor current to duty cycle Trasnfer Function
% C*((sI-A)^-1*((A1-A2)X+(B1-B2)U))
y_IL = C*(inv_SIminusA*A1minusA2XPlusB1minusB2U)% Bodeplot af TF
% minreal cancelling poles and zeros
y_IL1 = minreal(y_IL)
% pole-zero-gain model
zpk(y_IL1)
% Display poles
pole(y_IL1)
% Display zeros
zero(y_IL1)
% Bodeplot af TF
figure;
hold on;
%bode(y_ILtexas);
bode(y_IL1)
grid on;
title('Bidirectional Buck-Boost converter transfer functions');
legend('TF');onal Buck-Boost converter transfer functions');
legend('TF');
0 Comments
Accepted Answer
Sam Chak
on 1 Dec 2022
Hi @Mads Olesen
Perhaps you can directly insert the PI controller and obtain the closed-loop response. Tune the gains if not good enough.
s = tf('s');
% Values below is from an example made by texas instruments
% Input Voltage
Vp = 200;
% Input resistance
Rp = 2.75*10^-3*200;
% Input capacitance
ci = 1*10^-3;
% Input capacitance ESR
Rci = 74*10^-3;
% DCR of the inductor
Rl = 9.6*10^-3;
% Inductance
l = 130*10^-6;
% Output Capacitance
co = 15*10^-3;
% Output Capacitance ESR
Rco = 5*10^-3;
% Output Load
Io = 80;
% Duty cycle
D = 0.5;
% The matrice for solving of inductor current transfer function
C = [0 0 1];
Dm = 0;
% state vector expressions
iL = Io/(1 - D);
vci = Vp - Io*Rp/(1 - D);
vco = (Vp/(1-D)) - ((Io*(Rp + Rl + D*(1 - D)*Rco))/(1 - D)^2);
% determining the state and input matrices for the converter in ON and OFF
A1 = [0 0 0; 0 -1/(ci*(Rp+Rci)) -Rp/(ci*(Rp+Rci)); 0 Rp/(l*(Rp+Rci)) (-(Rl*Rp+Rl*Rci+Rci*Rp))/(l*(Rp+Rci))];
B1 = [-1/co 0; 0 1/(ci*(Rp+Rci)); 0 Rci/(l*(Rp+Rci))];
A2 = [0 0 1/co; 0 -1/(ci*(Rp+Rci)) -Rp/(ci*(Rp+Rci)); -1/l Rp/(l*(Rp+Rci)) (-(Rl*Rp+Rl*Rci+Rci*Rp+Rp*Rco+Rco*Rci))/(l*(Rp+Rci))];
B2 = [-1/co 0; 0 1/(ci*(Rp+Rci)); Rco/l Rci/(l*(Rp+Rci))];
% Determining the state and input vectors
X = [vco; vci; iL];
U = [Io; Vp];
A_avg = A1*D+A2*(1-D);
B_avg = B1*D+B2*(1-D);
% Finding the transfer function
% (sI-A)
SIminusA = s*eye(3) - A_avg;
% (sI-A)^-1
inv_SIminusA = inv(SIminusA);
% (A1-A2)X+(B1-B2)U
A1minusA2XPlusB1minusB2U = (A1 - A2)*X + (B1 - B2)*U;
% Inductor current to duty cycle Trasnfer Function
% C*((sI-A)^-1*((A1-A2)X+(B1-B2)U))
y_IL = C*(inv_SIminusA*A1minusA2XPlusB1minusB2U) % Bodeplot af TF
% minreal cancelling poles and zeros
y_IL1 = minreal(y_IL)
% Step response of the Buck-Boost Converter (Uncontrolled, Open loop)
step(y_IL1)
% pole-zero-gain model
zpk(y_IL1)
% PI Controller
Kp = 1;
Ki = 2;
Gc = pid(Kp, Ki)
Gcl = minreal(feedback(Gc*y_IL1, 1))
% Step response of the Feedback Control System (Closed-loop)
step(Gcl)
6 Comments
Sam Chak
on 2 Dec 2022
Hi @Mads Olesen
That's because the value of your chosen is relatively small compared to the coefficients and . Moreover, you can to mix and match the combinations of and values to observe some results. In your case, seems to have a greater influence over the response than does. See the following example...
...
Gp = minreal(y_IL, 1e-6)
% Brute force simulating the step responses of 25 PI Controllers
Kp = [1e-2 1e-1 1e-0 1e1 1e2];
Ki = [2e-2 2e-1 2e-0 2e1 2e2];
[ca, cb] = ndgrid(Kp, Ki);
combs = [ca(:), cb(:)];
for j = 1:length(combs)
K = combs(j, :);
Kp = K(1);
Ki = K(2);
Gc = pid(Kp, Ki);
Gcl = minreal(feedback(Gc*Gp, 1));
step(Gcl), hold on
end
hold off
Lastly, keep in mind that using a 2-parameter 1st-order controller (PI) on a 3rd-order system yields a 4th-order closed-loop system with 4 free terms to be solved in the Characteristic Polynomial (look up ). The free terms outnumber the design parameters {Kp, Ki} making the design problem overconstrained.
In other words, you cannot freely design the controller to achieve desired response (specified in terms of desired settling time). However, it is possible use the Brute Force method to find a combination of Kp and Ki that give a satisfactory stable response.
More Answers (2)
Sam Chak
on 5 Dec 2022
Hi @Mads Olesen
You can try this. But use a small combination pool.
From the previous simulations, it seems that Kp has a more dominant influence on the transient behavior than Ki.
formatSpec = '%.2f';
s = tf('s');
Gp = (1.699e06*s^2 + 2.764e09*s + 6.575e10)/(s^3 + 2197*s^2 + 7.057e06*s + 2.055e08);
% Kp = [1e-1 45e-2 1e0];
% Ki = [2e-1 11e-1 2e0];
Kp = 0.2:0.2:1.0;
Ki = 2e0;
[ca, cb] = ndgrid(Kp, Ki);
combs = [ca(:), cb(:)]
for j = 1:length(combs)
K = combs(j, :);
Kp = K(1);
Ki = K(2);
Gc = pid(Kp, Ki);
Gcl = minreal(feedback(Gc*Gp, 1));
t = linspace(0, 3.5e-5, 351);
y = step(Gcl, t); hold on
plot(t, y, 'linewidth', 1.5, 'DisplayName', ['K_p = ' num2str(combs(j), formatSpec) ', K_i = ' num2str(combs(j+length(combs)), formatSpec)]);
end
hold off, grid on, ylim([-0.2 1.2])
legend('show', 'location', 'best');
Sam Chak
on 20 Dec 2022
Hi @Mads Olesen
It appears that your intuition is right. The P-only controller is sufficient because the steady-state error is insignificant, at least for this range of P-values. The larger the P-value is, the smaller the steady-state error is.
On your Question #2, there are some differences. The Loop transfer function with a P-only controller is a Type-0 system, while Loop transfer function with a PI controller is a Type-1 system.
The Closed-loop transfer function under a P-only controller is a 3rd-order system, while Closed-loop transfer function under a PI controller is a 4th-order system. See results below.
formatSpec = '%.2f';
s = tf('s');
Gp = (1.699e06*s^2 + 2.764e09*s + 6.575e10)/(s^3 + 2197*s^2 + 7.057e06*s + 2.055e08);
% P-only controller
Gca = pid(1);
% Loop transfer function (Type-0 system)
Gl1 = series(Gca, Gp)
% closed-loop system under P-only controller (3rd-order system)
Gcl = minreal(feedback(Gl1, 1))
Kp = 0.2:0.2:1.0;
for j = 1:length(Kp)
K = Kp(j);
Gc = pid(K);
Gcl = minreal(feedback(Gc*Gp, 1));
yssP(j) = dcgain(Gcl);
t = linspace(0, 3.5e-5, 351);
y = step(Gcl, t); hold on
plot(t, y, 'linewidth', 1.5, 'DisplayName', ['K_p = ' num2str(Kp(j), formatSpec)]);
end
hold off, grid on, ylim([-0.2 1.2])
legend('show', 'location', 'best');
% output steady-state under P-only controller
yssP % if not exactly 1, then the steady-state error ess is non-zero
% PI controller
Gcb = pid(1, 2);
% Loop transfer function (Type-1 system)
Gl2 = series(Gcb, Gp)
% closed-loop system under PI controller (4th-order system)
Gcl = minreal(feedback(Gl2, 1))
% steady-state under PI controller
yssPI = dcgain(Gcl) % if exactly 1, then the output is exactly equal to the unit step input.
1 Comment
Siddharth Jawahar
on 22 Nov 2024 at 21:21
Hello! Thanks for the detailed effort, Sam, to guide Mads here. I would also like to point out that once you have the pid object in MATLAB, you can use the pidtune command to tune the gains automatically based on the controller requirements you need. Please see an example below with the plant model you have:
% Define the PID controller type and set up a PID control object
pidController = pid(1,1,0.1); % Initialize PID controller
% Configure tuning options with 'balanced' design focus
opts = pidtuneOptions('DesignFocus', 'balanced');
% Tune the PID controller
[pidTuned, tuningInfo] = pidtune(y_IL1, controllerType, opts);
% Display the tuned PID controller and tuning information
disp('Tuned PID Controller with balanced focus:');
disp(pidTuned);
disp('Tuning Info:');
disp(tuningInfo);
% Create closed-loop system with the tuned PID controller
closedLoopSystem = feedback(pidTuned * y_IL1, 1);
% Plot step response of the closed-loop system
figure;
step(closedLoopSystem);
title('Step Response with Balanced PID Tuning');
grid on;
HTH,
Sid
See Also
Categories
Find more on Get Started with Control System Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!