Discretetime or continuoustime twodegreeoffreedom PID controller
Simulink / Discrete
The Discrete PID Controller (2DOF) block implements a
twodegreeoffreedom PID controller (PID, PI, or PD). The block is identical to the
PID Controller
(2DOF) block with the Time domain parameter set to
Discretetime
.
The block generates an output signal based on the difference between a reference signal and a measured system output. The block computes a weighted difference signal for the proportional and derivative actions according to the setpoint weights (b and c) that you specify. The block output is the sum of the proportional, integral, and derivative actions on the respective difference signals, where each action is weighted according to the gain parameters P, I, and D. A firstorder pole filters the derivative action.
The block supports several controller types and structures. Configurable options in the block include:
Controller type (PID, PI, or PD) — See the Controller parameter.
Controller form (Parallel or Ideal) — See the Form parameter.
Time domain (discrete or continuous) — See the Time domain parameter.
Initial conditions and reset trigger — See the Source and External reset parameters.
Output saturation limits and builtin antiwindup mechanism — See the Limit output parameter.
Signal tracking for bumpless control transfer and multiloop control — See the Enable tracking mode parameter.
As you change these options, the internal structure of the block changes by activating different variant subsystems. (See Variant Subsystems.) To examine the internal structure of the block and its variant subsystems, rightclick the block and select Mask > Look Under Mask.
In one common implementation, the PID Controller block operates in the feedforward path of a feedback loop.
For a singleinput block that accepts an error signal (a difference between a setpoint and a system output), see Discrete PID Controller.
The PID controller coefficients and the setpoint weights are tunable either manually or automatically. Automatic tuning requires Simulink^{®} Control Design™ software. For more information about automatic tuning, see the Select tuning method parameter.
Ref
— Reference signalReference signal for plant to follow, as shown.
When the reference signal is a vector, the block acts separately on each signal, vectorizing the PID coefficients and producing a vector output signal of the same dimensions. You can specify the PID coefficients and some other parameters as vectors of the same dimensions as the input signal. Doing so is equivalent to specifying a separate PID controller for each entry in the input signal.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Port_1( y )
— Measured system outputFeedback signal for the controller, from the plant output.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
P
— Proportional gainProportional gain, provided from a source external to the block. External gain input is useful, for example, when you want to map a different PID parameterization to the PID gains of the block. You can also use external gain input to implement gainscheduled PID control. In gainscheduled control, you determine the PID coefficients by logic or other calculation in your model and feed them to the block.
To enable this port, set Controller parameters Source to external
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
I
— Integral gainIntegral gain, provided from a source external to the block. External gain input is useful, for example, when you want to map a different PID parameterization to the PID gains of the block. You can also use external gain input to implement gainscheduled PID control. In gainscheduled control, you determine the PID coefficients by logic or other calculation in your model and feed them to the block.
When you supply gains externally, time variations in the integral gain are also integrated. This result occurs because of the way the PID gains are implemented within the block. For details, see the Controller parameters Source parameter.
To enable this port, set Controller parameters Source to
external
, and set Controller to
a controller type that has integral action.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
D
— Derivative gainDerivative gain, provided from a source external to the block. External gain input is useful, for example, when you want to map a different PID parameterization to the PID gains of the block. You can also use external gain input to implement gainscheduled PID control. In gainscheduled control, you determine the PID coefficients by logic or other calculation in your model and feed them to the block.
When you supply gains externally, time variations in the derivative gain are also differentiated. This result occurs because of the way the PID gains are implemented within the block. For details, see the Controller parameters Source parameter.
To enable this port, set Controller parameters Source to
external
, and set Controller to
a controller type that has derivative action.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
N
— Filter coefficientDerivative filter coefficient, provided from a source external to the block. External coefficient input is useful, for example, when you want to map a different PID parameterization to the PID gains of the block. You can also use the external input to implement gainscheduled PID control. In gainscheduled control, you determine the PID coefficients by logic or other calculation in your model and feed them to the block.
To enable this port, set Controller parameters Source to
external
, and set Controller to a
controller type that has a filtered derivative.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
b
— Proportional setpoint weightProportional setpoint weight, provided from a source external to the block. External input is useful, for example, when you want to map a different PID parameterization to the PID gains of the block. You can also use the external input to implement gainscheduled PID control. In gainscheduled control, you determine the PID coefficients by logic or other calculation in your model and feed them to the block.
To enable this port, set Controller parameters Source to
external
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
c
— Derivative setpoint weightDerivative setpoint weight, provided from a source external to the block. External input is useful, for example, when you want to map a different PID parameterization to the PID gains of the block. You can also use the external input to implement gainscheduled PID control. In gainscheduled control, you determine the PID coefficients by logic or other calculation in your model and feed them to the block.
To enable this port, set Controller parameters Source to
external
, and set Controller to
a controller type that has derivative action.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Reset
— External reset triggerTrigger to reset the integrator and filter to their initial conditions. Use the
External reset parameter to specify what kind of signal
triggers a reset. The port icon indicates the trigger type specified in that parameter.
For example, the following illustration shows a continuoustime PID Controller (2DOF)
block with External reset set to
rising
.
When the trigger occurs, the block resets the integrator and filter to the initial conditions specified by the Integrator Initial condition and Filter Initial condition parameters or the I_{0} and D_{0} ports.
Note
To be compliant with the Motor Industry Software Reliability Association (MISRA^{®}) software standard, your model must use Boolean signals to drive the external reset ports of the PID controller block.
To enable this port, set External reset to any value other than none
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
 Boolean
I_{0}
— Integrator initial conditionIntegrator initial condition, provided from a source external to the block.
To enable this port, set Initial conditions Source to
external
, and set Controller to
a controller type that has integral action.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
D_{0}
— Filter initial conditionInitial condition of the derivative filter, provided from a source external to the block.
To enable this port, set Initial conditions Source to
external
, and set Controller to a
controller type that has derivative action.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
up
— Output saturation upper limitUpper limit of the block output, provided from a source external to the block. If the weighted sum of the proportional, integral, and derivative actions exceeds the value provided at this port, the block output is held at that value.
To enable this port, select Limit output and set the output
saturation Source to
external
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
lo
— Output saturation lower limitLower limit of the block output, provided from a source external to the block. If the weighted sum of the proportional, integral, and derivative actions goes below the value provided at this port, the block output is held at that value.
To enable this port, select Limit output and set the output saturation
Source to external
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
TR
— Tracking signalSignal for controller output to track. When signal tracking is active, the difference between the tracking signal and the block output is fed back to the integrator input. Signal tracking is useful for implementing bumpless control transfer in systems that switch between two controllers. It can also be useful to prevent block windup in multiloop control systems. For more information, see the Enable tracking mode parameter.
To enable this port, select the Enable tracking mode parameter.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
T_{DTI}
— Discreteintegrator timeDiscreteintegrator time, provided as a scalar to the block. You can use your own value of discretetime integrator sample time that defines the rate at which the block is going to be run either in Simulink or on external hardware. The value of the discretetime integrator time should match the average sampling rate of the external interrupts, when the block is used inside a conditionallyexecuted subsystem.
In other words, you can specify
Ts
for any of the integrator
methods below such that the value matches the
average sampling rate of the external interrupts.
In discrete time, the derivative term of the
controller transfer function is:
$$D\left[\frac{N}{1+N\alpha (z)}\right],$$
where α(z) depends on the integrator method you specify with this parameter.
Forward
Euler
$$\alpha (z)=\frac{{T}_{s}}{z1}.$$
Backward
Euler
$$\alpha (z)=\frac{{T}_{s}z}{z1}.$$
Trapezoidal
$$\alpha (z)=\frac{{T}_{s}}{2}\frac{z+1}{z1}.$$
For more information about discretetime integration, see the DiscreteTime Integrator block reference page. For more information on conditionally executed subsystems, see Conditionally Executed Subsystems Overview.
To enable this port, set Time
Domain to
Discretetime
and
select the PID Controller is inside a
conditionally executed subsystem
option.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
Port_1( u )
— Controller outputController output, generally based on a sum of the input signal, the integral of the input signal, and the derivative of the input signal, weighted by the setpoint weights and by the proportional, integral, and derivative gain parameters. A firstorder pole filters the derivative action. Which terms are present in the controller signal depends on what you select for the Controller parameter. The base controller transfer function for the current settings is displayed in the Compensator formula section of the block parameters and under the mask. Other parameters modify the block output, such as saturation limits specified by the Upper Limit and Lower Limit saturation parameters.
The controller output is a vector signal when any of the inputs is a vector signal. In that case, the block acts as N independent PID controllers, where N is the number of signals in the input vector.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Controller
— Controller typePID
(default)  PI
 PD
Specify which of the proportional, integral, and derivative terms are in the controller.
PID
Proportional, integral, and derivative action.
PI
Proportional and integral action only.
PD
Proportional and derivative action only.
Tip
The controller output for the current setting is displayed in the Compensator formula section of the block parameters and under the mask.
Block Parameter: Controller 
Type: string, character vector 
Values: "PID" , "PI" , "PD" 
Default: "PID" 
Form
— Controller structureParallel
(default)  Ideal
Specify whether the controller structure is parallel or ideal.
Parallel
The proportional, integral, and derivative gains P, I, and D, are applied independently. For example, for a continuoustime 2DOF PID controller in parallel form, the controller output u is:
$$u=P\left(bry\right)+I\frac{1}{s}\left(ry\right)+D\frac{N}{1+N\frac{1}{s}}\left(cry\right),$$
where r is the reference signal, y is the measured plant output signal, and b and c are the setpoint weights.
For a discretetime 2DOF controller in parallel form, the controller output is:
$$u=P\left(bry\right)+I\alpha \left(z\right)\left(ry\right)+D\frac{N}{1+N\beta \left(z\right)}\left(cry\right),$$
where the Integrator method and Filter method parameters determine α(z) and β(z), respectively.
Ideal
The proportional gain P acts on the sum of all actions. For example, for a continuoustime 2DOF PID controller in ideal form, the controller output is:
$$u=P\left[\left(bry\right)+I\frac{1}{s}\left(ry\right)+D\frac{N}{1+N\frac{1}{s}}\left(cry\right)\right].$$
For a discretetime 2DOF PID controller in ideal form, the transfer function is:
$$u=P\left[\left(bry\right)+I\alpha \left(z\right)\left(ry\right)+D\frac{N}{1+N\beta \left(z\right)}\left(cry\right)\right],$$
where the Integrator method and Filter method parameters determine α(z) and β(z), respectively.
Tip
The controller output for the current settings is displayed in the Compensator formula section of the block parameters and under the mask.
Block Parameter: Controller 
Type: string, character vector 
Values: "Parallel" , "Ideal" 
Default: "Parallel" 
Time domain
— Specify discretetime or continuoustime controllerDiscretetime
(default)  Continuoustime
When you select Discretetime
, it is
recommended that you specify an explicit sample time for the block. See the
Sample time (1 for inherited) parameter. Selecting
Discretetime
also enables the
Integrator method, and Filter
method parameters.
When the PID Controller block is in a model with
synchronous state control (see the State Control (HDL Coder) block), you
cannot select Continuoustime
.
Note
The PID Controller (2DOF) and Discrete PID Controller (2DOF) blocks are identical except for the default value of this parameter.
Block Parameter:
TimeDomain 
Type: string, character vector 
Values:
"Continuoustime" ,
"Discretetime" 
Default:
"Discretetime" 
PID Controller is inside a conditionally executed subsystem
— Enable the discreteintegrator time portoff
(default)  on
For discretetime PID controllers, enable the discretetime integrator port to use
your own value of discretetime integrator sample time. To ensure proper integration,
Use the T_{DTI}
port to provide a scalar value
of Δt for accurate discretetime integration.
To enable this parameter, set Time Domain to
Discretetime
.
Block Parameter:
UseExternalTs 
Type: string, character vector 
Values:
"on" , "off" 
Default:
"off" 
Sample time (1 for inherited)
— Discrete interval between samplesSpecify a sample time by entering a positive scalar value, such as 0.1. The default discrete sample time of –1 means that the block inherits its sample time from upstream blocks. However, it is recommended that you set the controller sample time explicitly, especially if you expect the sample time of upstream blocks to change. The effect of the controller coefficients P, I, D, and N depend on the sample time. Thus, for a given set of coefficient values, changing the sample time changes the performance of the controller.
See Specify Sample Time for more information.
To implement a continuoustime controller, set Time domain to Continuoustime
.
Tip
If you want to run the block with an externally specified or variable sample time, set this parameter to –1 and put the block in a Triggered Subsystem. Then, trigger the subsystem at the desired sample time.
To enable this parameter, set Time domain to Discretetime
.
Block Parameter: SampleTime 
Type: scalar 
Values: 1 , positive scalar 
Default: 1 
Integrator method
— Method for computing integral in discretetime controllerForward Euler
(default)  Backward Euler
 Trapezoidal
In discrete time, the integral term of the controller transfer function is Ia(z), where a(z) depends on the integrator method you specify with this parameter.
Forward Euler
Forward rectangular (lefthand) approximation,
$$\alpha (z)=\frac{{T}_{s}}{z1}.$$
This method is best for small sampling times, where the Nyquist limit is large compared to the bandwidth of the controller. For larger sampling times, the Forward Euler
method can result in instability, even when discretizing a system that is stable in continuous time.
Backward Euler
Backward rectangular (righthand) approximation,
$$\alpha (z)=\frac{{T}_{s}z}{z1}.$$
An advantage of the Backward Euler
method is that discretizing a stable continuoustime system using this method always yields a stable discretetime result.
Trapezoidal
Bilinear approximation,
$$\alpha (z)=\frac{{T}_{s}}{2}\frac{z+1}{z1}.$$
An advantage of the Trapezoidal
method is that discretizing a stable continuoustime system using this method always yields a stable discretetime result. Of all available integration methods, the Trapezoidal
method yields the closest match between frequencydomain properties of the discretized system and the corresponding continuoustime system.
Tip
The controller formula for the current setting is displayed in the Compensator formula section of the block parameters and under the mask.
For more information about discretetime integration, see the DiscreteTime Integrator block reference page.
To enable this parameter, set Time Domain to Discretetime
and set Controller to a controller type with integral action.
Block Parameter: IntegratorMethod 
Type: string, character vector 
Values: "Forward Euler" , "Backward Euler" , "Trapezoidal" 
Default: "Forward Euler" 
Filter method
— Method for computing derivative in discretetime controllerForward Euler
(default)  Backward Euler
 Trapezoidal
In discrete time, the derivative term of the controller transfer function is:
$$D\left[\frac{N}{1+N\alpha (z)}\right],$$
where α(z) depends on the filter method you specify with this parameter.
Forward Euler
Forward rectangular (lefthand) approximation,
$$\alpha (z)=\frac{{T}_{s}}{z1}.$$
This method is best for small sampling times, where the Nyquist limit is large compared to the bandwidth of the controller. For larger sampling times, the Forward Euler
method can result in instability, even when discretizing a system that is stable in continuous time.
Backward Euler
Backward rectangular (righthand) approximation,
$$\alpha (z)=\frac{{T}_{s}z}{z1}.$$
An advantage of the Backward Euler
method is that discretizing a stable continuoustime system using this method always yields a stable discretetime result.
Trapezoidal
Bilinear approximation,
$$\alpha (z)=\frac{{T}_{s}}{2}\frac{z+1}{z1}.$$
An advantage of the Trapezoidal
method is that discretizing a stable continuoustime system using this method always yields a stable discretetime result. Of all available integration methods, the Trapezoidal
method yields the closest match between frequencydomain properties of the discretized system and the corresponding continuoustime system.
Tip
The controller formula for the current setting is displayed in the Compensator formula section of the block parameters and under the mask.
For more information about discretetime integration, see the DiscreteTime Integrator block reference page.
To enable this parameter, set Time Domain to
Discretetime
and
enable Use filtered
derivative.
Block Parameter: FilterMethod 
Type: string, character vector 
Values: "Forward Euler" , "Backward Euler" , "Trapezoidal" 
Default: "Forward Euler" 
Source
— Source for controller gains and filter coefficientinternal
Specify the controller gains, filter coefficient, and setpoint weights using the block parameters P, I, D, N, b, and c respectively.
external
Specify the PID gains, filter coefficient, and setpoint weights externally using block inputs. An additional input port appears on the block for each parameter that is required for the current controller type.
Enabling external inputs for the parameters allows you to compute their values externally to the block and provide them to the block as signal inputs.
External input is useful, for example, when you want to map a different PID parameterization to the PID gains of the block. You can also use external gain input to implement gainscheduled PID control. In gainscheduled control, you determine the PID gains by logic or other calculation in your model and feed them to the block.
When you supply gains externally, time variations in the integral and derivative gain values are integrated and differentiated, respectively. The derivative setpoint weight c is also differentiated. This result occurs because in both continuous time and discrete time, the gains are applied to the signal before integration or differentiation. For example, for a continuoustime PID controller with external inputs, the integrator term is implemented as shown in the following illustration.
Within the block, the input signal u is multiplied by the externally supplied integrator gain, I, before integration. This implementation yields:
$${u}_{i}={\displaystyle \int \left(ry\right)I\text{\hspace{0.17em}}dt}.$$
Thus, the integrator gain is included in the integral. Similarly, in the derivative term of the block, multiplication by the derivative gain precedes the differentiation, which causes the derivative gain D and the derivative setpoint weight c to be differentiated.
Block Parameter: ControllerParametersSource 
Type: string, character vector 
Values: "internal" , "external" 
Default: "internal" 
Proportional (P)
— Proportional gainSpecify a finite, real gain value for the proportional gain. When Controller form is:
Parallel
— Proportional action is independent of the integral and derivative actions. For example, for a continuoustime 2DOF PID controller in parallel form, the controller output u is:
$$u=P\left(bry\right)+I\frac{1}{s}\left(ry\right)+D\frac{N}{1+N\frac{1}{s}}\left(cry\right),$$
where r is the reference signal, y is the measured plant output signal, and b and c are the setpoint weights.
For a discretetime 2DOF controller in parallel form, the controller output is:
$$u=P\left(bry\right)+I\alpha \left(z\right)\left(ry\right)+D\frac{N}{1+N\beta \left(z\right)}\left(cry\right),$$
where the Integrator method and Filter method parameters determine α(z) and β(z), respectively.
Ideal
— The proportional gain multiples the integral and derivative terms. For example, for a continuoustime 2DOF PID controller in ideal form, the controller output is:
$$u=P\left[\left(bry\right)+I\frac{1}{s}\left(ry\right)+D\frac{N}{1+N\frac{1}{s}}\left(cry\right)\right].$$
For a discretetime 2DOF PID controller in ideal form, the transfer function is:
$$u=P\left[\left(bry\right)+I\alpha \left(z\right)\left(ry\right)+D\frac{N}{1+N\beta \left(z\right)}\left(cry\right)\right],$$
where the Integrator method and Filter method parameters determine α(z) and β(z), respectively.
Tunable: Yes
To enable this parameter, set the Controller parameters Source to internal
.
Block Parameter: P 
Type: scalar, vector 
Default: 1 
Integral (I)
— Integral gainSpecify a finite, real gain value for the integral gain.
Tunable: Yes
To enable this parameter, in the Main tab, set the controllerparameters
Source to internal
, and set
Controller to a type that has integral action.
Block Parameter: I 
Type: scalar, vector 
Default: 1 
Derivative (D)
— Derivative gainSpecify a finite, real gain value for the derivative gain.
Tunable: Yes
To enable this parameter, in the Main tab, set the controllerparameters
Source to internal
, and set
Controller to PID
or
PD
.
Block Parameter: D 
Type: scalar, vector 
Default: 0 
Use filtered derivative
— Apply filter to derivative termon
(default)  off
For discretetime PID controllers only, clear this option to replace the filtered derivative with an unfiltered discretetime differentiator. When you do so, the derivative term of the controller output becomes:
$$D\frac{z1}{z{T}_{s}}\left(cry\right).$$
For continuoustime PID controllers, the derivative term is always filtered.
To enable this parameter, set Time domain to Discretetime
, and set Controller to a type that has a derivative term.
Block Parameter: UseFilter 
Type: string, character vector 
Values: "on" , "off" 
Default: "on" 
Filter coefficient (N)
— Derivative filter coefficientSpecify a finite, real gain value for the filter coefficient. The filter coefficient determines the pole location of the filter in the derivative action of the block. The location of the filter pole depends on the Time domain parameter.
When Time domain is
Continuoustime
, the pole
location is s = N
.
When Time domain is
Discretetime
, the pole
location depends on the Filter method
parameter.
Filter Method  Location of Filter Pole 

Forward
Euler  $${z}_{pole}=1N{T}_{s}$$ 
Backward
Euler  $${z}_{pole}=\frac{1}{1+N{T}_{s}}$$ 
Trapezoidal  $${z}_{pole}=\frac{1N{T}_{s}/2}{1+N{T}_{s}/2}$$ 
The block does not support N = Inf
(ideal unfiltered derivative). When the Time domain is Discretetime
, you can clear Use filtered derivative to remove the derivative filter.
Tunable: Yes
To enable this parameter, in the Main tab, set the controllerparameters
Source to
internal
and set
Controller to
PID
or
PD
.
Block Parameter: N 
Type: scalar, vector 
Default: 100 
Setpoint weight (b)
— Proportional setpoint weightSetpoint weight on the proportional term of the controller. The proportional term of a 2DOF controller output is P(br–y), where r is the reference signal and y is the measured plant output. Setting b to 0 eliminates proportional action on the reference signal, which can reduce overshoot in the system response to step changes in the setpoint. Changing the relative values of b and c changes the balance between disturbance rejection and setpoint tracking.
Tunable: Yes
To enable this parameter, in the Main tab, set the controllerparameters
Source to internal
.
Block Parameter: b 
Type: scalar, vector 
Default: 1 
Setpoint weight (c)
— Derivative setpoint weightSetpoint weight on the derivative term of the controller. The derivative term of a 2DOF controller acts on cr–y, where r is the reference signal and y is the measured plant output. Thus, setting c to 0 eliminates derivative action on the reference signal, which can reduce transient response to step changes in the setpoint. Setting c to 0 can yield a controller that achieves both effective disturbance rejection and smooth setpoint tracking without excessive transient response. Changing the relative values of b and c changes the balance between disturbance rejection and setpoint tracking.
Tunable: Yes
To enable this parameter, in the Main tab, set the controllerparameters
Source to internal
and set
Controller to a type that has derivative action.
Block Parameter: c 
Type: scalar, vector 
Default: 1 
Select tuning method
— Tool for automatic tuning of controller coefficientsTransfer Function Based (PID Tuner App)
(default)  Frequency Response Based
If you have Simulink Control Design software, you can automatically tune the PID coefficients when they are internal to the block. To do so, use this parameter to select a tuning tool, and click Tune.
Transfer Function Based (PID Tuner App)
Use PID Tuner, which lets you interactively tune PID coefficients while examining relevant system responses to validate performance. PID Tuner can tune all the coefficients P, I, D, and N, and the setpoint coefficients b and c. By default, PID Tuner works with a linearization of your plant model. For models that cannot be linearized, you can tune PID coefficients against a plant model estimated from simulated or measured response data. For more information, see Design TwoDegreeofFreedom PID Controllers (Simulink Control Design).
Frequency Response Based
Use Frequency Response Based PID Tuner, which tunes PID controller coefficients based on frequencyresponse estimation data obtained by simulation. This tuning approach is especially useful for plants that are not linearizable or that linearize to zero. Frequency Response Based PID Tuner tunes the coefficients P, I, D, and N, but does not tune the setpoint coefficients b and c. For more information, see Design PID Controller from Plant FrequencyResponse Data (Simulink Control Design).
Both of these tuning methods assume a singleloop control configuration. Simulink Control Design software includes other tuning approaches that suit more complex configurations. For information about other ways to tune a PID Controller block, see Choose a Control Design Approach (Simulink Control Design).
To enable this parameter, in the Main tab, set the
controllerparameters Source to
internal
.
Enable zerocrossing detection
— Detect zero crossings on reset and on entering or leaving a saturation stateon
(default)  off
Zerocrossing detection can accurately locate signal discontinuities without resorting to excessively small time steps that can lead to lengthy simulation times. If you select Limit output or activate External reset in your PID Controller block, activating zerocrossing detection can reduce computation time in your simulation. Selecting this parameter activates zerocrossing detection:
At initialstate reset
When entering an upper or lower saturation state
When leaving an upper or lower saturation state
For more information about zerocrossing detection, see ZeroCrossing Detection.
Block Parameter: ZeroCross 
Type: string, character vector 
Values: "on" , "off" 
Default: "on" 
Source
— Source for integrator and derivative initial conditionsinternal
(default)  external
Simulink uses initial conditions to initialize the integrator and derivativefilter (or the unfiltered derivative) output at the start of a simulation or at a specified trigger event. (See the External reset parameter.) These initial conditions determine the initial block output. Use this parameter to select how to supply the initial condition values to the block.
internal
Specify the initial conditions using the Integrator Initial condition and Filter Initial condition parameters. If Use filtered derivative is not selected, use the Differentiator parameter to specify the initial condition for the unfiltered differentiator instead of a filter initial condition.
external
Specify the initial conditions externally using block inputs. Additional input ports I_{o} and D_{o} appear on the block. If Use filtered derivative is not selected, supply the initial condition for the unfiltered differentiator at D_{o} instead of a filter initial condition.
Block Parameter:
InitialConditionSource 
Type: string, character vector 
Values:
"internal" , "external" 
Default:
"internal" 
Integrator
— Integrator initial conditionSimulink uses the integrator initial condition to initialize the integrator at the start of a simulation or at a specified trigger event (see External reset). The integrator initial condition and the filter initial condition determine the initial output of the PID controller block.
The integrator initial condition cannot be NaN
or Inf
.
To use this parameter, in the Initialization tab, set
Source to internal
, and set
Controller to a type that has integral action.
Block Parameter: InitialConditionForIntegrator 
Type: scalar, vector 
Default: 0 
Filter
— Filter initial conditionSimulink uses the filter initial condition to initialize the derivative filter at the start of a simulation or at a specified trigger event (see External reset). The integrator initial condition and the filter initial condition determine the initial output of the PID controller block.
The filter initial condition cannot be NaN
or Inf
.
To use this parameter, in the Initialization tab, set
Source to internal
, and use a
controller that has a derivative filter.
Block Parameter: InitialConditionForFilter 
Type: scalar, vector 
Default: 0 
Differentiator
— Initial condition for unfiltered derivativeWhen you use an unfiltered derivative, Simulink uses this parameter to initialize the differentiator at the start of a simulation or at a specified trigger event (see External reset). The integrator initial condition and the derivative initial condition determine the initial output of the PID controller block.
The derivative initial condition cannot be NaN
or Inf
.
To use this parameter, set Time domain to Discretetime
, clear the Use filtered derivative check box, and in the Initialization tab, set Source to internal
.
Block Parameter: DifferentiatorICPrevScaledInput 
Type: scalar, vector 
Default: 0 
Initial condition setting
— Location at which initial condition is appliedState (most efficient)
(default)  Output
Use this parameter to specify whether to apply the Integrator Initial condition and Filter Initial condition parameter to the corresponding block state or output. You can change this parameter at the command line only, using set_param
to set the InitialConditionSetting
parameter of the block.
State (most efficient)
Use this option in all situations except when the block is in a triggered subsystem or a functioncall subsystem and simplified initialization mode is enabled.
Output
Use this option when the block is in a triggered subsystem or a functioncall subsystem and simplified initialization mode is enabled.
For more information about the Initial condition setting parameter, see the DiscreteTime Integrator block.
This parameter is only accessible through programmatic use.
Block Parameter: InitialConditionSetting 
Type: string, character vector 
Values: "state" , "output" 
Default: "state" 
External reset
— Trigger for resetting integrator and filter valuesnone
(default)  rising
 falling
 either
 level
Specify the trigger condition that causes the block to reset the integrator and filter to initial conditions. (If Use filtered derivative is not selected, the trigger resets the integrator and differentiator to initial conditions.) Selecting any option other than none
enables the Reset port on the block for the external reset signal.
none
The integrator and filter (or differentiator) outputs are set to initial conditions at the beginning of simulation, and are not reset during simulation.
rising
Reset the outputs when the reset signal has a rising edge.
falling
Reset the outputs when the reset signal has a falling edge.
either
Reset the outputs when the reset signal either rises or falls.
level
Reset the outputs when the reset signal either:
Is nonzero at the current time step
Changes from nonzero at the previous time step to zero at the current time step
This option holds the outputs to the initial conditions while the reset signal is nonzero.
To enable this parameter, set Controller to a type that has derivative or integral action.
Block Parameter: ExternalReset 
Type: string, character vector 
Values:
"none" ,
"rising" ,
"falling" ,
"either" ,"level" 
Default: "none" 
Ignore reset when linearizing
— Force linearization to ignore resetoff
(default)  on
Select to force Simulink and Simulink Control Design linearization commands to ignore any reset mechanism specified in the External reset parameter. Ignoring reset states allows you to linearize a model around an operating point even if that operating point causes the block to reset.
Block Parameter: IgnoreLimit 
Type: string, character vector 
Values: "off" , "on" 
Default: "off" 
Enable tracking mode
— Activate signal trackingoff
(default)  on
Signal tracking lets the block output follow a tracking signal that you provide at the TR port. When signal tracking is active, the difference between the tracking signal and the block output is fed back to the integrator input with a gain Kt
, specified by the Tracking gain (Kt) parameter. Signal tracking has several applications, including bumpless control transfer and avoiding windup in multiloop control structures.
Use signal tracking to achieve bumpless control transfer in systems that switch between two controllers. Suppose you want to transfer control between a PID controller and another controller. To do so, connecting the controller output to the TR input as shown in the following illustration.
For more information, see Bumpless Control Transfer with a TwoDegreeofFreedom PID Controller.
Use signal tracking to prevent block windup in multiloop control approaches. For an example illustrating this approach with a 1DOF PID controller, see Prevent Block Windup in Multiloop Control.
To enable this parameter, set Controller to a type that has integral action.
Block Parameter: TrackingMode 
Type: string, character vector 
Values: "off" , "on" 
Default: "off" 
Tracking coefficient (Kt)
— Gain of signaltracking feedback loopWhen you select Enable tracking mode, the difference between the signal TR and the block output is fed back to the integrator input with a gain Kt
. Use this parameter to specify the gain in that feedback loop.
To enable this parameter, select Enable tracking mode.
Block Parameter: Kt 
Type: scalar 
Default: 1 
Limit Output
— Limit block output to specified saturation valuesoff
(default)  on
Activating this option limits the block output, so that you do not need a separate Saturation block after the controller. It also allows you to activate the antiwindup mechanism built into the block (see the Antiwindup method parameter). Specify the output saturation limits using the Lower limit and Upper limit parameters. You can also specify the saturation limits externally as block input ports.
Block Parameter: LimitOutput 
Type: string, character vector 
Values: "off" , "on" 
Default: "off" 
Source
— Source for output saturation limitsUse this parameter to specify how to supply the upper and lower saturation limits of the block output.
internal
Specify the output saturation limits using the Upper limit and Lower limit parameters.
external
Specify the output saturation limits externally using block input ports. The additional input ports up and lo appear on the block. You can use the input ports to implement the upper and lower output saturation limits determined by logic or other calculations in the Simulink model and passed to the block.
Block Parameter:
SatLimitsSource 
Type: string, character vector 
Values:
"internal" , "external" 
Default:
"internal" 
Upper limit
— Upper saturation limit for block outputInf
(default)  scalarSpecify the upper limit for the block output. The block output is held at the Upper saturation limit whenever the weighted sum of the proportional, integral, and derivative actions exceeds that value.
To enable this parameter, select Limit output.
Block Parameter: UpperSaturationLimit 
Type: scalar 
Default: Inf 
Lower limit
— Lower saturation limit for block outputInf
(default)  scalarSpecify the lower limit for the block output. The block output is held at the Lower saturation limit whenever the weighted sum of the proportional, integral, and derivative actions goes below that value.
To enable this parameter, select Limit output.
Block Parameter: LowerSaturationLimit 
Type: scalar 
Default: Inf 
Ignore saturation when linearizing
— Force linearization to ignore output limitsoff
(default)  on
Force Simulink and Simulink Control Design linearization commands to ignore block output limits specified in the Upper limit and Lower limit parameters. Ignoring output limits allows you to linearize a model around an operating point even if that operating point causes the block to exceed the output limits.
To enable this parameter, select the Limit output parameter.
Block Parameter: LinearizeAsGain 
Type: string, character vector 
Values: "off" , "on" 
Default: "off" 
Antiwindup method
— Integrator antiwindup method none
(default)  backcalculation
 clamping
When you select Limit output and the weighted sum of the controller components exceeds the specified output limits, the block output holds at the specified limit. However, the integrator output can continue to grow (integrator windup), increasing the difference between the block output and the sum of the block components. In other words, the internal signals in the block can be unbounded even if the output appears bounded by saturation limits. Without a mechanism to prevent integrator windup, two results are possible:
If the sign of the signal entering the integrator never changes, the integrator continues to integrate until it overflows. The overflow value is the maximum or minimum value for the data type of the integrator output.
If the sign of the signal entering the integrator changes once the weighted sum has grown beyond the output limits, it can take a long time to unwind the integrator and return the weighted sum within the block saturation limit.
In either case, controller performance can suffer. To combat the effects of windup without an antiwindup mechanism, it may be necessary to detune the controller (for example, by reducing the controller gains), resulting in a sluggish controller. To avoid this problem, activate an antiwindup mechanism using this parameter.
none
Do not use an antiwindup mechanism.
backcalculation
Unwind the integrator when the block output saturates by feeding back to the integrator the difference between the saturated and unsaturated control signal. The following diagram represents the backcalculation feedback circuit for a continuoustime controller. To see the actual feedback circuit for your controller configuration, rightclick on the block and select Mask > Look Under Mask.
Use the Backcalculation coefficient (Kb) parameter
to specify the gain of the antiwindup feedback circuit. It is usually
satisfactory to set Kb = I
, or for controllers with
derivative action, Kb = sqrt(I*D)
. Backcalculation can
be effective for plants with relatively large dead time
[1].
clamping
Integration stops when the sum of the block components exceeds the output limits and the integrator output and block input have the same sign. Integration resumes when the sum of the block components exceeds the output limits and the integrator output and block input have opposite sign. Clamping is sometimes referred to as conditional integration.
Clamping can be useful for plants with relatively small dead times, but can yield a poor transient response for large dead times [1].
To enable this parameter, select the Limit output parameter.
Block Parameter:
AntiWindupMode 
Type: string, character vector 
Values:
"none" ,
"backcalculation" ,"clamping" 
Default:
"none" 
Backcalculation coefficient (Kb)
— Gain coefficient of antiwindup feedback loopThe backcalculation
antiwindup method unwinds the integrator when the
block output saturates. It does so by feeding back to the integrator the difference
between the saturated and unsaturated control signal. Use the Backcalculation
coefficient (Kb) parameter to specify the gain of the antiwindup
feedback circuit. For more information, see the Antiwindup method
parameter.
To enable this parameter, select the Limit output parameter, and set the
Antiwindup method parameter to
backcalculation
.
Block Parameter: Kb 
Type: scalar 
Default: 1 
The parameters in this tab are primarily of use in fixedpoint code generation using FixedPoint Designer™. They define how numeric quantities associated with the block are stored and processed when you generate code.
If you need to configure data types for fixedpoint code generation, click Open FixedPoint Tool and use that tool to configure the rest of the parameters in the tab. For information about using FixedPoint Tool, see Autoscaling Data Objects Using the FixedPoint Tool (FixedPoint Designer).
After you use FixedPoint Tool, you can use the parameters in this tab to make adjustments to fixedpoint datatype settings if necessary. For each quantity associated with the block, you can specify:
Floatingpoint or fixedpoint data type, including whether the data type is inherited from upstream values in the block.
The minimum and maximum values for the quantity, which determine how the quantity is scaled for fixedpoint representation.
For assistance in selecting appropriate values, click to open the Data Type Assistant for the corresponding quantity. For more information, see Specify Data Types Using Data Type Assistant.
The specific quantities listed in the Data Types tab vary depending on how you configure the PID controller block. In general, you can configure data types for the following types of quantities:
Product output — Stores the result of a multiplication carried out under the block mask. For example, P product output stores the output of the gain block that multiplies the block input with the proportional gain P.
Parameter — Stores the value of a numeric block parameter, such as P, I, or D.
Block output — Stores the output of a block that resides under the PID controller block mask. For example, use Integrator output to specify the data type of the output of the block called Integrator. This block resides under the mask in the Integrator subsystem, and computes integrator term of the controller action.
Accumulator — Stores values associated with a sum block. For example, SumI2 Accumulator sets the data type of the accumulator associated with the sum block SumI2. This block resides under the mask in the Back Calculation subsystem of the AntiWindup subsystem.
In general, you can find the block associated with any listed parameter by looking under the
PID Controller block mask and examining its subsystems. You can also use the Model Explorer
to search under the mask for the listed parameter name, such as SumI2
.
(See Model
Explorer.)
Matching Input and Internal Data Types
By default, all data types in the block are set to Inherit: Inherit via internal rule
. With this setting, Simulink chooses data types to balance numerical accuracy, performance, and generated code size, while accounting for the properties of the embedded target hardware.
Under some conditions, incompatibility can occur between data types within the block. For
instance, in continuous time, the Integrator block under the mask can accept only signals of
type double
. If the block input signal is a type that cannot be
converted to double
, such as uint16
,
the internal rules for type inheritance generate an error when you generate code.
To avoid such errors, you can use the Data Types settings to force a data type conversion. For
instance, you can explicitly set P product output, I product
output, and D product output to
double
, ensuring that the signals reaching the
continuoustime integrators are of type double
.
In general, it is not recommended to use the block in continuous time for code generation applications. However, similar data type errors can occur in discrete time, if you explicitly set some values to data types that are incompatible with downstream signal constraints within the block. In such cases, use the Data Types settings to ensure that all data types are internally compatible.
FixedPoint Operational ParametersInteger rounding mode
— Rounding mode for fixedpoint operationsFloor
(default)  Ceiling
 Convergent
 Nearest
 Round
 Simplest
 Zero
Specify the rounding mode for fixedpoint operations. For more information, see Rounding (FixedPoint Designer).
Block parameters always round to the nearest representable value. To control the rounding of a block parameter, enter an expression using a MATLAB^{®} rounding function into the mask field.
Block Parameter:
RndMeth 
Type: character vector 
Values:
'Ceiling'  'Convergent'  'Floor'  'Nearest'  'Round'  'Simplest' 
'Zero' 
Default:
'Floor' 
Saturate on integer overflow
— Method of overflow actionoff
(default)  on
Specify whether overflows saturate or wrap.
off
— Overflows wrap to the appropriate value that the data type can represent.
For example, the number 130 does not fit in a signed 8bit integer and wraps to 126.
on
— Overflows saturate to either the minimum or maximum value that the data type can represent.
For example, an overflow associated with a signed 8bit integer can saturate to 128 or 127.
Tip
Consider selecting this check box when your model has a possible overflow and you want explicit saturation protection in the generated code.
Consider clearing this check box when you want to optimize efficiency of your generated code.
Clearing this check box also helps you to avoid overspecifying how a block handles outofrange signals. For more information, see Troubleshoot Signal Range Errors.
When you select this check box, saturation applies to every internal operation on the block, not just the output or result.
In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
Block Parameter: SaturateOnIntegerOverflow 
Type: character vector 
Values: 'off'  'on' 
Default: 'off' 
Lock data type settings against changes by the fixedpoint tools
— Prevent fixedpoint tools from overriding data typesoff
(default)  on
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify on this block. For more information, see Lock the Output Data Type Setting (FixedPoint Designer).
Block Parameter: LockScale 
Type: character vector 
Values: 'off'  'on' 
Default: 'off' 
The parameters in this tab are primarily of use in code generation.
State name (e.g., 'position')
— Name for continuoustime filter and integrator states''
(default)  character vectorAssign a unique name to the state associated with the integrator or the filter, for continuoustime PID controllers. (For information about state names in a discretetime PID controller, see the State name parameter.) The state name is used, for example:
For the corresponding variable in generated code
As part of the storage name when logging states during simulation
For the corresponding state in a linear model obtain by linearizing the block
A valid state name begins with an alphabetic or underscore character, followed by alphanumeric or underscore characters.
To enable this parameter, set Time domain to Continuoustime
.
Parameter: IntegratorContinuousStateAttributes , FilterContinuousStateAttributes 
Type: character vector 
Default: '' 
State name
— Names for discretetime filter and integrator statesAssign a unique name to the state associated with the integrator or the filter, for discretetime PID controllers. (For information about state names in a continuoustime PID controller, see the State name (e.g., 'position') parameter.)
A valid state name begins with an alphabetic or underscore character, followed by alphanumeric or underscore characters. The state name is used, for example:
For the corresponding variable in generated code
As part of the storage name when logging states during simulation
For the corresponding state in a linear model obtain by linearizing the block
For more information about the use of state names in code generation, see C Code Generation Configuration for Model Interface Elements (Simulink Coder).
To enable this parameter, set Time domain to Discretetime
.
Parameter: IntegratorStateIdentifier , FilterStateIdentifier 
Type: string, character vector 
Default: "" 
State name must resolve to Simulink signal object
— Require that state name resolve to a signal objectoff
(default)  on
Select this parameter to require that the discretetime integrator or filter state name resolves to a Simulink signal object.
To enable this parameter for the discretetime integrator or filter state:
Set Time domain to Discretetime
.
Specify a value for the integrator or filter State name.
Set the model configuration parameter Signal resolution to a value other than None
.
Block Parameter: IntegratorStateMustResolveToSignalObject , FilterStateMustResolveToSignalObject 
Type: string, character vector 
Values: "off" , "on" 
Default: "off" 
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

A 2DOF PID controller can be interpreted as a PID controller with a prefilter, or a PID controller with a feedforward element.
In parallel form, a twodegreeoffreedom PID controller can be equivalently modeled by the following block diagram, where C is a single degreeoffreedom PID controller and F is a prefilter on the reference signal.
Ref is the reference signal, y is the feedback from the measured system output, and u is the controller output. For a continuoustime 2DOF PID controller in parallel form, the transfer functions for F and C are
$$\begin{array}{l}{F}_{par}(s)=\frac{(bP+cDN){s}^{2}+(bPN+I)s+IN}{(P+DN){s}^{2}+(PN+I)s+IN},\\ {C}_{par}(s)=\frac{(P+DN){s}^{2}+(PN+I)s+IN}{s(s+N)},\end{array}$$
where b and c are the setpoint weights.
For a 2DOF PID controller in ideal form, the transfer functions are
$$\begin{array}{l}{F}_{id}(s)=\frac{(b+cDN){s}^{2}+(bN+I)s+IN}{(1+DN){s}^{2}+(N+I)s+IN},\\ {C}_{id}(s)=P\frac{(1+DN){s}^{2}+(N+I)s+IN}{s(s+N)}.\end{array}$$
A similar decomposition applies for a discretetime 2DOF controller.
Alternatively, the parallel twodegreeoffreedom PID controller can be modeled by the following block diagram.
In this realization, Q acts as feedforward conditioning on the reference signal. For a continuoustime 2DOF PID controller in parallel form, the transfer function for Q is
$${Q}_{par}(s)=\frac{\left((b1)P+(c1)DN\right)s+(b1)PN}{s+N}.$$
For a 2DOF PID controller in ideal form, the transfer function is
$${Q}_{id}(s)=P\frac{\left((b1)+(c1)DN\right)s+(b1)N}{s+N}.$$
The transfer functions for C are the same as in the filter decomposition.
A similar decomposition applies for a discretetime 2DOF controller.
ReferenceBlock
parameter returns different pathBehavior changed in R2021b
Starting in R2021b, the get_param
function returns a different
value for the ReferenceBlock
parameter. The
ReferenceBlock
parameter is a property common to all Simulink blocks and gives the path of the library block to which a block links. The
PID Controller (2DOF) and Discrete PID Controller
(2DOF) blocks now link to 'slpidlib/PID Controller
(2DOF)'
. Previously, the blocks linked to 'pid_lib/PID Controller
(2DOF)'
.
This change does not affect any other functionality or workflows. You can still use
the previous path with the set_param
function.
ReferenceBlock
parameter returns different pathBehavior changed in R2020b
Starting in R2020b, the get_param
function returns a different
value for the ReferenceBlock
parameter. The
ReferenceBlock
parameter is a property common to all Simulink blocks and gives the path of the library block to which a block links. The
PID Controller (2DOF) and Discrete PID Controller
(2DOF) blocks now link to 'pid_lib/PID Controller
(2DOF)'
. Previously, the blocks linked to 'simulink/Continuous/PID
Controller (2DOF)'
.
This change does not affect any other functionality or workflows. You can still use the previous path with the set_param
function.
[1] Visioli, A., "Modified AntiWindup Scheme for PID Controllers," IEE Proceedings  Control Theory and Applications, Vol. 150, Number 1, January 2003
For continuoustime PID controllers (Time domain set to Continuoustime
):
Consider using Model Discretizer to map continuoustime blocks to discrete equivalents that support code generation. To access Model Discretizer, in the Apps tab, under Control Systems, click Model Discretizer.
Not recommended for production code.
For discretetime PID controllers (Time domain set to Discretetime
):
Depends on absolute time when placed inside a triggered subsystem hierarchy.
Generated code relies on memcpy
or memset
functions (string.h
) under certain conditions.
Fixedpoint code generation is supported for discretetime PID controllers only (Time domain set to Discretetime
).
Gain  DiscreteTime Integrator  Discrete Derivative  PID Controller (2DOF)  Discrete PID Controller
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.