Products & Services Solutions Academia Support User Community Company

Learn more about Simulink Control Design   

Automatic PID Tuning

Automatic PID Tuning Overview

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 general information about linearization, see Exact Linearization Using the GUI in the Simulink Control Design User's Guide.

PID Tuning Algorithm

Typical PID tuning objectives include:

The 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 default operating point, 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.

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

      Tip   After the tuner launches, you can close the PID Controller block dialog box.

Analyzing the Design in the PID Tuner

To determine whether the compensator design meets your requirements, you can analyze the system response in any of these response plots:

To view a particular plot type, select the plot type from the Plot drop-down menu.

You can also 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 .

  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

    Decreasing the bandwidth increases the response time, which makes the controller less aggressive. Increasing the bandwidth decreases the response time, which 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 .

  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 The 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 default operating point specified 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 Is in Desired Operating Conditions at a Known Time.  

  1. Click the Design with new plant model button in the PID Tuner to open the Linearize Simulink model at different operating point dialog box.

  2. Select Linearize at simulation snapshot time (second) and enter a time at which you expect the model to have the desired operating conditions. For example, enter a time at which the model is at steady-state.

  3. Click Linearize. 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 Saved 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. See Working with Operating Points.

  2. In the PID Tuner, click the Design with new plant model button to open the Linearize Simulink model at different operating point dialog box.

  3. Select Linearize at one of the following operating points from MATLAB workspace.

  4. Select your exported operating point from the table.

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

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.

The PID Tuner Returns the Error "Linearization Aborted Because the Linear Plant Model Seen by the PID Block Is Effectively 0"

What This Means.  When you click Tune in the PID Tuner, the PID Tuner returns this error message.

The PID Tuner returns this error when the effective plant model linearizes to zero. This error can occur when one or more blocks in the PID loop have zero gain at the linearization operating point. For example:

In either case, the linearized plant is zero, and the PID Tuner cannot design a controller for it.

How To Fix It.  Use the Control and Estimation Tools Manager to analyze your model and determine why the plant linearizes to zero.

To perform this analysis, use the Simulink Control Design linearization tools to create the same linear model seen by the PID controller. To define the plant for linearization:

Symbols appear at the PID Controller block input and output in your model to indicate these linearization points, as shown in the following diagram.

For more information about linearization points, see Selecting Inputs and Outputs for the Linearized Model.

After you create the linearization points, use the procedure described in Steps for Linearizing Models Using the GUI to linearize the plant in your Simulink model. You can then analyze your model to determine why it linearizes to zero and take corrective actions. See Troubleshooting Exact Linearization Results for information about correcting linearization problems.

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.

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

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS