How To Auto Tune Pid Controller In Matlab
Download ->->->-> https://urlgoal.com/2t2cgb
Learn how to automatically tune PID controllers, whether you have an existing mathematical model of your dynamic system or you are tuning your PID parameters based on the response of an algorithm running on hardware. Automatic PID tuning can work for a variety of systems and will save development time by providing a good initial set of control parameters for your control system.
For the purpose of this example we are controlling the rotation of a wheel by setting the motor velocity and using the information from a rotational encoder attached to the motor shaft. In this case we will also start by setting up a stable control architecture in Simulink using the PID control block. However, we will now include the Closed-Loop PID Autotuner block in our model. This block should be placed in the signal connecting your PID controller to your plant and requires as an input the plant measurements. The algorithm will inject a test signal into the controller output in order to estimate the frequency response of your system. However, the starting gains set in the PID control block will be used throughout the experiment, so the system remains stable in the closed-loop configuration. Since the auto tuning algorithm is meant to execute a triggered test, you also get the option of controlling when the test starts and stops using the third input signal, and the third block output will contain the finals PID gains calculated by the algorithm. The minimum test setup includes making sure that the controller options matches those of your PID block, a set of tuning goals for the response of your controller, and a coefficient for the magnitude of the test signals injected into the system. In this case I would like my controller to respond within half a second or at 2 hertz bandwidth, and since the range of velocities of my motor is -100 to 100, I will set the disturbance magnitude to 10, which is a conservative fraction of that actuation range. To determine whether the test is successful or not, you can monitor the test convergence using the second output. Once we start the test, this value should converge quickly, once it gets close to 100% you can stop the test and record the PID gains calculated.
In this case I will generate and deploy C code to my microcontroller and also interact directly with the hardware by using the hardware monitor and tune functionality included within available hardware support packages, but you can also generate standalone C code and integrate it with your preferred testing method. After the test has been enabled and the convergence is close to 100% you can stop the test and get the new PID gains. it is also possible to update the gains on your PID block directly from the block tab of the autotuner block parameters. In this case we improved our rise time by X seconds compared to the initial gains.
Model-based PID controller tuning lets you automatically tune controller gains based on a Simulink model of the control system. Tools for model-based tuning include PID Tuner, which lets you interactively tune PID gains while examining relevant system responses to validate performance. By default, PID Tuner works with a linearization of your plant model. For models that cannot be linearized, you can tune PID gains against a plant model estimated from simulated or measured response data. For more information about available tools for model-based controller tuning, see Choose a Control Design Approach.
Real-time PID Autotuning lets you deploy an embedded automatic tuning algorithm as a standalone application for model-free tuning against a physical plant. The Simulink Control Design PID autotuning algorithm injects test signals into the plant to estimate plant frequency response near your target control bandwidth. It uses the resulting response to compute PID controller gains to balance robustness and performance. For more information about real-time PID autotuning, see When to Use PID Autotuning.
The PID Tuner app automatically tunes the gains of a PID controller for a SISO plant to achieve a balance between performance and robustness. You can specify the controller type, such as PI, PID with derivative filter, or two-degree-of-freedom (2-DOF) PID controllers. Analysis plots let you examine controller performance in time and frequency domains. You can interactively refine the performance of the controller to adjust loop bandwidth and phase margin, or to favor setpoint tracking or disturbance rejection.
For interactive PID tuning in the Live Editor, see the Tune PID Controller Live Editor task. This task lets you interactively design a PID controller and automatically generates MATLAB® code for your live script.
If you are tuning a controller for a plant represented by an LTI model, use the Type menu to specify controller type. When you change controller type, PID Tuner automatically designs a new controller. Available controller types include 2-DOF PID controllers for more flexibility in the trade-off between disturbance rejection and reference tracking. For details on available controller types, see PID Controller Types for Tuning.
For interactive PID tuning in the Live Editor, see the Tune PID Controller Live Editor task. This task lets you interactively design a PID controller and automatically generates MATLAB code for your live script.
The previous video showed three different approaches to developing a mathematical model of your physical system. Now that we have this model, we can use it to tune a PID controller that will work to control the physical system.
To use PID autotuning for a plant modeled in Simulink®, you incorporate a PID autotuner block into the model. You can control the autotuning process while the model is running. When tuning is complete you can validate tuned controller parameters against the simulated plant. Using PID autotuning this way can be useful for generating an initial PID design that you later refine with real-time autotuning.
Run the model and initiate tuning. Use the start/stop signal to initiate the PID autotuning process. When you start the process, the autotuner block injects test signals and measures the response of the plant.
The control signal u from the PID controller feeds into the u port of the autotuner block. The u+Δu port feeds into the plant input. Before you begin the autotuning process, the autotuner block feeds the PID control signal directly from u to u+Δu and the plant input. In that state, the autotuner block has no effect on plant or controller behavior. During the autotuning process, the block injects test signals at the plant input and measures the response at y.
The Open-Loop PID Autotuner block opens the loop between u and u+Δu during the estimation experiment. If your controller includes integral action, you can use signal tracking to avoid integrator windup while the loop is open. Signal tracking enables the PID controller to continue to track the real plant input while it is out of the loop. Without it, your system can experience a bump when the control loop is closed at the end of the tuning process. In system of the following illustration, the PID controller is a Simulink PID Controller block with the Enable tracking mode parameter on. The plant input feeds into the tracking input of the controller block.
To start and stop the autotuning process, use a signal at the start/stop port. When the experiment is not running, the block passes signals unchanged from u to u+Δu. In this state, the block has no impact on plant or controller behavior.
As an alternative to a manual switch, you can configure the start/stop signal to begin and end the experiment automatically at particular simulation times. For example, you can use the sum of two Step blocks: Configure one Step block to step from 0 to 1 at the experiment start time, and a second Step block to step from 1 to 0 at the end time. Feed the sum of the two signals into the start/stop port of the PID autotuner block.
The target bandwidth, specified in rad/sec, is the target value for the 0-dB gain crossover frequency of the tuned open-loop response CP, where P is the plant response, and C is the controller response. This crossover frequency roughly sets the control bandwidth. For a desired rise-time τ seconds, a good guess for the target bandwidth is 2/τ rad/sec.
When you stop experiment, the block computes new PID gains based on the estimated frequency response of the system and your specified tuning goals. Examine them for reasonableness. For instance, if you have an initial PID controller, you might expect the tuned gains to be roughly the same magnitude as the gains of the initial design. There are several ways to see the tuned gains:
To configure the autotuner block to write tuned gains to your controller, designate the controller as the associated PID block in the PID autotuner block parameters. (For more information, see the see the Closed-Loop PID Autotuner or Open-Loop PID Autotuner block reference pages.) Then, update your controller by clicking Update PID Block. You can update the PID gains while the simulation is running. Doing so is useful for immediately validating tuned PID gains.
When you examine these gains and transfer them to your own controller, be aware of the meaning of these gains in the PID autotuner blocks. In discrete time, the blocks assume the following PID controller transfer function:
PID Tuner automatically linearizes the plant at the operating point specified by the model initial conditions, as described in What Plant Does PID Tuner See?. If you want to design a controller for a different operating point, see Tune at a Different Operating Point.
Is this a black-box PID controller? As a first thing, read the manual. Many have an auto-tune feature to find the best PID settings. What are you trying to control? Systems can differ by many orders of magnitude in the way the respond to input changes. (compare a temperature controller for a jacuzzi to a controller that keeps a maglev train at the correct height!). 2b1af7f3a8