Main Content

tunablePID

Tunable PID controller

Syntax

blk = tunablePID(name,type)
blk = tunablePID(name,type,Ts)
blk = tunablePID(name,sys)

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.

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

Construction

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 (see Input Arguments).

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.

Input Arguments

name

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

type

Controller type, specified as one of the values in the following table. 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

Ts

Sample time, specified as a scalar.

sys

Dynamic system model representing a PID controller.

Properties

Kp, Ki, Kd, Tf

Parametrization of the PID gains Kp, Ki, Kd, and filter time constant Tf of the tunable PID controller blk.

The following 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.

blk.Kp, blk.Ki, blk.Kd, and blk.Tf are param.Continuous objects. For general information about the properties of these param.Continuous objects, see the param.Continuous (Simulink Design Optimization) object reference page.

IFormula, DFormula

Discrete integrator formulas IF(z) and DF(z) for the integral and derivative terms, respectively, specified as one of the values in the following table.

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

Tsz1

'BackwardEuler'

Tszz1

'Trapezoidal'

Ts2z+1z1

Default: 'ForwardEuler'

Ts

Sample time. 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.

Default: 0 (continuous time)

TimeUnit

Units for the time variable, the sample time Ts, and any time delays in the model, specified as one of the following 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.

Default: 'seconds'

InputName

Input channel name, specified 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

Default: Empty character vector, ''

InputUnit

Input channel units, specified 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.

Default: Empty character vector, ''

InputGroup

Input channel groups. This property is not needed for PID controller models.

Default: struct with no fields

OutputName

Output channel name, specified 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 shorthand 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

Default: Empty character vector, ''

OutputUnit

Output channel units, specified 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.

Default: Empty character vector, ''

OutputGroup

Output channel groups. This property is not needed for PID controller models.

Default: struct with no fields

Name

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

Default: ''

Notes

Any text that you want 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.'

Default: [0×1 string]

UserData

Any type of data you want to associate with system, specified as any MATLAB® data type.

Default: []

Examples

Tunable Controller with a Fixed Parameter

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
blk =

  Parametric 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 and "get(blk)" to see all properties.

Controller Initialized by Dynamic System Model

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)
blk =

  Parametric 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 and "get(blk)" to see all properties.

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

Controller with Named Input and Output

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

blk = tunablePID('pidblock','pid')   
blk.InputName = {'error'}       % assign input name
blk.OutputName = {'control'}    % assign output name

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