Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Design Controller in Simulink

This example shows how to design a model predictive controller in Simulink®.

Suppose you have built a nonlinear plant model in Simulink. You want to design an MPC controller at a specific equilibrium operating point. This example shows that model-based design workflow. You linearize the plant at the desired operating point, design the MPC controller and validate it with nonlinear simulation.

Continuous Stirred Tank-Reactor Model

The Simulink model, CSTR_ClosedLoop, models a continuous stirred tank-reactor (CSTR) plant. A model predictive controller regulates the CSTR plant.

open_system('CSTR_ClosedLoop');

CSTR Plant

The CSTR block, which models the nonlinear plant, has three inputs:

  • Feed Concentration (CAi inport) — Concentration of the limiting reactant in the CSTR feed stream.

  • Feed Temperature (Ti inport) — Temperature of the limiting reactant in the CSTR feed stream.

  • Coolant Temperature (Tc inport) — Temperature of the CSTR coolant. The MPC controller (MPC Controller block) treats this plant input as a manipulated variable.

The CSTR block has two states: the temperature and concentration of the limiting reactant in the reactor. These states are measured and displayed by the following blocks:

  • CSTR Temperature — Temperature of the limiting reactant in the product stream.

  • Concentration — Concentration of the limiting reactant in the product stream, also referred to as residual concentration. The MPC controller regulates this state to satisfy the desired setpoint.

MPC Controller

The MPC Controller block, which requires a supported C or C++ compiler, represents the model predictive controller. It is available in the Model Predictive Control Toolbox library of the Simulink Library Browser. For this example, the block is configured as follows:

  • Measured output (mo inport) — Residual concentration; signal originating at the CA outport of the CSTR block.

  • Reference, also referred to as setpoint or target (ref inport) — Residual concentration reference; signal originating at the Concentration Setpoint block. Set to 2 kmol/m3.

  • Manipulated variable (mv outport) — Concentration of the CSTR coolant; input signal of the Tc inport of the CSTR block.

The reactor temperature is usually controlled. For this example, ignore the reactor temperature for a more challenging nonlinear control problem.

Open MPC Design Tool

Double-click the MPC Controller block to open the block dialog box.

The MPC Controller box is blank. No controller has been designed yet.

Click Design. The MPC Question dialog box opens.

For this example, use the default values of this dialog box. Click OK. The software performs multiple tasks to design an initial MPC controller. These tasks include finding an equilibrium operating point, linearizing the plant model, and building the MPC controller. Finally, the Control and Estimation Tools Manager opens, containing an MPC design task node (MPC Design Task - MPC Controller). This node includes the linearized plant model, MPC open loop plant 1.

Evaluate Default Operating Point

The CSTR plant model has multiple equilibrium operating points. The software uses the default equilibrium operating point to linearize the plant model. This operating point could differ from the desired operating point. It is important to verify that the software used an appropriate operating point. Otherwise, the linear plant model can be unsuitable for controller design.

In the MPC open loop plant 1 node of the tree, click Operating Point.

The software found a steady-state operating point (derivatives are close to zero). However, the reactor temperature (CSTR_ClosedLoop/CSTR/T_K) is very low, yielding a low reaction rate. Compare the values of the residual concentration state (9.9919 kmol/m3) and the feed concentration (10 kmol/m3) to confirm the low reaction rate.

Because this operating point does not result in a significant reaction, calculate another operating point with a higher reaction rate.

Calculate Desired Operating Point for Plant Model

Suppose the desired operating point is:

  • Residual concentration is 2 kmol/m3

  • Reactor temperature is 370 K

Specify output constraints on all the OV/MV/MD signals connected to the MPC Controller. This step is required because the software uses the steady-state values of these signals as the nominal values for the controller. In the Simulink model, right-click the MO signal entering the controller. Select Linear Analysis Points> Trim Output Constraint. Repeat for the MV signal of the MPC Controller block. All constrained signals are marked with T.

In the tree of the Control and Estimation Tools Manager, click Operating Points. Then, click the Compute Operating Points tab.

Specify the desired operating point states:

  • CSTR_ClosedLoop/CSTR/C_A (residual concentration) — Enter 2 in the Value box.

  • CSTR_ClosedLoop/CSTR/T_K (reactor temperature) — Enter 370 in the Value box.

  • CSTR_ClosedLoop/MPC Controller/MPC/last_mv — Clear the Steady State check box. This state, which belongs to the MPC Controller block, can be arbitrary. Its value is set by the software during the operating point calculation.

Specify the desired operating point outputs. Click the Outputs tab.

  • CSTR_ClosedLoop/CSTR (reactor concentration) — Enter 2 in the Value box. Then, select Known check box.

  • CSTR_ClosedLoop/MPC Controller (coolant temperature) — Use default values.

Click Compute Operating Points.

The Computation Results tab displays the operating point search result. The new operating point, Operating Point, appears in the Operating Points node.

    Tip   If an operating point computation fails, you can:

    • Specify better initial estimates of the unknown quantities.

    • Select a different optimization algorithm for the operating point search. To specify a different optimization algorithm, in the Controls and Estimation Tools Manager, select Options in the Tools menu. Specify the algorithm options in the Operating Point Search tab.

Confirm that Operating Point is the desired operating point. In the tree, click Operating Point in the Operating Points node.

As desired, the reactor temperature is close to 370 K at steady state. Similarly, the reactor concentration is 2 kmol/m3 at steady state. Operating Point is verified as the desired operating point.

Linearize Plant at Desired Operating Point

In the tree, click MPC Design Task - MPC Controller.

Click Import Plant. The Plant Model Importer dialog box opens.

Click the Linearized Plant from Simulink tab.

  • Linearized plant model name box (name of the linearized plant to be created) — Use the default name, MPC open loop plant2.

  • Use existing operating point list — Select Operating Point.

Click OK. The software calculates the linearized plant model, MPC open loop plant2. This model is visible in the Control and Estimation Tools Manager, in the Plant models node.

(Optional) Close the Plant Model Importer dialog box by clicking Close.

(Optional) To see the nominal values of the input and output signals, in the tree, click MPC Design Task - MPC Controller.

These values correspond to the desired operating point.

Update Controller to Use New Plant Model

In the tree, click Controllers. Then, in the Plant Model list, select MPC open loop plant2.

Alternatively, delete MPC open loop plant1, the model computed at default operating point. Deleting this plant forces the controller to use the new model and eliminates the potential for confusion. In the tree, click Plant models. Then, in the Plant models imported for this project list box, select MPC open loop plant 1. Click Delete.

Generally, the next step is to configure the controller, including specifying the control and prediction horizons, constraints, weights, and noise/disturbance models. For such configuration, select the controller in the Controllers node. However, for this example, use the default controller settings.

(Optional) You can validate the controller design by performing linear simulations. To do so, use the Scenarios node.

Export Controller and Operating Point to MATLAB Workspace

By default, the software creates a controller, MPC1, based on the model obtained by automatic linearization. The software automatically exports MPC1 to the MATLAB® workspace. Also, in the Simulink model, the software updates the MPC Controller block. It sets the MPC Controller parameter to MPC1. So, when you run the Simulink model, you use MPC1.

Because the initial linearization was unsuitable, you must export the controller with the new plant model. In the Controllers node, right-click MPC1 and select Export Controller. The MPC Controller Exporter dialog box opens. Use the default values specified in this dialog box. Click Export and confirm that you want to replace the existing MPC1 in the MATLAB workspace. Optionally, close this dialog box by clicking Close.

    Tip   After you export the controller, you can examine it for design errors and stability problems using review.

Verify Steady-State Operation for Plant-Controller Combination

To simulate the model at the desired operating point, export Operating Point to the MATLAB workspace and initialize the model with it. In the Control and Estimation Tools Manager, expand the Operating Points node and right-click Operating Point. Select Export to Workspace. The Export to Workspace dialog box opens. Select the Use the operating point to initialize model check box. Click OK.

Run the CSTR_ClosedLoop model.

The simulation plots show that the residual concentration reaches 2 kmol/m3 and the reactor temperature is approximately 373 K. Therefore, the controller is initialized at the desired operating point.

Test Controller Robustness

For example, change the feed concentration, specified by the Feed Concentration block, to 9.5 kmol/m3. Recall that the nominal feed concentration value used to design the controller is 10 kmol/m3. Run the model.

The decrease in feed concentration reduces heat generation. If the controller were absent, the reactor temperature would drop significantly, reducing the reaction rate, and the CSTR concentration would increase to roughly 3 kmol/m3. To counteract these effects, the controller raises the coolant temperature, which returns the CSTR temperature to a value slightly below the nominal condition.

See Also

Related Examples

Was this topic helpful?