23 views (last 30 days)

Show older comments

Hafiz Hamza on 1 Aug 2024 at 15:55

Commented: Sam Chak on 1 Aug 2024 at 21:23

I am working on tunning the PID gains for a flyback converter. I am curious about what methods out of the popular lmethods ( Ziegler–Nichols, Aström's AMIGO, Skogestad's Internal Model Control, and Chien-Hrones-Reswick) the "pidtune()" function used to give the PID gains.

I also go throw the pidtune.m file using the "edit pidtune" command in the MATLAB script to have a look what is going on inside the pidtune function. After going through several iteration line by line I am still unable to figure out the answer. To me its look like a kind of heuristic algorithm.

I am seeking assistance from all the community.

Regards

##### 0 Comments Show -2 older commentsHide -2 older comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

### Answers (1)

Sam Chak on 1 Aug 2024 at 16:30

⋮

Hi @Hafiz Hamza

The pidtune() command utilizes a proprietary algorithm for tuning the PID gains to achieve a balance between performance and robustness. If you do not specify the desired properties, namely the target phase margin and the closed-loop performance objective, for tuning a PID controller using the pidtuneOptions() command, then the algorithm will determine a crossover frequency based on the given plant dynamics, and then design for a target phase margin of 60 degrees.

https://www.mathworks.com/help/control/getstart/pid-tuning-algorithm.html

##### 3 Comments Show 1 older commentHide 1 older comment

Show 1 older commentHide 1 older comment

Sam Chak on 1 Aug 2024 at 16:42

#### Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/2142161-which-algorithm-pidtune-function-used-for-finding-pid-gains#comment_3226686

If the nominal model of the plant is available or identified, I do not use any of the Ziegler–Nichols, Aström's AMIGO, Skogestad's Internal Model Control, or Chien-Hrones-Reswick methods.

For stable deterministic 2nd-order single-input, single-output (SISO) systems, I use my own intellectual formulas to directly determine the PID gains that fully meet the control performance objectives.

For high-order systems or those that cannot be reduced to a 2nd-order form, I employ a Genetic Algorithm with a custom objective function to search for the "best" PID gains.

Hafiz Hamza on 1 Aug 2024 at 20:14

#### Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/2142161-which-algorithm-pidtune-function-used-for-finding-pid-gains#comment_3226856

@Sam Chak Thank you for your response. But I am confused here "proprietary algorithm".

What are these algorithms?. Yes I have my system model derived. Could you please elaborate why one should not use Ziegler–Nichols, Aström's AMIGO, Skogestad's Internal Model Control, or Chien-Hrones-Reswick methods when he/she has derived the system matehmatical model.

I shall be gratefull if you share your approach ( intellectual formulas) to determine the PID gains.

Regarding genetic algorithims how would you come up with a objective function if let suppose my system is continuously subjected to varying loads?

I am looking forwrad to your response.

Regards

Sam Chak on 1 Aug 2024 at 21:23

#### Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/2142161-which-algorithm-pidtune-function-used-for-finding-pid-gains#comment_3226926

Open in MATLAB Online

Hi @Hafiz Hamza

The "proprietary algorithm" could be utilizing the in-house 'fmincon()' algorithm or a similar optimizer to tune the PID gains until the optimization objectives are met (e.g., the target phase margin and the closed-loop performance).

You may have misinterpreted my previous comment. However, you can definitely use any of the Ziegler–Nichols, Åström's AMIGO, Skogestad's Internal Model Control, or Chien-Hrones-Reswick methods to tune the PID gains, even when the Plant's transfer function is known. These autotuning methods are model-free, reactive approaches. In other words, you inject an input signal and measure the output response. From the data analysis, you can obtain the response characteristics such as time constant, dead-time, etc.

For example, if you select the Chien-Hrones-Reswick method, these characteristics serve as the parameters to estimate the PID gains using the specified formulas that guarantee 0% (conservative) and 20% (aggressive) overshoot. No complex control design and stability proof is required!!!

Unfortunately, I am unfamiliar with the flyback converter, so I cannot comment on how to construct the objective function. However, I can share my unpublished PID formulas for 0% overshoot, if that would be helpful.

Gp = tf(20, [1 4.5 64]) % Plant's transfer function (stable)

Gp = 20 ---------------- s^2 + 4.5 s + 64 Continuous-time transfer function.

Ts = 0.561; % Desired Settling Time of the Closed-loop System

[Gc, Gh] = zeropid(Gp, Ts) % Scroll down to the end of the script

Gc = 1 Kp + Ki * --- + Kd * s s with Kp = 4.86, Ki = 17, Kd = 0.349 Continuous-time PID controller in parallel form.Gh = 0.821 s^2 + 4.094 s + 16.95 ---------------------------- 0.3487 s^2 + 4.863 s + 16.95 Continuous-time transfer function.

Gcl = feedback(Gc*Gp, Gh) % Closed-loop System

Gcl = 2.431 s^4 + 67.82 s^3 + 709.4 s^2 + 3298 s + 5749 ------------------------------------------------------------- 0.3487 s^5 + 12.16 s^4 + 169.5 s^3 + 1182 s^2 + 4122 s + 5749 Continuous-time transfer function.

S = stepinfo(Gcl) % Performances

S = struct with fields:

RiseTime: 0.3150 TransientTime: 0.5610 SettlingTime: 0.5610 SettlingMin: 0.9066 SettlingMax: 0.9999 Overshoot: 0 Undershoot: 0 Peak: 0.9999 PeakTime: 1.2900

step(Gcl, round(4*Ts, 0)), hold on

step(Gp), grid on, ylim([-0.2, 1.2])

xline(S.SettlingTime, '--', sprintf('Settling Time: %.3f sec', S.SettlingTime), 'color', '#7F7F7F', 'LabelVerticalAlignment', 'bottom')

legend('Closed-loop', 'Open-loop Plant', 'location', 'east')

%% The 0% overshoot method

function [C, H] = zeropid(P, Ts)

% Gp is a stable 2nd-order Plant

% Ts is the desired settling time

[numP, denP] = tfdata(minreal(P), 'v');

a1 = denP(2);

a2 = denP(3);

b = numP(3);

Tc = -log(0.02)/Ts; % Desired time constant

% Formulas

k1 = (3*(b^2)*((Tc/b)^2) - a2)/b;

k2 = (b^2)*((Tc/b)^3);

k3 = (3*b*(Tc/b) - a1)/b;

k4 = 2*b*((Tc/b)^2); % P-gain of PID controller

k5 = k2; % I-gain of PID controller

k6 = Tc/b; % D-gain of PID controller

% PID controller and the Compensator

C = pid(k4, k5, k6); % PID control in the forward path

H = tf([k3 k1 k2], [k6 k4 k5]); % Compensator in the feedback path

end

Sign in to comment.

Sign in to answer this question.

### See Also

### Categories

Control SystemsControl System ToolboxControl System Design and TuningPID Controller Tuning

Find more on **PID Controller Tuning** in Help Center and File Exchange

### Tags

- pid
- controller tunning

### Products

- Control System Toolbox

### Community Treasure Hunt

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

Start Hunting!

**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

- América Latina (Español)
- Canada (English)
- United States (English)

Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français

- United Kingdom(English)

Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

Contact your local office