Main Content

tunablePID

Tunable PID controller

Description

Model object for creating tunable one-degree-of-freedom PID controllers.

tunablePID lets you parametrize a tunable SISO PID controller for parameter studies or for automatic tuning with tuning commands such as systune, looptune, or the Robust Control Toolbox™ command, hinfstruct (Robust Control Toolbox).

tunablePID is part of the family of parametric Control Design Blocks. Other parametric Control Design Blocks include tunableGain, tunableSS, and tunableTF.

Creation

Description

blk = tunablePID(name,type) creates the one-degree-of-freedom continuous-time PID controller:

blk=Kp+Kis+Kds1+Tfs,

with tunable parameters Kp, Ki, Kd, and Tf. The type argument sets the controller type by fixing some of these values to zero.

example

blk = tunablePID(name,type,Ts) creates a discrete-time PID controller with sample time Ts:

blk=Kp+KiIF(z)+KdTf+DF(z),

where IF(z) and DF(z) are the discrete integrator formulas for the integral and derivative terms, respectively. The values of the IFormula and DFormula properties set the discrete integrator formulas (see Properties).

blk = tunablePID(name,sys) uses the dynamic system model, sys, to set the sample time, Ts, and the initial values of the parameters Kp, Ki, Kd, and Tf.

example

Input Arguments

expand all

Name of PID controller, specified as a character vector, such as 'C' or 'PI1'. See Properties.

Name of PID controller, specified as 'P', 'PI', 'PD', or 'PID'. Specifying a controller type fixes up to three of the PID controller parameters.

Value for typeController TypeEffect on PID Parameters
'P'Proportional onlyKi and Kd are fixed to zero; Tf is fixed to 1; Kp is free
'PI'Proportional-integralKd is fixed to zero; Tf is fixed to 1; Kp and Ki are free
'PD'Proportional-derivative with first-order filter on derivative actionKi is fixed to zero; Kp, Kd, and Tf are free
'PID'Proportional-integral-derivative with first-order filter on derivative actionKp, Ki, Kd, and Tf are free

Sample time, specified as a scalar.

System representing a PID controller, specified as a dynamic system model object. See Dynamic System Models.

Properties

expand all

Parametrization of the PID gains Kp, Ki, Kd, and filter time constant Tf of the tunable PID controller blk, stored as param.Continuous objects. For general information about the properties of these param.Continuous objects, see the param.Continuous (Simulink Design Optimization) object reference page.

These fields of blk.Kp, blk.Ki, blk.Kd, and blk.Tf are used when you tune blk using a tuning command such as systune.

FieldDescription
ValueCurrent value of the parameter.
Free

Logical value determining whether the parameter is fixed or tunable. For example,

  • If blk.Kp.Free = 1, then blk.Kp.Value is tunable.

  • If blk.Kp.Free = 0, then blk.Kp.Value is fixed.

Minimum

Minimum value of the parameter. This property places a lower bound on the tuned value of the parameter. For example, setting blk.Kp.Minimum = 0 ensures that Kp remains positive.

blk.Tf.Minimum must always be positive.

MaximumMaximum value of the parameter. This property places an upper bound on the tuned value of the parameter. For example, setting blk.Tf.Maximum = 100 ensures that the filter time constant does not exceed 100.

Discrete integrator formulas IF(z) and DF(z) for the integral and derivative terms, respectively, stored as 'ForwardEuler', 'BackwardEuler', or 'Trapezoidal'.

ValueIF(z) or DF(z) Formula
'ForwardEuler'

Tsz1

'BackwardEuler'

Tszz1

'Trapezoidal'

Ts2z+1z1

Sample time, stored as a scalar. For continuous-time models, Ts = 0. For discrete-time models, Ts is a positive scalar representing the sampling period. This value is expressed in the unit specified by the TimeUnit property of the model. Unspecified sample time (Ts = -1) is not supported for PID blocks.

Changing this property does not discretize or resample the model.

Units for the time variable, the sample time Ts, and any time delays in the model, stored as one of these values:

  • 'nanoseconds'

  • 'microseconds'

  • 'milliseconds'

  • 'seconds'

  • 'minutes'

  • 'hours'

  • 'days'

  • 'weeks'

  • 'months'

  • 'years'

Changing this property has no effect on other properties, and therefore changes the overall system behavior. Use chgTimeUnit to convert between time units without modifying system behavior.

Input channel name, stored as a character vector. Use this property to name the input channel of the controller model. For example, assign the name error to the input of a controller model C as follows.

C.InputName = 'error';

You can use the shorthand notation u to refer to the InputName property. For example, C.u is equivalent to C.InputName.

Input channel names have several uses, including:

  • Identifying channels on model display and plots

  • Specifying connection points when interconnecting models

Input channel units, stored as a character vector. Use this property to track input signal units. For example, assign the concentration units mol/m^3 to the input of a controller model C as follows.

C.InputUnit = 'mol/m^3';

InputUnit has no effect on system behavior.

Input channel groups, stored as a struct with no fields. This property is not needed for PID controller models.

Output channel name, stored as a character vector. Use this property to name the output channel of the controller model. For example, assign the name control to the output of a controller model C as follows.

C.OutputName = 'control';

You can use the short notation y to refer to the OutputName property. For example, C.y is equivalent to C.OutputName.

Input channel names have several uses, including:

  • Identifying channels on model display and plots

  • Specifying connection points when interconnecting models

Output channel units, stored as a character vector. Use this property to track output signal units. For example, assign the unit Volts to the output of a controller model C as follows.

C.OutputUnit = 'Volts';

OutputUnit has no effect on system behavior.

Output channel groups, stored as a struct with no fields. This property is not needed for PID controller models.

System name, stored as a character vector. For example, 'system_1'.

Text to associate with the system, stored as a string or a cell array of character vectors. The property stores whichever data type you provide. For instance, if sys1 and sys2 are dynamic system models, you can set their Notes properties as follows:

sys1.Notes = "sys1 has a string.";
sys2.Notes = 'sys2 has a character vector.';
sys1.Notes
sys2.Notes
ans = 

    "sys1 has a string."


ans =

    'sys2 has a character vector.'

Data type to associate with the system, specified as any MATLAB data type.

Object Functions

systuneTune fixed-structure control systems modeled in MATLAB
looptuneTune fixed-structure feedback loops
genssGeneralized state-space model
hinfstruct (Robust Control Toolbox)H tuning of fixed-structure controllers

Examples

collapse all

Create a tunable PD controller. Then, initialize the parameter values, and fix the filter time constant.

blk = tunablePID('pdblock','PD');
blk.Kp.Value = 4;        % initialize Kp to 4
blk.Kd.Value = 0.7;      % initialize Kd to 0.7
blk.Tf.Value = 0.01;     % set parameter Tf to 0.01
blk.Tf.Free = false;     % fix parameter Tf to this value
blk
Tunable continuous-time PID controller "pdblock" with formula:

               s    
  Kp + Kd * --------
             Tf*s+1 

and tunable parameters Kp, Kd.

Type "pid(blk)" to see the current value.

Create a tunable discrete-time PI controller. Use a pid object to initialize the parameters and other properties.

C = pid(5,2.2,'Ts',0.1,'IFormula','BackwardEuler');
blk = tunablePID('piblock',C)
Tunable discrete-time PID controller "piblock" with formula:

             Ts*z 
  Kp + Ki * ------
              z-1 

and tunable parameters Kp, Ki.

Type "pid(blk)" to see the current value.

blk takes the value of properties, such as Ts and IFormula, from C.

Create a tunable PID controller, and assign names to the input and output.

blk = tunablePID('pidblock','pid')   
Tunable continuous-time PID controller "pidblock" with formula:

             1            s    
  Kp + Ki * --- + Kd * --------
             s          Tf*s+1 

and tunable parameters Kp, Ki, Kd, Tf.

Type "pid(blk)" to see the current value.
blk.InputName = {'error'}       % assign input name
Tunable continuous-time PID controller "pidblock" with formula:

             1            s    
  Kp + Ki * --- + Kd * --------
             s          Tf*s+1 

and tunable parameters Kp, Ki, Kd, Tf.

Type "pid(blk)" to see the current value.
blk.OutputName = {'control'}    % assign output name
Tunable continuous-time PID controller "pidblock" with formula:

             1            s    
  Kp + Ki * --- + Kd * --------
             s          Tf*s+1 

and tunable parameters Kp, Ki, Kd, Tf.

Type "pid(blk)" to see the current value.

Tips

  • You can modify the PID structure by fixing or freeing any of the parameters Kp, Ki, Kd, and Tf. For example, blk.Tf.Free = false fixes Tf to its current value.

  • To convert a tunablePID parametric model to a numeric (nontunable) model object, use model commands such as pid, pidstd, tf, or ss. You can also use getValue to obtain the current value of a tunable model.

Version History

Introduced in R2016a

expand all