Skip to Main Content Skip to Search
Product Documentation

Automatic PID Tuning

Introduction to Automatic PID Tuning

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:

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 Linearizes Your Plant

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:

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.

PID Tuning Algorithm

Typical PID tuning objectives include:

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

Designing Controllers with the PID Tuner

Prerequisites for PID Tuning

Before you can use the PID Tuner, you must:

Opening the Tuner

To open the PID Tuner and view the initial compensator design:

  1. Open the Simulink model by typing the model name at the MATLAB command prompt.

  2. Double-click the PID Controller block to open the block dialog box.

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

Analyzing the Design in the PID Tuner

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.

ResponsePlotted System Description
Reference tracking

(from r to y)

Shows the closed-loop system response to a change in setpoint. Use when your design specifications include setpoint tracking.
Controller effort

(from r to u)

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

(from d1 to y)

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

(from d2 to y)

Shows the closed-loop system response to measurement noise.
Open-loopCGShows 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.
PlantGShows 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:

Refining the Design

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:

Adjusting Response Time to Tune Parameters.  To adjust response time to tune the controller response:

  1. In the PID Tuner, select Basic (the default option) from the Design mode drop-down menu.

  2. Move the Response time slider to find a PID controller that provides a slower or faster response for your system.

      Tip   To store a design and continue tuning without losing the design, click the camera button . To retrieve this design, click the picture button .

      To revert to the initial controller design, click the revert button .

  3. Analyze the compensator design to determine if it meets your design requirements, as described in Analyzing the Design in the PID Tuner.

  4. 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:

  1. In the PID Tuner, select Extended from the Design mode drop-down menu.

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

      Tip   To store a design and continue tuning without losing the design, click the camera button . To retrieve this design, click the picture button .

      To revert to the initial controller design, click the revert button .

  3. Analyze the compensator design to determine if it meets your design requirements, as described in Analyzing the Design in the PID Tuner.

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

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:

  1. In the PID Tuner, click Apply to update the Simulink PID Controller block with the tuned PID parameters.

      Tip   To update PID block parameters automatically as you tune the controller in the PID Tuner, select Automatically update block parameters.

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

Tuning at a Different Operating Point

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.  

  1. Close the PID Tuner.

  2. Set the initial conditions of the components of your model to the values that yield the desired operating conditions.

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

  1. Click the Design with new plant model button in the PID Tuner to open the Obtain plant model dialog box.

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

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

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

  2. In the PID Tuner, click the Design with new plant model button to open the Obtain plant model dialog box.

  3. Select Importing an LTI system or linearizing at an operating point defined in MATLAB workspace.

  4. Select your exported operating point in the table. The operating point you select appears highlighted.

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

Designing Two-Degree-of-Freedom PID Controllers

Use the PID Tuner to tune two-degree-of-freedom PID Controller (2DOF) blocks to achieve both good setpoint tracking and good disturbance rejection.

About Two-Degree-of-Freedom PID Controllers

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.

Tuning Two-Degree-of-Freedom PID Controllers

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:

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

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

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

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

Tuning a PID Controller Within a Model Reference

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.

  1. Open the model.

    open('model_ref_pid');
    

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

  2. Double-click Inner Loop to open the referenced model.

    The referenced model innerloop contains a PID controller block, PID.

  3. Double-click the PID controller block PID to open the block dialog box.

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

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

Troubleshooting Automatic PID Tuning

This section explains some procedures that can help you obtain better results from the PID Tuner if the basic procedures yield unsatisfactory controller performance.

Cannot Find a Good Design in the PID Tuner

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:

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.

Simulated Response Does Not Match the PID Tuner Response

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:

Cannot Find an Acceptable PID Design in the Simulated Model

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:

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.

Controller Performance Deteriorates When Switching Time Domains

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.

When Tuning the PID Controller, the D Gain Has a Different Sign from the I Gain

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.

  


Free Control Systems Interactive Kit

Learn more about resources for designing, testing, and implementing control systems.

Get free kit

Trials Available

Try the latest control systems products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS