Main Content

tunablePID2

Tunable two-degree-of-freedom PID controller

Description

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

tunablePID2 lets you parametrize a tunable SISO two-degree-of-freedom PID controller. You can use this parametrized controller for parameter studies or for automatic tuning with tuning commands such as systune, looptune, or the Robust Control Toolbox™ command hinfstruct.

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

Creation

Description

blk = tunablePID2(name,type) creates the two-degree-of-freedom continuous-time PID controller described by the equation:

u=Kp(bry)+Kis(ry)+Kds1+Tfs(cry).

r is the setpoint command, y is the measured response to that setpoint, and u is the control signal, as shown in the following illustration.

The tunable parameters of the block are:

  • Scalar gains Kp, Ki, and Kd

  • Filter time constant Tf

  • Scalar weights b and c

The type argument sets the controller type by fixing some of these values to zero.

blk = tunablePID2(name,type,Ts) creates a discrete-time PID controller with sample time Ts. The equation describing this controller is:

u=Kp(bry)+KiIF(z)(ry)+KdTf+DF(z)(cry).

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.

blk = tunablePID2(name,sys) uses the dynamic system model, sys, to set the sample time, Ts, and the initial values of all the tunable parameters. The model sys must be compatible with the equation of a two-degree-of-freedom PID controller.

Input Arguments

expand all

PID controller Name, specified as a character vector such as 'C' or '2DOFPID1'.

Data Types: char

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

Data Types: char

Sample time, specified as a scalar.

Data Types: double

Dynamic system model representing a two-degree-of-freedom PID controller.

Data Types: double

Properties

expand all

Parametrization of the PID gains Kp, Ki, Kd, the filter time constant, Tf, and the scalar gains, b and c.

The following fields of blk.Kp, blk.Ki, blk.Kd, blk.Tf, blk.b, and blk.c are used when you tune blk using a tuning command such as systune:

FieldDescription
ValueCurrent value of the parameter. blk.b.Value, and blk.c.Value are always nonnegative.
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.c.Maximum = 1 ensures that c does not exceed unity.

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | function_handle | categorical | datetime | duration | calendarDuration | fi
Complex Number Support: Yes

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | function_handle | categorical | datetime | duration | calendarDuration | fi

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.

Data Types: double

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.

Input channel name, specified as a character vector or a 2-by-1 cell array of character vectors. Use this property to name the input channels of the controller model. For example, assign the names setpoint and measurement to the inputs of a 2-DOF PID controller model C as follows.

C.InputName = {'setpoint';'measurement'};

Alternatively, use automatic vector expansion to assign both input names. For example:

C.InputName = 'C-input';

The input names automatically expand to {'C-input(1)';'C-input(2)'}.

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, specified as a 2-by-1 cell array of character vectors. Use this property to track input signal units. For example, assign the units Volts to the reference input and the concentration units mol/m^3 to the measurement input of a 2-DOF PID controller model C as follows.

C.InputUnit = {'Volts';'mol/m^3'};

InputUnit has no effect on system behavior.

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

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

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.

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

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

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

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

Object Functions

Examples

Tunable Two-Degree-of-Freedom Controller with a Fixed Parameter

Tunable Two-Degree-of-Freedom Controller with a Fixed Parameter

Create a tunable two-degree-of-freedom PD controller. Then, initialize the parameter values, and fix the filter time constant.

blk = tunablePID2('pdblock','PD');
blk.b.Value = 1;
blk.c.Value = 0.5;
blk.Tf.Value = 0.01;
blk.Tf.Free = false;
blk
blk =

  Parametric continuous-time 2-DOF PID controller "pdblock" with equation:

                         s    
  u = Kp (b*r-y) + Kd -------- (c*r-y)
                       Tf*s+1 

  where r,y are the controller inputs and Kp, Kd, b, c are tunable gains.

Type "showBlockValue(blk)" to see the current value and "get(blk)" to see all 
properties.

Controller Initialized by Dynamic System Model

Controller Initialized by Dynamic System Model

Create a tunable two-degree-of-freedom PI controller. Use a two-input, one-output tf model to initialize the parameters and other properties.

s = tf('s');
Kp = 10;
Ki = 0.1;
b = 0.7;
sys = [(b*Kp + Ki/s), (-Kp - Ki/s)];
blk = tunablePID2('PI2dof',sys)
blk =

  Parametric continuous-time 2-DOF PID controller "PI2dof" with equation:

                       1 
  u = Kp (b*r-y) + Ki --- (r-y)
                       s 

  where r,y are the controller inputs and Kp, Ki, b are tunable gains.

Type "showBlockValue(blk)" to see the current value and "get(blk)" to see all 
properties.

blk takes initial parameter values from sys.

If sys is a discrete-time system, blk takes the value of properties, such as Ts and IFormula, from sys.

Controller with Named Inputs and Output

Controller with Named Inputs and Output

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

blk = tunablePID2('pidblock','pid');   
blk.InputName = {'reference','measurement'};     
blk.OutputName = {'control'};

blk.InputName is a cell array containing two names, because a two-degree-of-freedom PID controller has two inputs.

Tips

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

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

Version History

Introduced in R2016a

expand all