Compare Multiple Controller Responses Using MPC Designer
This example shows how to compare multiple controller responses using MPC Designer. In particular, controllers with different output constraint configurations are compared.
Define Plant Model
Create a state-space model of your plant, and specify the MPC signal types. For this example, use the CSTR model described in CSTR Model and used in Design Controller Using MPC Designer. For this example, assume that the second input is an unmeasured disturbance and that the second output is not measured.
A = [ -5 -0.3427; 47.68 2.785]; B = [ 0 1 0.3 0]; C = [0 1; 1 0]; D = zeros(2,2); plant = ss(A,B,C,D); plant = setmpcsignals(plant,'MV',1,'UD',2,'MO',1,'UO',2);
Open MPC Designer, and import the plant model.
mpcDesigner(plant)
The app imports the specified plant to the Data Browser and
creates a default controller, mpc1
, and a default simulation scenario,
scenario1
.
Define Simulation Scenario
Configure a disturbance rejection simulation scenario.
In MPC Designer, on the MPC Designer tab, click Edit Scenario > scenario1.
In the Simulation Scenario dialog box, specify a Simulation duration of 6 seconds.
In the Reference Signals table, in the
Signal drop-down lists, select Constant
to hold the setpoints of both outputs at their nominal values.
In the Unmeasured Disturbances table, in the
Signal drop-down list, select Step
. Use
the default Time and Step values.
This scenario simulates a unit step change in the unmeasured input disturbance at a time of 1 second.
Click OK.
The app runs the updated simulation scenario and updates the controller response plots. In the Output Response plots, the default controller returns the measured output, MO1, to its nominal value, however the control action causes an increase in the unmeasured output, UO1.
Create Controller with Hard Output Constraints
Suppose that the control specifications indicate that such an increase in the unmeasured disturbance is undesirable. To limit the effect of the unmeasured disturbance, create a controller with a hard output constraint.
Note
In practice, using hard output constraints is not recommended. Such constraints can create an infeasible optimization problem when the output variable moves outside of the constraint bounds due to a disturbance.
In the Data Browser, in the Controllers
section, right-click mpc1
, and select
Copy.
The app creates a copy of the default controller and adds it to the Controllers section.
Click each controller name and rename them as follows.
Right-click the mpcHard
controller, and select Tune
(select as current MPC). The app adds the mpcHard
controller response to the Input Response and Output
Response plots.
On the Tuning tab, in the Controller
section, mpcHard
is selected as the current MPC
Controller being tuned.
In the Design section, click Constraints.
In the Constraints dialog box, in the Output Constraints section,
in the Max column, specify a maximum output constraint of
0.15
for the unmeasured output (UO).
By default, all output constraints are soft, that is the controller can allow violations of the constraint when computing optimal control moves.
To make the unmeasured output constraint hard, click Constraint Softening
Settings, and enter a MaxECR value of
0
for the UO. This setting places a strict limit on the controller
output that cannot be violated.
Click OK.
The response plots update to reflect the new mpcHard
configuration.
In the Output Response plot, in the UO1 plot,
the mpcHard
response is limited to a maximum of
0.15
. As a trade-off, the controller cannot return the
MO1 response to its nominal value.
Tip
If the plot legends are blocking the response signals, you can drag the legends to different locations.
Create Controller with Soft Output Constraints
Suppose the deviation of MO1 from its nominal value is too large. You can soften the output constraint for a compromise between the two control objectives: MO1 output tracking and UO1 constraint satisfaction.
On the Tuning tab, in the Analysis section,
click Store Controller to save a copy of mpcHard
in the Data Browser.
In the Controllers section, rename
mpcHard_Copy
to mpcSoft
.
On the Tuning tab, in the Controller
section, in the MPC Controller drop-down list, select
mpcSoft
as the current controller.
The app adds the mpcSoft
controller response to the Input
Response and Output Response plots.
In the Design section, click Constraints.
In the Constraints dialog box, in the Output Constraints section,
enter a MaxECR value of 10
for the UO to soften
the constraint.
Click OK.
The response plots update to reflect the new mpcSoft
configuration.
In the Output Response plot, mpcSoft
shows a
compromise between the previous controller responses.
Remove Default Controller Response Plot
To compare the two constrained controllers only, you can remove the default unconstrained controller from the input and output response plots.
On the MPC Designer tab, in the Result section, click Compare Controllers > mpcNone to deselect the first controller.
The app removes the mpcNone
responses from the Input
Response and Output Response plots.
You can toggle the display of any controller in the Data Browser except for controller currently being tuned. Under Compare Controllers, the controllers with displayed responses are indicated with check marks.