Use Parameter Writer Block to Schedule PID Controller Gain
This example shows how to use Parameter Writer blocks to dynamically update the gain values of a PID controller designed for a nonlinear system to track a reference input signal. In this example, a PID controller is designed for a continuous stirred tank reactor model. A gain scheduler designed using 1-D Look Up Tables uses Parameter Writer blocks to update the PID controller gains dynamically during the simulation. The controller enables the plant to track a reference concentration signal.
Open the gain scheduler model.
mdl = "GainSchedParamWriter.slx";
open_system(mdl)
Plant
This example uses a nonlinear continuous stirred tank reactor (CSTR) model. The plant model uses the reactor coolant temperature as input and outputs the reactor concentration. The plant is represented using mathematical function blocks. For more information about the mathematical equations and schematic diagram of this model, see CSTR Model (Model Predictive Control Toolbox).
open_system('GainSchedParamWriter/CSTR Plant')
close_system('GainSchedParamWriter/CSTR Plant')
Control Unit
Two sub-components comprise the control unit:
PID controller
Gain scheduler
PID Controller
A PID controller is used to control the nonlinear CSTR plant model. However, a single set of controller PID gain coefficients do not provide desired tracking performance throughout the entire range of operating points for the plant. Consequently, a gain scheduler is used. The scheduler updates the PID gain coefficients as the output concentration changes ensuring desired tracking performance.
Gain Scheduler
To implement a gain scheduler, the system is linearized at several equilibrium operating points. For this model, eight operating points are identified based on the output concentration values of the CSTR plant. Based on the linearized plant at those eight operating points, a family of PID controllers is designed as described in Design Family of PID Controllers for Multiple Operating Points (Simulink Control Design). These gains are designed to achieve open-loop crossover frequency of 10 rad/sec and default phase margin of 60 degrees.
The gain values are loaded from the MAT file ControllerGain
file in the base workspace variable ControllerGains
.
open_system('GainSchedParamWriter/PID Gain Scheduler')
The gain scheduler executes at 0.01s intervals during simulation. Using the scheduling variables as inputs, a set of 1-D Lookup Table blocks compute the PID gain coefficients. The coefficient values are written to the PID block using a set of Parameter Writer blocks.
The following figure shows configuration of one of the Parameter Writer blocks that writes to the "D" (derivative) coefficient of the PID controller. To configure the block, select Block Parameter
from Destination parameter drop-down options and then select D
for PID controller block. To make the simulation faster, the Validate Parameter check box is cleared. All the other three Parameter Writer blocks are configured similarly to write to P, I and Transfer Coefficient (N).
To enable updating the masked parameters of the PID Controller using Parameter Writer blocks, skip mask initialization during simulation. To do so, on the Modeling tab, in the Model Settings gallery, in Model Properties, set SkipMaskInitInSimulation
parameter to off
using PreLoadFcn
model callback parameter.
close_system('GainSchedParamWriter/PID Gain Scheduler')
Run Simulation and Visualize Results
Simulate the model and visualize the result using the Scope block. Observe that the plant output (indicated by the yellow line) tracks the reference signal (indicated by the blue line).
out = sim(mdl);
See Also
Parameter Writer | PID Controller | 1-D Lookup Table | Function-Call Subsystem | Function-Call Generator