ControlDesign

 PIDAuto
 automatic tuning of PID controller based on a desired closed-loop time constant

 Calling Sequence PIDAuto(sys, Tc, opts)

Parameters

 sys - System; system object Tc - And(positive, numeric); desired closed-loop time constant (seconds) opts - (optional) equation(s) of the form option = value; specify options for the PIDAuto command

Options

 • factored = true or false
 True means return the factored version of the controller gains ($K=\mathrm{Kp}$, $\mathrm{Ti}=\frac{\mathrm{Kp}}{\mathrm{Ki}}$, $\mathrm{Td}=\frac{\mathrm{Kd}}{\mathrm{Kp}}$ and $\mathrm{Nd}=\mathrm{Tf}$). False means return the controller gains ($\mathrm{Kp}$, $\mathrm{Ki}$, $\mathrm{Kd}$ and $\mathrm{Tf}$). The default is false.
 • returntype =  record or system
 Specifies the returned type. If a record is specified, a record containing the PID controller parameters is returned. If system is specified, a System (DynamicSystems system object) containing the transfer function of the PID controller is returned. The default value is record.
 True means return a System (DynamicSystems system object) containing the PID controller transfer function. False means return a record containing the controller gains. The default value is false.
 • proper =  true or false
 True means return PID controller gains to make its transfer function proper in case $\mathrm{Tf}=0$ ($\mathrm{Tf}$ is set to a recommended value of $\frac{1}{100}\mathrm{Kd}$ . The default is false.
 • parameters = {list, set}(name = complexcons)
 Specifies numeric values for the parameters of sys. These values override any parameters previously specified for sys. The numeric value on the right-hand side of each equation is substituted for the name on the left-hand side in the sys equations. The default is the value of sys given by DynamicSystems:-SystemOptions(parameters).

Description

 • The PIDAuto command automatically calculates the controller gains of a PID controller with filtered derivative, based on the desired closed-loop time constant, Tc (seconds).
 • The system sys is a continuous-time linear system object created using the DynamicSystems package. The system object must be in transfer function (TF) form. The system must be single-input single-output (SISO). The system must be proper and must have a nonzero static gain.
 • The parameter Tc is a tuning parameter that generally has the same order of magnitude as the time constant of the closed-loop. Tune this parameter to adjust the time constant of the closed-loop precisely.
 • The PIDAuto command returns a record containing the controller parameters $\mathrm{Kp}$, $\mathrm{Ki}$, $\mathrm{Kd}$ and $\mathrm{Tf}$, where $\mathrm{Kp}$ is the proportional gain, $\mathrm{Ki}$ is the integral gain, $\mathrm{Kd}$ is the derivative gain and $\mathrm{Tf}$ is the time constant of the derivative filter. The controller transfer function is then obtained as:
 $C\left(s\right)=\mathrm{Kp}+\frac{\mathrm{Ki}}{s}+\frac{\mathrm{Kd}s}{\mathrm{Tf}s+1}$.
 • If the computed value of $\mathrm{Tf}$ is equal to zero, the resulting PID controller transfer function is improper. A recommended value to make the transfer function proper is $\mathrm{Tf}=\frac{1}{100}\mathrm{Kd}$. This value is used when the proper option is set to true and the computed value of $\mathrm{Tf}$ is equal to zero. The controller transfer function is then obtained as:
 $C\left(s\right)=\mathrm{Kp}+\frac{\mathrm{Ki}}{s}+\frac{\mathrm{Kd}s}{1+\frac{1}{100}\mathrm{Kd}s}$.
 If the resulting closed-loop is unstable, use RouthTable in order to calculate a value of $\mathrm{Tf}$ that keeps the closed-loop stable.
 • If the order of sys is greater than two and sys is unstable or has complex poles, the gains are calculated using an optimization algorithm that may not be able to find a solution if Tc is too small. The error message is then could not compute a stabilizing PID. In this case, try increasing Tc until a solution can be found.

Examples

 > $\mathrm{with}\left(\mathrm{DynamicSystems}\right):$
 > $\mathrm{with}\left(\mathrm{ControlDesign}\right):$
 > ${\mathrm{infolevel}}_{\mathrm{ControlDesign}}≔3:$

Differential equations of a DC motor model:

 > $\mathrm{eq1}≔J\left(\frac{ⅆ}{ⅆt}\mathrm{ω}\left(t\right)\right)+b\mathrm{ω}\left(t\right)-Ki\left(t\right)=0:$
 > $\mathrm{eq2}≔L\left(\frac{ⅆ}{ⅆt}i\left(t\right)\right)+Ri\left(t\right)=V\left(t\right)-K\mathrm{ω}\left(t\right):$
 > $\mathrm{eq3}≔\frac{ⅆ}{ⅆt}\mathrm{θ}\left(t\right)=\mathrm{ω}\left(t\right):$

The numeric values of the model parameters are as follows:

 > $\mathrm{params}≔\left\{J=0.01,K=0.01,L=0.5,R=1,b=0.1\right\}:$

Transfer function

 > $\mathrm{systf}≔\mathrm{TransferFunction}\left(\left[\mathrm{eq1},\mathrm{eq2},\mathrm{eq3}\right],\left[V\left(t\right)\right],\left[i\left(t\right),\mathrm{ω}\left(t\right),\mathrm{θ}\left(t\right)\right]\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{systf}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{3 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{V}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{i}{}\left({s}\right){,}{\mathrm{\omega }}{}\left({s}\right){,}{\mathrm{\theta }}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{J}{}{s}{+}{b}}{{J}{}{L}{}{{s}}^{{2}}{+}\left({J}{}{R}{+}{L}{}{b}\right){}{s}{+}{{K}}^{{2}}{+}{R}{}{b}}\\ {{\mathrm{tf}}}_{{2}{,}{1}}{=}\frac{{K}}{{J}{}{L}{}{{s}}^{{2}}{+}\left({J}{}{R}{+}{L}{}{b}\right){}{s}{+}{{K}}^{{2}}{+}{R}{}{b}}\\ {{\mathrm{tf}}}_{{3}{,}{1}}{=}\frac{{K}}{{J}{}{L}{}{{s}}^{{3}}{+}\left({J}{}{R}{+}{L}{}{b}\right){}{{s}}^{{2}}{+}\left({{K}}^{{2}}{+}{R}{}{b}\right){}{s}}\end{array}\right$ (1)

Extract a subsystem with the desired output (position $\mathrm{\theta }$):

 > $\mathrm{subsystf}≔\mathrm{Subsystem}\left(\mathrm{systf},'\mathrm{all}',\left\{3\right\}\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{subsystf}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{V}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{\theta }}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{K}}{{J}{}{L}{}{{s}}^{{3}}{+}\left({J}{}{R}{+}{L}{}{b}\right){}{{s}}^{{2}}{+}\left({{K}}^{{2}}{+}{R}{}{b}\right){}{s}}\end{array}\right$ (2)

Design a position controller with a settling time of 4 seconds (time constant is 0.7 seconds approximately):

 > $\mathrm{τ}≔0.7$
 ${\mathrm{τ}}{≔}{0.7}$ (3)
 > $\mathrm{pid}≔\mathrm{PIDAuto}\left(\mathrm{subsystf},\mathrm{τ},'\mathrm{parameters}'=\mathrm{params}\right)$
 PIDAuto:   Using PIDOptimize
 ${\mathrm{pid}}{≔}{\mathrm{Record}}{[}{\mathrm{packed}}{]}{}\left({\mathrm{Kp}}{=}{10.2115133154945}{,}{\mathrm{Ki}}{=}{0.000879895477927287}{,}{\mathrm{Kd}}{=}{1.01771326328058}{,}{\mathrm{Tf}}{=}{0}\right)$ (4)

Get a proper transfer function for the PID controller

 > $\mathrm{pidtf}≔\mathrm{PIDAuto}\left(\mathrm{subsystf},\mathrm{τ},'\mathrm{parameters}'=\mathrm{params},'\mathrm{returntype}'=\mathrm{system},'\mathrm{proper}'=\mathrm{true}\right):$
 PIDAuto:   Using PIDOptimize PIDAuto:   Computed 'Tf = 0' (improper PID transfer function); setting 'Tf = Kd/100' to make it proper
 > $\mathrm{PrintSystem}\left(\mathrm{pidtf}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{1.121637189}{}{{s}}^{{2}}{+}{10.21152227}{}{s}{+}{0.0008798954779}}{{0.01017713263}{}{{s}}^{{2}}{+}{s}}\end{array}\right$ (5)

Calculate the closed-loop system and plot a step response:

 > $\mathrm{clsys}≔\mathrm{PIDClosedLoop}\left(\mathrm{subsystf},\mathrm{pidtf},'\mathrm{parameters}'=\mathrm{params}\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{clsys}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{theta_ref}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{\theta }}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{0.01121637189}{}{{s}}^{{2}}{+}{0.1021152227}{}{s}{+}{8.798954779}{}{{10}}^{{-6}}}{{0.00005088566315}{}{{s}}^{{5}}{+}{0.005610627958}{}{{s}}^{{4}}{+}{0.06101873098}{}{{s}}^{{3}}{+}{0.1113163719}{}{{s}}^{{2}}{+}{0.1021152227}{}{s}{+}{8.798954779}{}{{10}}^{{-6}}}\end{array}\right$ (6)
 > $\mathrm{ResponsePlot}\left(\mathrm{clsys},\mathrm{Step}\left(\right),'\mathrm{output}'=\mathrm{θ},'\mathrm{duration}'=10,'\mathrm{gridlines}'=\mathrm{true},'\mathrm{parameters}'=\mathrm{params}\right)$

References

 [1] Philippe de Larminat, Automatique appliquee, Hermes, 2007.
 [2] Sigurd Skogestad, Simple analytic rules for model reduction and PID controller design, Journal of Process Control, Vol. 13, 291-309, 2003.
 [3] J. M. Maciejowski, Multivariable Feedback Design, Pearson Education, 1989.
 [4] J. M. Edmunds, Control system design and analysis using closed-loop Nyquist and Bode arrays, International Journal of Control, 30: 5, 773-802, 1979.