# ltiblock.pid2

Tunable two-degree-of-freedom PID controller

## Syntax

`blk = ltiblock.pid2(name,type)blk = ltiblock.pid2(name,type,Ts)blk = ltiblock.pid2(name,sys)`

## Description

Model object for creating tunable two-degree-of-freedom PID controllers. `ltiblock.pid2` 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 Robust Control Toolbox™ tuning commands such as `systune`, `looptune`, or `hinfstruct`.

`ltiblock.pid2` is part of the family of parametric Control Design Blocks. Other parametric Control Design Blocks include `ltiblock.gain`, `ltiblock.ss`, and `ltiblock.tf`.

## Construction

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

$u={K}_{p}\left(br-y\right)+\frac{{K}_{i}}{s}\left(r-y\right)+\frac{{K}_{d}s}{1+{T}_{f}s}\left(cr-y\right).$

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 string `type` sets the controller type by fixing some of these values to zero (see Input Arguments).

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

$u={K}_{p}\left(br-y\right)+{K}_{i}IF\left(z\right)\left(r-y\right)+\frac{{K}_{d}}{{T}_{f}+DF\left(z\right)}\left(cr-y\right).$

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 = ltiblock.pid2(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

`name`

PID controller `Name`, specified as a string. (See Properties.)

`type`

Controller type, specified as a string. Specifying a controller type fixes up to three of the PID controller parameters. `type` can take the following values:

StringController TypeEffect on PID Parameters
`'P'`Proportional only`Ki` and `Kd` are fixed to zero; `Tf` is fixed to 1; `Kp` is free
`'PI'`Proportional-integral`Kd` is fixed to zero; `Tf` is fixed to 1; `Kp` and `Ki` are free
`'PD'`Proportional-derivative with first-order filter on derivative action`Ki` is fixed to zero; `Kp`, `Kd`, and `Tf` are free
`'PID'`Proportional-integral-derivative with first-order filter on derivative action`Kp`, `Ki`, `Kd`, and `Tf` are free

`Ts`

Sample time, specified as a scalar.

`sys`

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

## Properties

`Kp,Ki,Kd,Tf,b,c`

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
`Value`Current 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.
`Maximum`Maximum 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` object reference page.

`IFormula, DFormula`

Strings setting the discrete integrator formulas IF(z) and DF(z) for the integral and derivative terms, respectively. `IFormula` and `DFormula` can have the following values:

StringIF(z) or DF(z) Formula
`'ForwardEuler'`

$\frac{{T}_{s}}{z-1}$

`'BackwardEuler'`

$\frac{{T}_{s}z}{z-1}$

`'Trapezoidal'`

$\frac{{T}_{s}}{2}\frac{z+1}{z-1}$

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. To denote a discrete-time model with unspecified sample time, set ```Ts = -1```.

Changing this property does not discretize or resample the model. Use `c2d` and `d2c` to convert between continuous- and discrete-time representations. Use `d2d` to change the sample time of a discrete-time system.

Default: `0` (continuous time)

`TimeUnit`

String representing the unit of the time variable. This property specifies the units for the time variable, the sample time `Ts`, and any time delays in the model. Use any 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 names. Set `InputName` to a string for single-input model. For a multi-input model, set `InputName` to a cell array of strings.

Alternatively, use automatic vector expansion to assign input names for multi-input models. For example, if `sys` is a two-input model, enter:

`sys.InputName = 'controls';`

The input names automatically expand to `{'controls(1)';'controls(2)'}`.

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

Input channel names have several uses, including:

• Identifying channels on model display and plots

• Extracting subsystems of MIMO systems

• Specifying connection points when interconnecting models

Default: Empty string `''` for all input channels

`InputUnit`

Input channel units. Use `InputUnit` to keep track of input signal units. For a single-input model, set `InputUnit` to a string. For a multi-input model, set `InputUnit` to a cell array of strings. `InputUnit` has no effect on system behavior.

Default: Empty string `''` for all input channels

`InputGroup`

Input channel groups. The `InputGroup` property lets you assign the input channels of MIMO systems into groups and refer to each group by name. Specify input groups as a structure. In this structure, field names are the group names, and field values are the input channels belonging to each group. For example:

```sys.InputGroup.controls = [1 2]; sys.InputGroup.noise = [3 5];```

creates input groups named `controls` and `noise` that include input channels 1, 2 and 3, 5, respectively. You can then extract the subsystem from the `controls` inputs to all outputs using:

`sys(:,'controls')`

Default: Struct with no fields

`OutputName`

Output channel names. Set `OutputName` to a string for single-output model. For a multi-output model, set `OutputName` to a cell array of strings.

Alternatively, use automatic vector expansion to assign output names for multi-output models. For example, if `sys` is a two-output model, enter:

`sys.OutputName = 'measurements';`

The output names automatically expand to `{'measurements(1)';'measurements(2)'}`.

You can use the shorthand notation `y` to refer to the `OutputName` property. For example, `sys.y` is equivalent to `sys.OutputName`.

Output channel names have several uses, including:

• Identifying channels on model display and plots

• Extracting subsystems of MIMO systems

• Specifying connection points when interconnecting models

Default: Empty string `''` for all output channels

`OutputUnit`

Output channel units. Use `OutputUnit` to keep track of output signal units. For a single-output model, set `OutputUnit` to a string. For a multi-output model, set `OutputUnit` to a cell array of strings. `OutputUnit` has no effect on system behavior.

Default: Empty string `''` for all output channels

`OutputGroup`

Output channel groups. The `OutputGroup` property lets you assign the output channels of MIMO systems into groups and refer to each group by name. Specify output groups as a structure. In this structure, field names are the group names, and field values are the output channels belonging to each group. For example:

```sys.OutputGroup.temperature = [1]; sys.InputGroup.measurement = [3 5];```

creates output groups named `temperature` and `measurement` that include output channels 1, and 3, 5, respectively. You can then extract the subsystem from all inputs to the `measurement` outputs using:

`sys('measurement',:)`

Default: Struct with no fields

`Name`

System name. Set `Name` to a string to label the system.

Default: `''`

`Notes`

Any text that you want to associate with the system. Set `Notes` to a string or a cell array of strings.

Default: `{}`

`UserData`

Any type of data you wish to associate with system. Set `UserData` to any MATLAB® data type.

Default: `[]`

## Examples

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 = ltiblock.pid2('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

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 = ltiblock.pid2('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

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

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

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

collapse all

### 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 `ltiblock.pid2` 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.