# pid2

2-DOF PID controller in parallel form

## Description

Use `pid2`

to create parallel-form, two-degree-of-freedom (2-DOF)
proportional-integral-derivative (PID) controller model objects, or to convert dynamic system models to parallel 2-DOF PID controller
form.

2-DOF PID controllers include setpoint weighting on the proportional and derivative terms. A 2-DOF PID controller can achieve fast disturbance rejection without significant increase of overshoot in setpoint tracking. 2-DOF PID controllers are also useful to mitigate the influence of changes in the reference signal on the control signal. The following illustration shows a typical control architecture using a 2-DOF PID controller.

The `pid2`

controller model object can represent parallel-form PID
controllers in continuous time or discrete time.

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

Discrete time — $$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)$$

Here:

*b*is the setpoint weighting on the proportional term.*c*is the setpoint weighting on the derivative term.*K*is the proportional gain._{p}*K*is the integral gain._{i}*K*is the derivative gain._{d}*T*is the first-order derivative filter time constant._{f}*IF*(*z*) is the integrator method for computing the integral in the discrete-time controller.*DF*(*z*) is the integrator method for computing the derivative filter in the discrete-time controller.

You can then combine this object with other components of a control architecture, such as the plant, actuators, and sensors to represent your control system. For more information, see Control System Modeling with Model Objects.

You can create a PID controller model object by either specifying the controller
parameters directly, or by converting a model of another type (such as a transfer function
model `tf`

) to PID controller form.

You can also use `pid2`

to create generalized state-space (`genss`

) models or uncertain state-space (`uss`

(Robust Control Toolbox)) models.

## Creation

You can obtain `pid2`

controller models in one of the following
ways.

Create a model using the

`pid2`

function.Use the

`pidtune`

function to tune PID controllers for a plant model. Specify a 2-DOF PID controller type in the`type`

argument of the`pidtune`

function to obtain a parallel-form 2-DOF PID controller. For example:`sys = zpk([],[-1 -1 -1],1); C2 = pidtune(sys,'PID2');`

Interactively tune the PID controller for a plant model using:

The Tune PID Controller Live Editor task.

The PID Tuner app.

### Syntax

### Description

### Input Arguments

### Output Arguments

## Properties

## Object Functions

The following lists contain a representative subset of the functions you can use with `pid2`

models. In general, any function applicable to Dynamic System Models is applicable to a `pid2`

object.

## Examples

## Tips

To break a 2-DOF controller into two SISO control components, such as a feedback controller and a feedforward controller, use

`getComponents`

.Create arrays of

`pid2`

controller objects by:Specifying array values for one or more of the coefficients

`Kp`

,`Ki`

,`Kd`

,`Tf`

,`b`

, and`c`

.Specifying an array of dynamic systems

`sys`

to convert to`pid2`

controller objects.Using

`stack`

to build arrays from individual controllers or smaller arrays.Passing an array of plant models to

`pidtune`

.

In an array of

`pid2`

controllers, each controller must have the same sample time`Ts`

and discrete integrator formulas`IFormula`

and`DFormula`

.To create or convert to a standard-form controller, use

`pidstd2`

. Standard form expresses the controller actions in terms of an overall proportional gain*K*, integral and derivative times_{p}*T*and_{i}*T*, and filter divisor_{d}*N*. For example, the relationship between the inputs and output of a continuous-time standard-form 2-DOF PID controller is given by:$$u={K}_{p}\left[\left(br-y\right)+\frac{1}{{T}_{i}s}\left(r-y\right)+\frac{{T}_{d}s}{\frac{{T}_{d}}{N}s+1}\left(cr-y\right)\right]$$

There are two ways to discretize a continuous-time

`pid2`

controller:Use the

`c2d`

command.`c2d`

computes new parameter values for the discretized controller. The discrete integrator formulas of the discretized controller depend upon the`c2d`

discretization method you use, as shown in the following table.`c2d`

Discretization Method`IFormula`

`DFormula`

`'zoh'`

`ForwardEuler`

`ForwardEuler`

`'foh'`

`Trapezoidal`

`Trapezoidal`

`'tustin'`

`Trapezoidal`

`Trapezoidal`

`'impulse'`

`ForwardEuler`

`ForwardEuler`

`'matched'`

`ForwardEuler`

`ForwardEuler`

For more information about

`c2d`

discretization methods, See the`c2d`

reference page. For more information about`IFormula`

and`DFormula`

, see Properties.If you require different discrete integrator formulas, you can discretize the controller by directly setting

`Ts`

,`IFormula`

, and`DFormula`

to the desired values. (See Discretize a Continuous-Time 2-DOF PID Controller.) However, this method does not compute new gain and filter-constant values for the discretized controller. Therefore, this method might yield a poorer match between the continuous- and discrete-time`pid2`

controllers than using`c2d`

.

## Version History

**Introduced in R2015b**