The PID autotuner blocks work by performing a frequency-response estimation experiment. The blocks inject test signals into your plant and tune PID gains based on an estimated frequency response. The following schematic diagram illustrates generally how a PID autotuner block fits into a control system. Control System Design MATLAB & Simulink. If you have a plant model in Simulink, you can use PID autotuning to: Obtain an initial PID design for your plant, which you can refine by tuning against the physical plant. Preview plant response and adjust the settings for PID autotuning before tuning the controller in real time. How To Design a PID Controller In MATLAB - Manual Tuning Method Learn to design a PID controller in MATLAB by tuning the variables Kp, Ki, and Kd. Complete MATLAB Tutorial for Beginners Get The. Download Code Examples to Learn How to Automatically Tune PID Controller. PID controller design and tuning MATLAB Simulink in this video, PID.
This example shows how to automatically tune a PID Controller block using PID Tuner.
Introduction of the PID Tuner
PID Tuner provides a fast and widely applicable single-loop PID tuning method for the Simulink® PID Controller blocks. With this method, you can tune PID controller parameters to achieve a robust design with the desired response time.
A typical design workflow with the PID Tuner involves the following tasks:
(1) Launch the PID Tuner. When launching, the software automatically computes a linear plant model from the Simulink model and designs an initial controller.
(2) Tune the controller in the PID Tuner by manually adjusting design criteria in two design modes. The tuner computes PID parameters that robustly stabilize the system.
(3) Export the parameters of the designed controller back to the PID Controller block and verify controller performance in Simulink.
Open the Model
Open the engine speed control model with PID Controller block and take a few moments to explore it.
Design Overview
In this example, you design a PI controller in an engine speed control loop. The goal of the design is to track the reference signal from a Simulink step block
scdspeedctrlpidblock/Speed Reference
. The design requirement are:- Settling time under 5 seconds
- Zero steady-state error to the step reference input.
In this example, you stabilize the feedback loop and achieve good reference tracking performance by designing the PI controller
scdspeedctrl/PID Controller
in the PID Tuner.Open PID Tuner
To launch the PID Tuner, double-click the PID Controller block to open its block dialog. In the Main tab, click Tune.
Initial PID Design
When the PID Tuner launches, the software computes a linearized plant model seen by the controller. The software automatically identifies the plant input and output, and uses the current operating point for the linearization. The plant can have any order and can have time delays.
The PID Tuner computes an initial PI controller to achieve a reasonable tradeoff between performance and robustness. By default, step reference tracking performance displays in the plot.
The following figure shows the PID Tuner dialog with the initial design:
Display PID Parameters
Click Show parameters to view controller parameters P and I, and a set of performance and robustness measurements. In this example, the initial PI controller design gives a settling time of 2 seconds, which meets the requirement.
Adjust PID Design in PID Tuner
The overshoot of the reference tracking response is about 7.5 percent. Since we still have some room before reaching the settling time limit, you could reduce the overshoot by increasing the response time. Move the response time slider to the left to increase the closed loop response time. Notice that when you adjust response time, the response plot and the controller parameters and performance measurements update.
The following figure shows an adjusted PID design with an overshoot of zero and a settling time of 4 seconds. The designed controller effectively becomes an integral-only controller.
Complete PID Design with Performance Trade-Off
In order to achieve zero overshoot while reducing the settling time below 2 seconds, you need to take advantage of both sliders. You need to make control response faster to reduce the settling time and increase the robustness to reduce the overshoot. For example, you can reduce the response time from 3.4 to 1.5 seconds and increase robustness from 0.6 to 0.72.
The following figure shows the closed-loop response with these settings:
Write Tuned Parameters to PID Controller Block
After you are happy with the controller performance on the linear plant model, you can test the design on the nonlinear model. To do this, click Update Block in the PID Tuner. This action writes the parameters back to the PID Controller block in the Simulink model.
The following figure shows the updated PID Controller block dialog:
Completed Design
The following figure shows the response of the closed-loop system:
The response shows that the new controller meets all the design requirements.
You can also use the Control System Designer to design the PID Controller block, when the PID Controller block belongs to a multi-loop design task. See the example Single Loop Feedback/Prefilter Compensator Design.
See Also
Related Topics
When to Use PID Autotuning
The PID autotuner blocks in Simulink® Control Design™ let you tune a PID controller without a parametric plant model or an initial controller design. If you have a code-generation product such as Simulink Coder™, you can generate code that implements the tuning algorithm on hardware. Deploying the algorithm to hardware lets you tune a controller for a physical plant, with or without using Simulink to manage the tuning process.
To achieve model-free tuning, use the Closed-Loop PID Autotuner or Open-Loop PID Autotuner blocks. These blocks perform a frequency-response estimation experiment that injects signals into the plant and measures the plant output with the feedback loop closed or open, respectively. The blocks use the resulting estimated frequency response to tune PID gains for the plant.
PID autotuning works with any asymptotically stable or integrating SISO plant, whether low-order or high-order, with or without time delay, and with or without direct feedthrough. It can tune any type of PID controller. You trigger the tuning process via an input to the block, so you can tune your controller at any time.
PID Autotuning for a Physical Plant
Embedded PID autotuning is a useful option when you have a PID-controlled system and a test bed or control environment to operate in. In this case, you can deploy an autotuner block to your hardware and automatically tune the gains of the PID controller in your system.
In practice, you can manage the PID autotuning process in several ways, including:
- Deploy the autotuning algorithm as a standalone embedded module and manage the tuning process in your own software and hardware environment. For details, see PID Autotuning in Real Time.
- Initiate, monitor, and analyze the autotuning process via Simulink. For details, see Control Real-Time PID Autotuning in Simulink.
PID Autotuning for a Plant Model in Simulink
If you have a plant model in Simulink, you can use PID autotuning to:
- Obtain an initial PID design for your plant, which you can refine by tuning against the physical plant.
- Preview plant response and adjust the settings for PID autotuning before tuning the controller in real time. Doing so helps ensure that real-time tuning does not drive your system out of the desirable operating range.
For more information, see PID Autotuning for a Plant Modeled in Simulink.
Closed-Loop vs. Open-Loop PID Autotuning
The PID autotuning tools let you tune:
- In a closed-loop configuration, with your plant under control of an existing PID controller (Closed-Loop PID Autotuner block).
- In an open-loop configuration (Open-Loop PID Autotuner block). With open-loop autotuning, if the plant is in a feedback loop, the autotuner opens the loop for the duration of the tuning process.
In general, if you do not have an initial PID design, start with open-loop autotuning, and switch to closed-loop autotuning for retuning or refinement. If you have an initial PID design for your plant, use closed-loop tuning, which is safer for your plant. With closed-loop autotuning, the controller remains in the loop to:
- Reject unexpected plant disturbances to maintain safe operation of the plant during the estimation experiment.
- Reduce the risk that the perturbations used for the experiment drive the plant away from the desired operating point.
Additional advantages of the closed-loop autotuning approach include:
- Closed-loop tuning works with multiple-integrator plants. In contrast, you cannot use open-loop autotuning for multiple-integrator plants. Even single-integrator plants risk drifting away from the desired operating point during open-loop tuning.
- Because the feedback loop remains closed, there is no concern about controller saturation during the tuning process. In contrast, with open-loop autotuning, a controller with integral action can saturate while the loop is open. Such saturation can create a jump at the plant input when the tuning process ends. With open-loop tuning, you must take additional steps to ensure that the controller continues to track autotuner block output during tuning. (See, for instance, PID Autotuning for a Plant Modeled in Simulink.)
If safe operation of your plant is not a practical concern (such as when tuning against a plant model in Simulink), open-loop autotuning has these advantages:
- Open-loop tuning can result in more accurate frequency-response estimation and tuning. In closed-loop tuning, the controller suppresses injected perturbations, which can result in less accurate frequency-response estimation and poorer tuning results.
- Open-loop tuning is faster. Closed-loop tuning uses a lower-frequency perturbation signal, which makes the process about three times longer.
- The memory footprint of the deployed algorithm is slightly smaller.
Caution
Pid Controller Matlab Code
- Do not use either closed-loop or open-loop PID autotuning with an unstable plant.
- Do not use open-loop PID autotuning with a plant that has more than one integrator. You can use closed-loop PID autotuning with a multiple-integrator plant.
To get started with either type of PID autotuner, see How PID Autotuning Works.
When Not to Use PID Autotuning
PID Autotuning is not suitable for unstable plants. The perturbations applied in open-loop tuning can drive an unstable plant to operating conditions that are unsafe for the plant. Although closed-loop autotuning does not have that risk, it does not yield meaningful tuning results for unstable plants.
How To Auto Tune Pid Controller In Matlab Software
PID autotuning does not work well when there are large disturbances in the plant during the estimation experiment. Disturbances distort the plant response to the perturbation signals, yielding poor estimation results.