Which Algorithm "pidtune()" function used for finding PID gains? (2024)

23 views (last 30 days)

Show older comments

Hafiz Hamza on 1 Aug 2024 at 15:55

  • Link

    Direct link to this question

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

  • Link

    Direct link to this question

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

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

Sign in to comment.

Sign in to answer this question.

Answers (1)

Sam Chak on 1 Aug 2024 at 16:30

  • Link

    Direct link to this answer

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

  • Link

    Direct link to this answer

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

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

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

  • Link

    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

  • Link

    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

  • Link

    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')

Which Algorithm "pidtune()" function used for finding PID gains? (6)

%% 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.


Which Algorithm "pidtune()" function used for finding PID gains? (7)

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

Which Algorithm "pidtune()" function used for finding PID gains? (2024)

FAQs

What is the function of pidtune in Matlab? ›

pidtune tunes the parameters of the PID controller C to balance performance (response time) and robustness (stability margins). C = pidtune( sys , C0 ) designs a controller of the same type and form as the controller C0 .

What are the algorithms in PID? ›

There are currently 3 kinds of relatively simple PID control algorithms, namely: incremental algorithm, position type algorithm, differential algorithm. These control algorithms are the most simple and basic algorithms that they have their own characteristics and meet the general requirements of the most controls.

What is the tuning method of PID controller? ›

Manual tuning of pid controller

Manual PID tuning is done by setting the reset time to its maximum value and the rate to zero and increasing the gain until the loop oscillates at a constant amplitude. (When the response to an error correction occurs quickly a larger gain can be used.

How to calculate PID tuning parameters? ›

Once approximated the response to a first order model with delay, the controller parameters were calculated using the following ZN tuning rules:
  1. P controller: Kp = 1/a.
  2. PI controller: Kp = 0.9/a, Ti = 3L.
  3. PID controller: Kp = 1.2/a, Ti = 2L, Td = 0.5*L.

What is the code for PID controller in MATLAB? ›

C = pid( Kp , Ki , Kd , Tf ) creates a continuous-time parallel-form PID controller model and sets the properties Kp , Ki , Kd , and Tf . The remaining properties have default values. C = pid( Kp , Ki , Kd , Tf , Ts ) creates a discrete-time PID controller model with sample time Ts .

How to find step-response of transfer function in MATLAB? ›

Step Response at Specified Times

Examine the step response of the following transfer function. sys = (s+1)^2 ---------------------------- (s+0.05) (s^2 + 0.4s + 9.04) Continuous-time zero/pole/gain model. By default, step chooses an end time that shows the steady state that the response is trending toward.

What are the three 3 types of algorithms? ›

Types of Algorithms:
  • Sorting algorithms: Bubble Sort, insertion sort, and many more. ...
  • Searching algorithms: Linear search, binary search, etc. ...
  • Graph Algorithms: It is used to find solutions to problems like finding the shortest path between cities, and real-life problems like traveling salesman problems.
Oct 16, 2023

What are the 3 functions of algorithm? ›

Feasibility: It must be feasible to execute each instruction. Flexibility: It should also be possible to make changes in the algorithm without putting so much effort on it. Generality: The algorithm applies to a set of inputs.

How to choose PID gains? ›

To tune your PID controller manually, first the integral and derivative gains are set to zero. Increase the proportional gain until you observe oscillation in the output. Your proportional gain should then be set to roughly half this value.

What is gain in PID? ›

Gain adjustment is the function of P action in PID controller. It is just like how much times an amplifier amplifies the input signal. If the gain of P action is 1, then output of controller is equal to error signal. Gain is determined by Proportion Band. Mathematically, Gain= 100÷Proportional Band.

What is the good gain method for PID tuning? ›

The Good Gain method for PID tuning is applied to the established control system. The Good Gain method: Reading off the time, T ou , between the overshoot and the undershoot of the step response with P controller.

What is the easiest way to tune a PID? ›

The trial-and-error method is a relatively easy method, once you get a clear understanding of PID parameters. It steps through the parameters from proportional to integral to derivative. Usually you start from an existing set of parameters from which you perform small tweaks to improve the response.

What is the formula for the PID function? ›

The transfer function of a PID controller is found by taking the Laplace transform of Equation (1). = derivative gain. C = s^2 + s + 1 ----------- s Continuous-time transfer function. C = 1 Kp + Ki * --- + Kd * s s with Kp = 1, Ki = 1, Kd = 1 Continuous-time PID controller in parallel form.

How is PID calculated? ›

The basic idea behind a PID controller is to read a sensor, then compute the desired actuator output by calculating proportional, integral, and derivative responses and summing those three components to compute the output.

What is the function of convolution in MATLAB? ›

Convolution is a mathematical operation that combines two functions to describe the overlap between them. Convolution takes two functions and “slides” one of them over the other, multiplying the function values at each point where they overlap, and adding up the products to create a new function.

What is the function of Laplacian in MATLAB? ›

Description. l = laplacian( f , v ) returns the Laplacian of the symbolic field f with respect to the vector v in Cartesian coordinates. If f is an array, then the function computes the Laplacian for each element of f and returns the output l that is the same size as f .

What is the function of Imshow in MATLAB? ›

imshow( I ) displays the grayscale image I in a figure. imshow uses the default display range for the image data type and optimizes figure, axes, and image object properties for image display.

What is the Jaccard function in MATLAB? ›

Description. similarity = jaccard( BW1 , BW2 ) computes the intersection of binary images BW1 and BW2 divided by the union of BW1 and BW2 , also known as the Jaccard index. The images can be binary images, label images, or categorical images.

References

Top Articles
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 6583

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.