Documentation

Design MPC Controller in Simulink

This example shows how to design a model predictive controller for a continuous stirred-tank reactor (CSTR) in Simulink® using the MPC Designer app.

This example requires Simulink Control Design™ software to define the MPC structure by linearizing a nonlinear Simulink model.

CSTR Model

A CSTR is a jacketed nonadiabatic tank reactor commonly used in the process industry.

An inlet stream of reagent A feeds into the tank at a constant rate. A first-order, irreversible, exothermic reaction takes place to produce the product stream, which exits the reactor at the same rate as the input stream.

The CSTR model has three inputs:

  • Feed Concentration (CAi) — The concentration of reagent A in the feed stream (kgmol/m3)

  • Feed Temperature (Ti) — Feed stream temperature (K)

  • Coolant Temperature (Tc) — Reactor coolant temperature (K)

The two model outputs are:

  • CSTR Temperature (T) — Reactor temperature (K)

  • Concentration (CA) — Concentration of reagent A in the product stream, also referred to as the residual concentration (kgmol/m3)

The control objective is to maintain the residual concentration, CA, at its nominal setpoint by adjusting the coolant temperature, Tc. Changes in the feed concentration, CAi, and feed temperature, Ti, cause disturbances in the CSTR reaction.

The reactor temperature, T, is usually controlled. However, for this example, ignore the reactor temperature, and assume that the residual concentration is measured directly.

Open Simulink Model

open_system('CSTR_ClosedLoop');

Connect Measured Disturbance To MPC Controller Block

In the Simulink model window, double-click the MPC Controller block.

In the Block Parameters dialog box, on the General tab, in the Additional Inports section, check the Measured disturbance (md) option.

Click Apply to add the md inport to the controller block.

In the Simulink model window, connect the Feed Temperature block output to the md inport.

Open MPC Designer App

In the MPC Controller Block Parameters dialog box, click Design to open MPC Designer.

Define MPC Structure

In the MPC Designer app, on the MPC Designer tab, in the Structure section, click MPC Structure.

In the Define MPC Structure By Linearization dialog box, in the Controller Sample Time section, specify a sample time of 0.1.

In the MPC Structure section, click Change I/O Sizes to add the unmeasured disturbance and measured disturbance signal dimensions.

In the MPC Block Signal Sizes dialog box, specify the number of input/output channels of each type:

Click OK.

In the Define MPC Structure By Linearization dialog box, in the Simulink Signals for Plant Inputs section, the app adds a row for Unmeasured Disturbances (UD).

The manipulated variable, measured disturbance, and measured output are already assigned to their respective Simulink signal lines, which are connected to the MPC Controller block.

In the Simulink Signals for Plant Inputs section, select the Unmeasured Disturbances (UD) row, and click Select Signals.

In the Simulink model window, click the output signal from the Feed Concentration block.

The signal is highlighted and its block path is added to the Select Signal dialog box.

In the Select Signals dialog box, click Add Signal(s).

In the Define MPC Structure By Linearization dialog box, in the Simulink Signals for Plant Inputs table, the Block Path for the unmeasured disturbance signal is updated.

Linearize Simulink Model

Linearize the Simulink model at a steady-state equilibrium operating point where the residual concentration is 2 kgmol/m3. To compute such an operating point, add the CA signal as a trim output constraint, and specify its target constraint value.

In the Simulink model window, right-click the signal line connected to CA outport of the CSTR block, and click Linear Analysis Points > Trim Output Constraint.

The CA signal can now be used to define output specifications for calculating a model steady-state operating point.

In the Define MPC Structure By Linearization dialog box, in the Simulink Operating Point section, in the drop-down list, under Create New Operating Point, click Trim Model.

In the Trim the model dialog box, in the Outputs tab, check the box in the Known column for Channel-1 and specify a Value of 2.

This setting constrains the value of the output signal during the operating point search to a known value.

Click Start Trimming.

In the Define MPC Structure By Linearization dialog box, in the Simulink Operating Point section, the computed operating point, op_trim1, is added to the drop-down list and selected.

In the drop-down list, under View/Edit, click Edit op_trim1.

In the Edit dialog box, on the State tab, in the Actual dx column, the near-zero derivative values indicate that the computed operating point is at steady-state.

Click Initialize model to set the initial states of the Simulink model to the operating point values in the Actual Values column. Doing so enables you to later simulate the Simulink model at the computed operating point rather than at the default model initial conditions.

In the Initialize Model dialog box, click OK.

Close the Edit dialog box.

In the Define MPC Structure By Linearization dialog box, click Define and Linearize to linearize the model.

The linearized plant model is added to the MPC Designer Data Browser. Also, the following are added to the Data Browser:

  • A default MPC controller created using the linearized plant as an internal prediction model

  • A default simulation scenario

Define Input/Output Channel Attributes

On the MPC Designer tab, in the Structure section, click I/O Attributes.

In the Input and Output Channel Specifications dialog box, in the Name column, specify meaningful names for each input and output channel.

In the Unit column, specify appropriate units for each signal.

The Nominal Value for each signal is the corresponding steady-state value at the computed operating point.

Click OK.

Define Disturbance Rejection Simulation Scenarios

The primary objective of the controller is to hold the residual concentration, CA, at the nominal value of 2 kgmol/m3. To do so, the controller must reject both measured and unmeasured disturbances.

In the Scenario section, click Edit Scenario > scenario1.

In the Simulation Scenario dialog box, in the Reference Signals table, in the Signal drop-down list select Constant to hold the output setpoint at its nominal value.

In the Measured Disturbances table, in the Signal drop-down list, select Step.

Specify a step Size of 10 and a step Time of 0.

Click OK.

In the Data Browser, under Scenarios, double-click scenario1 and rename it MD_reject.

In the Scenario section, click Plot Scenario > New Scenario.

In the Simulation Scenario dialog box, in the Unmeasured Disturbances table, in the Signal drop-down list, select Step.

Specify a step Size of 1 and a step Time of 0.

Click OK.

In the Data Browser, under Scenarios, double-click NewScenario and rename it UD_reject.

Arrange Output Response Plots

To make viewing the tuning results easier, arrange the plot area to display the Output Response plots for both scenarios at the same time.

On the View tab, in the Tiles section, click Top/Bottom.

The plot display area changes to display the Input Response plots above the Output Response plots.

Drag the MD_reject: Output tab up to the top plot.

Tune Controller Performance

In the Tuning tab, in the Horizon section, specify a Prediction horizon of 20 and a Control horizon of 5.

The Output Response plots update based on the new horizon values.

Use the default controller constraint and weight configurations.

In the Performance Tuning section, drag the Closed-Loop Performance slider to the right, which leads to tighter control of outputs and more aggressive control moves. Drag the slider until the MD_reject: Output response reaches steady state in less than 2 seconds.

Drag the State Estimation slider to the right, which leads to more aggressive unmeasured disturbance rejection. Drag the slider until the UD_reject: Output response reaches steady state in less than 3 seconds.

Update Simulink Model with Tuned Controller

In the Analysis section, click the Update and Simulate arrow .

Under Update and Simulate, click Update Block Only. The app exports the tuned controller, mpc1, to the MATLAB® workspace. In the Simulink model, the MPC Controller block is updated to use the exported controller.

Simulate Unmeasured Disturbance Rejection

In the Simulink model window, change the simulation duration to 5 seconds.

The model initial conditions are set to the nominal operating point used for linearization.

Double-click the Feed Concentration block.

In the Block Parameters dialog box, enter a Constant Value of 11 to simulate a unit step at time zero.

Click Apply.

In the Simulink model window, click Run.

The Concentration output response is similar to the UD_reject response, however the settling time is around 1 second later. The different result is due to the mismatch between the linear plant used in the MPC Designer simulation and the nonlinear plant in the Simulink model.

Simulate Measured Disturbance Rejection

In the Block Parameters: Feed Concentration dialog box, enter a Constant Value of 10 to return the feed concentration to its nominal value.

Click OK.

In the Simulink model window, double-click the Feed Temperature block.

In the Block Parameters: Feed Temperature dialog box, enter a Constant Value of 310 to simulate a step change of size 10 at time zero.

Click OK.

In the Simulink model window, click Run.

The Concentration output response is similar to the MD_reject response from the MPC Designer simulation.

References

[1] Seborg, D. E., T. F. Edgar, and D. A. Mellichamp, Process Dynamics and Control, 2nd Edition, Wiley, 2004, pp. 34–36 and 94–95.

See Also

|

Related Examples

More About

Was this topic helpful?