Main Content

pidtune

PID tuning algorithm for linear plant model

Syntax

C = pidtune(sys,type)
C = pidtune(sys,C0)
C = pidtune(sys,type,wc)
C = pidtune(sys,C0,wc)
C = pidtune(sys,...,opts)
[C,info] = pidtune(...)

Description

C= pidtune(sys,type)designs a PID controller of typetypefor the plantsys. Iftypespecifies a one-degree-of-freedom (1-DOF) PID controller, then the controller is designed for the unit feedback loop as illustrated:

Iftypespecifies a two-degree-of-freedom (2-DOF) PID controller, thenpidtunedesigns a 2-DOF controller as in the feedback loop of this illustration:

pidtunetunes the parameters of the PID controllerCto balance performance (response time) and robustness (stability margins).

C= pidtune(sys,C0)designs a controller of the same type and form as the controllerC0. IfsysandC0are discrete-time models,Chas the same discrete integrator formulas asC0.

C= pidtune(sys,type,wc)andC= pidtune(sys,C0,wc)specify a target valuewcfor the first 0 dB gain crossover frequency of the open-loop response.

C= pidtune(sys,...,opts)uses additional tuning options, such as the target phase margin. UsepidtuneOptionsto specify the option setopts.

[C,info] = pidtune(...)returns the data structureinfo, which contains information about closed-loop stability, the selected open-loop gain crossover frequency, and the actual phase margin.

Input Arguments

sys

Single-input, single-outputdynamic system modelof the plant for controller design.syscan be:

  • Any type of SISO dynamic system model, including Numeric LTI models and identified models. Ifsysis a tunable or uncertain model,pidtunedesigns a controller for the current or nominal value ofsys.

  • A continuous- or discrete-time model.

  • Stable, unstable, or integrating. A plant with unstable poles, however, might not be stabilizable under PID control.

  • 一个模型,其中包括任何类型的时间延迟。一个plant with long time delays, however, might not achieve adequate performance under PID control.

  • An array of plant models. Ifsysis an array,pidtunedesigns a separate controller for each plant in the array.

If the plant has unstable poles, andsysis one of the following:

  • Afrdmodel

  • Assmodel with internal time delays that cannot be converted to I/O delays

you must usepidtuneOptionsto specify the number of unstable poles in the plant, if any.

type

Controller type of the controller to design, specified as a character vector. The termcontroller typerefers to which terms are present in the controller action. For example, a PI controller has only a proportional and an integral term, while a PIDF controller contains proportional, integrator, and filtered derivative terms.typecan take the values summarized below. For more detailed information about these controller types, seePID Controller Types for Tuning

1-DOF Controllers

  • 'P'— Proportional only

  • 'I'— Integral only

  • 'PI'— Proportional and integral

  • 'PD'— Proportional and derivative

  • 'PDF'— Proportional and derivative with first-order filter on derivative term

  • 'PID'— Proportional, integral, and derivative

  • 'PIDF'— Proportional, integral, and derivative with first-order filter on derivative term

2-DOF Controllers

  • 'PI2'— 2-DOF proportional and integral

  • 'PD2'— 2-DOF proportional and derivative

  • 'PDF2'— 2-DOF proportional and derivative with first-order filter on derivative term

  • 'PID2'— 2-DOF proportional, integral, and derivative

  • 'PIDF2'— 2-DOF proportional, integral, and derivative with first-order filter on derivative term

For more information about 2-DOF PID controllers generally, seeTwo-Degree-of-Freedom PID Controllers.

2-DOF Controllers with Fixed Setpoint Weights

  • 'I-PD'— 2-DOF PID withb= 0,c= 0

  • 'I-PDF'— 2-DOF PIDF withb= 0,c= 0

  • 'ID-P'— 2-DOF PID withb= 0,c= 1

  • 'IDF-P'— 2-DOF PIDF withb= 0,c= 1

  • 'PI-D'— 2-DOF PID withb= 1,c= 0

  • 'PI-DF'— 2-DOF PIDF withb= 1,c= 0

For more detailed information about fixed-setpoint-weight 2-DOF PID controllers, seePID Controller Types for Tuning.

Controller Form

When you use thetypeinput,pidtunedesigns a controller in parallel (pidorpid2) form. Use the inputC0instead oftypeif you want to design a controller in standard (pidstdorpidstd2) form.

Ifsysis a discrete-time model with sample timeTs,pidtunedesigns a discrete-time controller with the sameTs. The controller has theForwardEulerdiscrete integrator formula for both integral and derivative actions. Use the inputC0instead oftypeif you want to design a controller having a different discrete integrator formula.

For more information about PID controller forms and formulas, see:

C0

PID controller setting properties of the designed controller, specified as apid,pidstd,pid2, orpidstd2object. If you provideC0,pidtune:

  • Designs a controller of the type represented byC0.

  • Returns apidcontroller, ifC0is apidcontroller.

  • Returns apidstdcontroller, ifC0is apidstdcontroller.

  • Returns a 2-DOFpid2controller, ifC0is apid2controller.

  • Returns a 2-DOFpidstd2controller, ifC0is apidstd2controller.

  • Returns a controller with the sameIformulaandDformulavalues asC0, ifsysis a discrete-time system. See thepid,pid2,pidstd, andpidstd2reference pages for more information aboutIformulaandDformula.

wc

Target value for the 0 dB gain crossover frequency of the tuned open-loop response. Specifywcin units of radians/TimeUnit, whereTimeUnitis the time unit ofsys. The crossover frequencywcroughly sets the control bandwidth. The closed-loop response time is approximately1/wc.

Increasewcto speed up the response. Decreasewcto improve stability. When you omitwc,pidtuneautomatically chooses a value, based on the plant dynamics, that achieves a balance between response and stability.

opts

Option set specifying additional tuning options for thepidtunedesign algorithm, such as target phase margin or design focus. UsepidtuneOptionsto createopts.

Output Arguments

C

Controller designed forsys. Ifsysis an array of linear models,pidtunedesigns a controller for each linear model and returns an array of PID controllers.

Controller form:

  • If the second argument topidtuneistype,Cis apidorpid2controller.

  • If the second argument topidtuneisC0:

    • Cis apidcontroller, ifC0is apidobject.

    • Cis apidstdcontroller, ifC0is apidstdobject.

    • Cis apid2controller, ifC0is apid2object.

    • Cis apidstd2controller, ifC0is apidstd2object.

Controller type:

  • If the second argument topidtuneistype,Cgenerally has the specified type.

  • If the second argument topidtuneisC0,Cgenerally has the same type asC0.

In either case, however, where the algorithm can achieve adequate performance and robustness using a lower-order controller than specified withtypeorC0,pidtune返回一个Chaving fewer actions than specified. For example,Ccan be a PI controller even thoughtypeis'PIDF'.

Time domain:

  • Chas the same time domain assys.

  • Ifsysis a discrete-time model,Chas the same sample time assys.

  • If you specifyC0,Chas the sameIformulaandDformulaasC0. If noC0is specified, bothIformulaandDformulaareForward Euler. See thepid,pid2,pidstd, andpidstd2reference pages for more information aboutIformulaandDformula.

If you specifyC0,Calso obtains model properties such asInputNameandOutputNamefromC0. For more information about model properties, see the reference pages for each type of dynamic system model.

info

Data structure containing information about performance and robustness of the tuned PID loop. The fields ofinfoare:

  • Stable— Boolean value indicating closed-loop stability.Stableis 1 if the closed loop is stable, and 0 otherwise.

  • CrossoverFrequency— First 0 dB crossover frequency of the open-loop systemC*sys, inrad/TimeUnit, whereTimeUnitis the time units specified in theTimeUnitproperty ofsys.

  • PhaseMargin— Phase margin of the tuned PID loop, in degrees.

Ifsysis an array of plant models,infois an array of data structures containing information about each tuned PID loop.

Examples

collapse all

This example shows how to design a PID controller for the plant given by:

s y s = 1 ( s + 1 ) 3 .

As a first pass, create a model of the plant and design a simple PI controller for it.

sys = zpk([],[-1 -1 -1],1); [C_pi,info] = pidtune(sys,'PI')
C_pi = 1 Kp + Ki * --- s with Kp = 1.14, Ki = 0.454 Continuous-time PI controller in parallel form.
info =struct with fields:Stable: 1 CrossoverFrequency: 0.5205 PhaseMargin: 60.0000

C_piis apidcontroller object that represents a PI controller. The fields ofinfoshow that the tuning algorithm chooses an open-loop crossover frequency of about 0.52 rad/s.

Examine the closed-loop step response (reference tracking) of the controlled system.

T_pi = feedback(C_pi*sys, 1); step(T_pi)

Figure contains an axes object. The axes object contains an object of type line. This object represents T\_pi.

To improve the response time, you can set a higher target crossover frequency than the result thatpidtuneautomatically selects, 0.52. Increase the crossover frequency to 1.0.

[C_pi_fast,info] = pidtune(sys,'PI',1.0)
C_pi_fast = 1 Kp + Ki * --- s with Kp = 2.83, Ki = 0.0495 Continuous-time PI controller in parallel form.
info =struct with fields:Stable: 1 CrossoverFrequency: 1 PhaseMargin: 43.9973

The new controller achieves the higher crossover frequency, but at the cost of a reduced phase margin.

Compare the closed-loop step response with the two controllers.

T_pi_fast = feedback(C_pi_fast*sys,1); step(T_pi,T_pi_fast) axis([0 30 0 1.4]) legend('PI','PI,fast')

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent PI, PI,fast.

This reduction in performance results because the PI controller does not have enough degrees of freedom to achieve a good phase margin at a crossover frequency of 1.0 rad/s. Adding a derivative action improves the response.

Design a PIDF controller forGcwith the target crossover frequency of 1.0 rad/s.

[C_pidf_fast,info] = pidtune(sys,'PIDF',1.0)
C_pidf_fast = 1 s Kp + Ki * --- + Kd * -------- s Tf*s+1 with Kp = 2.72, Ki = 0.985, Kd = 1.72, Tf = 0.00875 Continuous-time PIDF controller in parallel form.
info =struct with fields:Stable: 1 CrossoverFrequency: 1 PhaseMargin: 60.0000

The fields of info show that the derivative action in the controller allows the tuning algorithm to design a more aggressive controller that achieves the target crossover frequency with a good phase margin.

Compare the closed-loop step response and disturbance rejection for the fast PI and PIDF controllers.

T_pidf_fast = feedback(C_pidf_fast*sys,1); step(T_pi_fast, T_pidf_fast); axis([0 30 0 1.4]); legend('PI,fast','PIDF,fast');

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent PI,fast, PIDF,fast.

You can compare the input (load) disturbance rejection of the controlled system with the fast PI and PIDF controllers. To do so, plot the response of the closed-loop transfer function from the plant input to the plant output.

S_pi_fast = feedback(sys,C_pi_fast); S_pidf_fast = feedback(sys,C_pidf_fast); step(S_pi_fast,S_pidf_fast); axis([0 50 0 0.4]); legend('PI,fast','PIDF,fast');

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent PI,fast, PIDF,fast.

This plot shows that the PIDF controller also provides faster disturbance rejection.

Design a PID controller in standard form for the following plant.

sys = 1 ( s + 1 ) 3

在标准形式来设计一个控制器,使用standard-form controller as theC0argument topidtune.

sys = zpk([],[-1 -1 -1],1); C0 = pidstd(1,1,1); C = pidtune(sys,C0)
C = 1 1 Kp * (1 + ---- * --- + Td * s) Ti s with Kp = 2.18, Ti = 2.57, Td = 0.642 Continuous-time PID controller in standard form

Design a discrete-time PI controller using a specified method to discretize the integrator.

If your plant is in discrete time,pidtuneautomatically returns a discrete-time controller using the default Forward Euler integration method. To specify a different integration method, usepidorpidstdto create a discrete-time controller having the desired integration method.

sys = c2d(tf([1 1],[1 5 6]),0.1); C0 = pid(1,1,'Ts',0.1,'IFormula','BackwardEuler'); C = pidtune(sys,C0)
C = t * z Kp +吻  * ------ z 1 Kp = -0.0658, Ki = 1.32, Ts = 0.1 Sample time: 0.1 seconds Discrete-time PI controller in parallel form.

UsingC0as an input causespidtuneto design a controllerCof the same form, type, and discretization method asC0. The display shows that the integral term ofCuses the Backward Euler integration method.

Specify a Trapezoidal integrator and compare the resulting controller.

C0_tr = pid(1,1,'Ts',0.1,'IFormula','Trapezoidal'); Ctr = pidtune(sys,C0_tr)
Ctr = Ts*(z+1) Ki * -------- 2*(z-1) with Ki = 1.32, Ts = 0.1 Sample time: 0.1 seconds Discrete-time I-only controller.

Design a 2-DOF PID Controller for the plant given by the transfer function:

G ( s ) = 1 s 2 + 0 . 5 s + 0 . 1 .

Use a target bandwidth of 1.5 rad/s.

wc = 1.5;特遣部队(G = 1, 0.5 - 0.1 [1]);C2 =πdtune(G,'PID2',wc)
C2 = 1 u = Kp (b*r-y) + Ki --- (r-y) + Kd*s (c*r-y) s with Kp = 1.26, Ki = 0.255, Kd = 1.38, b = 0.665, c = 0 Continuous-time 2-DOF PID controller in parallel form.

Using the type'PID2'causespidtuneto generate a 2-DOF controller, represented as apid2object. The display confirms this result. The display also shows thatpidtunetunes all controller coefficients, including the setpoint weightsbandc, to balance performance and robustness.

Tips

  • By default,pidtunewith thetypeinput returns apidcontroller in parallel form. To design a controller in standard form, use apidstdcontroller as input argumentC0. For more information about parallel and standard controller forms, see thepidandpidstdreference pages.

  • For interactive PID tuning in the Live Editor, see theTune PID ControllerLive Editor task. This task lets you interactively design a PID controller and automatically generates MATLAB®code for your live script.

Algorithms

For information about the MathWorks®PID tuning algorithm, seePID Tuning Algorithm.

Alternatives

References

Åström, K. J. and Hägglund, T.Advanced PID Control, Research Triangle Park, NC: Instrumentation, Systems, and Automation Society, 2006.

Version History

Introduced in R2010b