| Contents | Index |
| On this page… |
|---|
Introduction to Automatic PID Tuning The PID Tuner Linearizes Your Plant Designing Controllers with the PID Tuner Designing Two-Degree-of-Freedom PID Controllers |
You can use the Simulink Control Design PID Tuner to tune PID gains automatically in a Simulink model containing a PID Controller or PID Controller (2DOF) block. The PID Tuner allows you to achieve a good balance between performance and robustness for either one- or two-degree-of-freedom PID controllers.
The PID Tuner:
Automatically computes a linear model of the plant in your model. The PID Tuner considers the plant to be the combination of all blocks between the PID controller output and input. Thus, the plant includes all blocks in the control loop, other than the controller itself. See The PID Tuner Linearizes Your Plant.
Automatically computes an initial PID design with a good trade-off between performance and robustness. The PID Tuner bases the initial design upon the open-loop frequency response of the linearized plant. See PID Tuning Algorithm.
Provides the PID Tuner GUI to help you interactively refine the performance of the PID controller to meet your design requirements. See Designing Controllers with the PID Tuner.
You can use the PID Tuner to design one- or two-degree-of-freedom PID controllers. You can often achieve both good setpoint tracking and good disturbance rejection using a one-degree-of-freedom PID controller. However, depending upon the dynamics in your model, using a one-degree-of-freedom PID controller can require a trade-off between setpoint tracking and disturbance rejection. In such cases, if you need both good setpoint tracking and good disturbance rejection, use a two-degree-of-freedom PID Controller.
For examples of tuning one- and two-degree-of-freedom PID compensators, see the following demos:
The PID Tuner considers as the plant all blocks in the loop between the PID Controller block output and input. The blocks in your plant can include nonlinearities. Because automatic tuning requires a linear model, the PID Tuner computes a linearized approximation of the plant in your model. This linearized model is an approximation to a nonlinear system, which is generally valid in a small region around a given operating point of the system.
By default, the PID Tuner linearizes your plant using the initial conditions specified in your Simulink model as the operating point. The linearized plant can be of any order and can include any time delays. The PID tuner designs a controller for the linearized plant.
In some circumstances, however, you want to design a PID controller for a different operating point from the one defined by the model initial conditions. For example:
The Simulink model has not yet reached steady-state at the operating point specified by the model initial conditions, and you want to design a controller for steady-state operation.
You are designing multiple controllers for a gain-scheduling application and must design each controller for a different operating point.
In such cases, change the operating point used by the PID Tuner. See Opening the Tuner.
For more information about linearization, see Linearizing Nonlinear Models.
Typical PID tuning objectives include:
Closed-loop stability — The closed-loop system output remains bounded for bounded input.
Adequate performance — The closed-loop system tracks reference changes and suppresses disturbances as rapidly as possible. The larger the loop bandwidth (the frequency of unity open-loop gain), the faster the controller responds to changes in the reference or disturbances in the loop.
Adequate robustness — The loop design has enough gain margin and phase margin to allow for modeling errors or variations in system dynamics.
MathWorks algorithm for tuning PID controllers meets these objectives by tuning the PID gains to achieve a good balance between performance and robustness. The algorithm designs an initial controller by choosing a bandwidth to achieve that balance, based upon the open-loop frequency response of your linearized model. When you interactively change the response time, bandwidth, or phase margin using the PID Tuner interface, the algorithm computes new PID gains. (See Designing Controllers with the PID Tuner for information about using the PID Tuner interactively.)
Before you can use the PID Tuner, you must:
Create a Simulink model containing a PID Controller or PID Controller (2DOF) block. Your model can have one or more PID blocks, but you can only tune one PID block at a time.
If you are tuning a multi-loop control system with coupling between the loops, consider using other Simulink Control Design tools instead of the PID Tuner. See Design and Analysis of Control Systems and the Simulink Control Design demo Cascaded Multi-Loop/Multi-Compensator Feedback Design for more information.
The PID Controller blocks support vector signals. However, using the PID Tuner requires scalar signals at the block inputs.
Your plant (all blocks in the control loop other than the controller) can be linear or nonlinear. The plant can also be of any order, and have any time delays.
Configure the PID block settings, such as controller type, controller form, time domain, sample time. See the PID Controller or PID Controller (2DOF) block reference pages for more information about configuring these settings.
To open the PID Tuner and view the initial compensator design:
Open the Simulink model by typing the model name at the MATLAB command prompt.
Double-click the PID Controller block to open the block dialog box.
In the block dialog box, click Tune to launch the PID Tuner.
When you launch the PID Tuner, the following actions occur:
The PID Tuner automatically linearizes the plant at the operating point specified by the model initial conditions, as described in The PID Tuner Linearizes Your Plant. If you want to design a controller for a different operating point, see Tuning at a Different Operating Point.
Note If the plant model in the PID loop linearizes to zero on launch, the PID Tuner provides the Obtain plant model dialog box. This dialog box allows you to obtain a new plant model by either:
|
The PID Tuner computes an initial compensator design using the algorithm described in PID Tuning Algorithm.
The PID Tuner displays the closed-loop step reference tracking response for the initial compensator design in the PID Tuner dialog box. For comparison, the display also includes the closed-loop response for the gains specified in the PID Controller block, if that closed loop is stable, as shown in the following figure.

To determine whether the compensator design meets your requirements, you can analyze the system response using the response plots. Select a response plot from the Response drop-down menu.
The PID Tuner computes the responses based upon the following single-loop control architecture:

The following table summarizes the available responses.
| Response | Plotted System | Description |
|---|---|---|
| Reference tracking |
| Shows the closed-loop system response to a change in setpoint. Use when your design specifications include setpoint tracking. |
| Controller effort |
| Shows the closed-loop controller output response to a change in setpoint. Use when your design is limited by practical constraints, such as controller saturation. |
| Input disturbance Rejection |
| Shows the closed-loop system response to load disturbance (a disturbance at the plant input). Use when your design specifications include input disturbance rejection. |
| Output disturbance Rejection |
| Shows the closed-loop system response to measurement noise. |
| Open-loop | CG | Shows response of the open-loop controller-plant system. Use
for frequency-domain design. Use when your design specifications include robustness criteria such as open-loop gain margin and phase margin. |
| Plant | G | Shows the plant response. Use to examine plant dynamics. |
Use the Plot drop-down menu to choose Step plot (time-domain response) or Bode plot (frequency-domain response).
You can view the values for system characteristics, such as peak response and gain margin, either:
Directly on the response plot — Use the right-click menu to add characteristics, which appear as blue markers. Then, left-click the marker to display the corresponding data panel.
In the Performance and robustness table
— To display this table, click the Show Parameters arrow
.

Tip
To perform further analysis on the plant model, click the Export
plant model to workspace button
|
If the response of the initial controller design does not meet your requirements, you can interactively adjust the design. The PID Tuner gives you two ways to refine the controller design:
Adjust response time. Make the closed-loop response of the controlled system faster or slower.
Separately adjust loop bandwidth and phase margin. The larger the loop bandwidth, the faster the controller responds to changes in the reference or disturbances in the loop. The larger the phase margin, the more robust the controller is against modeling errors or variations in plant dynamics.
Adjusting Response Time to Tune Parameters. To adjust response time to tune the controller response:
In the PID Tuner, select Basic (the default option) from the Design mode drop-down menu.
Move the Response time slider to find a PID controller that provides a slower or faster response for your system.

Analyze the compensator design to determine if it meets your design requirements, as described in Analyzing the Design in the PID Tuner.
If the design meets your requirements, go to step 4.
If the design does not meet your requirements, try adjusting the bandwidth and phase margin. For instructions, see Adjusting Bandwidth and Phase Margin to Tune Parameters.
If you find a compensator design that meets your requirements, verify that it behaves in a similar way in the nonlinear Simulink model. For instructions, see Verifying the PID Design in Your Simulink Model.
Adjusting Bandwidth and Phase Margin to Tune Parameters. To adjust bandwidth and phase margin to tune the controller response:
In the PID Tuner, select Extended from the Design mode drop-down menu.
Adjust the bandwidth and phase margin to find a PID controller with an adequate balance between performance and robustness by:
Moving the slider bar
Entering a value in the text field
Incrementally adjusting the value in the text field using the up and down arrows

The response time is given by 2/wc, where wc is the bandwidth. Therefore, decreasing the bandwidth makes the controller less aggressive. Increasing the bandwidth makes the controller more aggressive.
For continuous-time systems, bandwidth is a finite positive
real number. For discrete-time systems, bandwidth is a positive real
number less than
, where Ts is
the PID Controller block sample time.
Decreasing the phase margin decreases robustness. Increasing the phase margin increases robustness. Phase margin must be a number in the range 0-90 degrees.
Analyze the compensator design to determine if it meets your design requirements, as described in Analyzing the Design in the PID Tuner.
If the design meets your requirements, go to step 4.
If you cannot find a compensator to meet your requirements by adjusting bandwidth and phase margin, see Cannot Find a Good Design in the PID Tuner.
If you find a compensator design that meets your requirements, verify that this design behaves in a similar way in the nonlinear Simulink model. For instructions, see Verifying the PID Design in Your Simulink Model.
In the PID Tuner, you tune the compensator using a linear model of your plant. First, you find a good compensator design in the PID Tuner. Then, verify that the tuned controller meets your design requirements when applied to the nonlinear plant in your Simulink model.
To verify the compensator design in the nonlinear Simulink model:
In the PID Tuner, click Apply to update the Simulink PID Controller block with the tuned PID parameters.
Simulate the Simulink model, and evaluate whether the simulation output meets your design requirements.
Because the PID Tuner works with a linear model of your plant, the simulated response sometimes does not match the response in the PID Tuner. See Simulated Response Does Not Match the PID Tuner Response for more information.
If the simulated response does not meet your design requirements, see Cannot Find an Acceptable PID Design in the Simulated Model.
By default, the PID Tuner linearizes your plant and designs a controller at the operating point specified by the initial conditions in your Simulink model. In some cases, this operating point can differ from the operating point you want to design a controller for. For example, you want to design a controller for your system at steady-state. However, the Simulink model is not at steady-state at the operating point specified in the model. In this case, change the operating point that the PID Tuner uses for linearizing your plant and designing a controller.
To set a new operating point for the PID Tuner, use one of the following methods. The method you choose depends upon the information you have about your desired operating point:
Known State Values Yield the Desired Operating Conditions.
Close the PID Tuner.
Set the initial conditions of the components of your model to the values that yield the desired operating conditions.
Click Tune in the PID Controller dialog box to launch the PID Tuner. The PID Tuner linearizes the plant using the new default operating point and designs a new initial controller for the new linear plant model.
After the PID Tuner generates a new initial controller design, continue from Analyzing the Design in the PID Tuner.
Your Model Has Desired Operating Conditions at a Known Time.
Click the Design with new plant model
button
in the PID Tuner to open the Obtain
plant model dialog box.
Select Linearizing the Simulink model at simulation snapshot time and enter a time value. Enter a time at which you expect the model to have the desired equilibrium operating conditions.
Click OK. The PID tuner linearizes the plant using the new operating point and designs a new initial controller for the new linear plant model.
After the PID Tuner generates a new initial controller design, continue from Analyzing the Design in the PID Tuner.
You Computed an Operating Point in the Control and Estimation Tools Manager.
In the Control and Estimation Tools Manager, right-click on the node corresponding to the saved operating point. Select Export to Workspace to export your operating point to the MATLAB workspace.
In the PID Tuner, click the Design with new plant
model button
to open the Obtain plant model dialog
box.
Select Importing an LTI system or linearizing at an operating point defined in MATLAB workspace.
Select your exported operating point in the table. The operating point you select appears highlighted.
Click OK. The PID tuner linearizes the plant using the operating point at the snapshot time and designs a new initial controller for the new linear plant model.
After the PID Tuner generates a new initial controller design, continue from Analyzing the Design in the PID Tuner.
Use the PID Tuner to tune two-degree-of-freedom PID Controller (2DOF) blocks to achieve both good setpoint tracking and good disturbance rejection.
A two-degree-of-freedom PID compensator, commonly known as an ISA-PID compensator, is equivalent to a feedforward compensator and a feedback compensator, as shown in the following figure.

The feedforward compensator is PD and the feedback compensator is PID. In the PID Controller (2DOF) block, the setpoint weights b and c determine the strength of the proportional and derivative action in the feedforward compensator. See the PID Controller (2DOF) block reference page for more information.
The PID Tuner tunes the PID gains P, I, D, and N. The tuner does not automatically tune the setpoint weights b and c. However, you can use the PID Tuner to tune a two-degree-of-freedom PID controller by the following process:
Use the PID Tuner to tune the PID gains P, I, D, and N to meet your disturbance rejection requirement.
To tune this portion of the compensator, follow the procedure for tuning a one-degree-of-freedom PID compensator, as described in Analyzing the Design in the PID Tuner. and Refining the Design. Focus on the disturbance rejection plot to make sure that the tuned controller meets your disturbance rejection requirements.
After you have tuned the PID gains P, I, D, and N, update the PID Controller (2DOF) block with the tuned parameters. To update the block, click Apply in the PID Tuner, or select the Automatically update block parameters check box.
Adjust the setpoint weights b and c of the feedforward portion of the compensator to meet your setpoint tracking requirements as follows:
In the PID Controller (2DOF) block dialog box, enter values for the setpoint weights b and c between 0 and 1.
To reduce undesirable controller response to sudden changes in the reference signal (derivative kick), set c to 0. Typically, give b a value in the range 0-1. Smaller b values generally result in slower reference tracking. However, b and c values do not affect loop stability or disturbance rejection.
Evaluate whether the compensator design meets your design requirements by viewing a simulation of the Simulink mode as described in Verifying the PID Design in Your Simulink Model.
This example shows how to tune a PID controller block contained in a referenced model.
When you launch the PID Tuner from a PID controller block in a model that is referenced in one or more open models, the software prompts you to specify which open model is the top-level model for linearization and tuning. The referenced model must be in normal mode.
For more information about model referencing, see Overview of Model Referencing in the Simulink documentation.
Open the model.
open('model_ref_pid');

The block Inner Loop is a referenced model that contains the PID Controller block to tune.
Double-click Inner Loop to open the referenced model.

The referenced model innerloop contains a PID controller block, PID.
Double-click the PID controller block PID to open the block dialog box.
Click Tune in the block dialog box.
The software prompts you to select which open model is the top-level model for linearization and tuning.

Note The software only identifies open models containing the model reference. The PID Tuner does not detect models that contain the model reference but are not open. |
Selecting innerloop causes the PID Tuner to disregard model_ref_pid. Instead, the PID Tuner tunes the PID Controller block for the plant G_Inner alone, as if there were no outer loop.
Alternatively, you can select model_ref_pid as the top-level model. When you do so, the PID Tuner considers the dynamics of both the inner and outer loops, and tunes with both loops closed. In this case, PID controller sees the effective plant (1+G_Outer*Gain)*G_Inner.
Select the desired top-level model, and click OK.
The PID Tuner linearizes the selected model and launches. Proceed with analyzing and adjusting the tuned response as described in Designing Controllers with the PID Tuner.
This section explains some procedures that can help you obtain better results from the PID Tuner if the basic procedures yield unsatisfactory controller performance.
Controller Performance Deteriorates When Switching Time Domains
When Tuning the PID Controller, the D Gain Has a Different Sign from the I Gain
What This means. You have adjusted the PID Tuner sliders, but you cannot find a design that meets your design requirements when you analyze the PID Tuner response plots.
How to Fix It. Try a different PID controller type. It is possible that your controller type is not the best choice for your plant or your requirements.
For example, the closed-loop step response of a P- or PD-controlled system can settle on a value that is offset from the setpoint. If you require a zero steady-state offset, adding an integrator (using a PI or PID controller) can give better results.
As another example, in some cases a PI controller does not provide adequate phase margin. You can instead try a PID controller to give the tuning algorithm extra degrees of freedom to satisfy both speed and robustness requirements simultaneously.
To switch controller types, in the PID Controller block dialog box:
Select a different controller type from the Controller drop-down menu.
Click Apply to save the change.
Click Tune to instruct the PID Tuner to tune the parameters for the new controller type.
If you cannot find any satisfactory controller with the PID Tuner, PID control possibly is not sufficient for your requirements. You can design more complex controllers using the SISO Design Tool. For more information, see Design and Analysis of Control Systems.
What This Means. When you run your Simulink model using the PID gains computed by the PID Tuner, the simulation output differs from the PID Tuner response plot.
There are several reasons why the simulated model can differ from the PID Tuner response plot. If the simulated result meets your design requirements (despite differing from the PID Tuner response), you do not need to refine the design further. If the simulated result does not meet your design requirements, see Cannot Find an Acceptable PID Design in the Simulated Model.
Some causes for a difference between the simulated and PID Tuner responses include:
The reference signals or disturbance signals in your Simulink model differ from the step signals the PID Tuner uses. If you need step signals to evaluate the performance of the PID controller in your model, change the reference signals in your model to step signals.
The structure of your model differs from the loop structure that the PID Tuner designs for. The PID Tuner assumes the loop configuration shown in the following figure.

As the figure illustrates, the PID Tuner designs for a PID in the feedforward path of a unity-gain feedback loop. If your Simulink model differs from this structure, or injects a disturbance signal in a different location, your simulated response differs from the PID Tuner response.
You have enabled nonlinear features in the PID Controller block in your model, such as saturation limits or anti-windup circuitry. The PID Tuner ignores nonlinear settings in the PID Controller block, which can cause the PID Tuner to give a different response from the simulation.
Your Simulink model has strong nonlinearities in the plant that make the linearization invalid over the full operating range of the simulation.
You selected an operating point using the PID Tuner that is different from the operating point saved in the model. In this case, the PID Tuner has designed a controller for a different operating point than the operating point that begins the simulation. Simulate your model using the PID Tuner operating point by initializing your Simulink model with this operating point. See Simulate Simulink Model at Specific Operating Point.
What This Means. You tune the PID Controller using the PID Tuner and run your Simulink model with the tuned PID gains. However, the simulated response of your model does not meet your design requirements.
How to Fix It. In some cases, PID control is not adequate to meet the control requirements for your plant. If you cannot find a design that meets your requirements when you simulate your model, consider using a more complex controller. See Design and Analysis of Control Systems.
If you have enabled saturation limits in the PID Controller block without antiwindup circuitry, enable antiwindup circuitry. You can enable antiwindup circuitry in two ways:
Activate the PID Controller block antiwindup circuitry on the PID Advanced tab of the block dialog box.
Use the PID Controller block tracking mode to implement your own antiwindup circuitry external to the block. Activate the PID Controller block tracking mode on the PID Advanced tab of the block dialog box.
To learn more about both ways of implementing antiwindup circuitry, see the Simulink demo Anti-Windup Control Using a PID Controller
After enabling antiwindup circuitry, run the simulation again to see whether controller performance is acceptable.
If the loop response is still unacceptable, try slowing the response of the PID controller. To do so, reduce the response time or the bandwidth in the PID Tuner. See Adjusting Response Time to Tune Parameters and Adjusting Bandwidth and Phase Margin to Tune Parameters.
If you still cannot find an acceptable controller with antiwindup circuitry enabled in the PID Controller block, consider using a more complex controller. See Design and Analysis of Control Systems.
What This Means. You obtain a well-tuned continuous-time PID controller. Then, you convert the controller time domain using the Time Domain selector button in the PID Controller block dialog box. The controller performs poorly or even becomes unstable when you convert the controller to discrete time.
How To Fix It. In some cases, you can improve performance by adjusting the sample time by trial and error. However, this procedure can yield a poorly tuned controller, especially where your application imposes a limit on the sample time. Instead, if you change time domains and the response deteriorates, click Tunein the PID Controller block dialog to design a new controller.
Note If the plant and controller time domains differ, the PID Tuner discretizes the plant (or converts the plant to continuous time) to match the controller time domain. If the plant and controller both use discrete time, but have different sample times, the PID Tuner resamples the plant to match the controller. All conversions use the tustin method (see Converting Between Continuous- and Discrete-Time Representations in the Control System Toolbox User's Guide). |
What This Means. When you use the PID Tuner to design a controller, the resulting derivative gain D can have a different sign from the integral gain I. The PID Tuner always returns a stable controller, even if one or more gains are negative.
For example, the following expression gives the PID controller transfer function in Ideal form:

For a stable controller, all three numerator coefficients require positive values. Because N is positive, IN > 0 requires that I is also positive. However, the only restriction on D is (1 + DN) > 0. Therefore, as long as DN > –1, a negative D still yields a stable PID controller.
Similar reasoning applies for any controller type and for the Parallel controller form. For more information about controller transfer functions, see the PID Controller block reference page.
![]() | Choosing a Compensator Design Approach | Design and Analysis of Control Systems | ![]() |

Learn more about resources for designing, testing, and implementing control systems.
Get free kit| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |