Simulate switching between multiple implicit MPC controllers
Model Predictive Control Toolbox
At each control instant the Multiple MPC Controllers block receives the current measured plant output, reference, and measured plant disturbance (if any). In addition, it receives a switching signal that selects the active controller from a list of candidate MPC controllers designed at different operating points within the operating range. The active controller then solves a quadratic program to determine the optimal plant manipulated variables for the current input signals.
The Multiple MPC Controllers block enables you to achieve better control
when operating conditions change. Using available measurements, you can detect the current
operating region at run time and choose the appropriate active controller via the
switch
input port. Switching controllers for different operating regions
is a common approach to solving nonlinear control problems using linear control
techniques.
To improve efficiency, inactive controllers do not compute optimal control moves. However, to provide bumpless transfer between controllers, the inactive controllers continue to perform state estimation.
The Multiple MPC Controllers block lacks several optional features found in the MPC Controller block, as follows:
You cannot disable optimization. One controller must always be active.
You cannot initiate a controller design from within the block dialog box; that is, there is no Design button. Design all candidate controllers before configuring the Multiple MPC Controllers block.
Similarly, there is no Review button. Instead, use the review
command or the MPC Designer app.
You cannot update custom constraints on linear combinations of inputs and outputs at run time.
Both the Multiple MPC Controllers block and the Adaptive MPC Controller block enable your control system to adapt to changing operating conditions at run time. The following table lists the advantages of using each block.
Block  Adaptive MPC Controller  Multiple MPC Controllers 

Adaptation approach  Update prediction model for a single controller as operating conditions change  Switch between multiple controllers designed for different operating regions 
Advantages 


ref
— Model output reference valuesPlant output reference values, specified as a row vector signal or matrix signal.
To use the same reference values across the prediction horizon, connect ref to a row vector signal with N_{Y} elements, where N_{y} is the number of output variables. Each element specifies the reference for an output variable.
To vary the references over the prediction horizon (previewing) from time k+1 to time k+p, connect ref to a matrix signal with N_{y} columns and up to p rows. Here, k is the current time and p is the prediction horizon. Each row contains the references for one prediction horizon step. If you specify fewer than p rows, the final references are used for the remaining steps of the prediction horizon.
switch
— Controller selectionUse the switch input port to select the active controller.
The switch input signal must be a scalar integer from
1
to N_{c}, where
N_{c} is the number of specified candidate
controllers. At each control instant, this signal designates the active controller. A
switch value of 1
corresponds to the first entry in the cell array
of candidate controllers, a value of 2
corresponds to the second
controller, and so on.
If the switch
signal is outside of the range 1 to
N_{c}, the block retains the previous
controller output.
mo
— Measured outputMeasured output signals, specified as a vector signal. The candidate controllers use the measured plant outputs to improve their state estimates.
All candidate controllers must use the same state estimation option, either default or custom. If your candidate controllers use default state estimation, you must connect the measured plant outputs to the mo input port. If your candidate controllers use custom state estimation, you must connect a signal to the x[kk] input port.
To enable this port, clear the Use custom state estimation instead of using the builtin Kalman filter parameter.
x[kk]
— Custom state estimateCustom state estimate, specified as a vector signal. The candidate controllers use the connected state estimates instead of estimating the states using its builtin estimator. Use custom state estimates when an alternative estimation technique is considered superior to the builtin estimator or when the states are fully measurable.
All candidate controllers must use the same state estimation option, either default or custom. If your candidate controllers use custom state estimation, you must connect current state estimates to the x[kk] input port. If your candidate controllers use default state estimation, you must connect a signal to the mo input port.
When you use custom state estimation, all candidate controllers must have the same dimensions. All candidate controllers must use the same state definitions (number and order of states) for their respective plant, disturbance and measurement noise models.
To enable this port, select the Use custom state estimation instead of using the builtin Kalman filter parameter.
ymin
— Minimum output variable constraintsMinimum output variable constraints, specified as a row vector that contains
N_{y} finite values, where
N_{y} is the number of outputs. Each
element specifies the lower bound for an output variable. The i
th
element of ymin replaces the
OutputVariables(i).Min
property of the controller at run
time.
If an output variable does not have a lower bound specified in the controller object, then the corresponding connected signal value is ignored.
If this parameter is not selected, the block uses the constant constraint values
stored within its mpc
object.
You cannot specify timevarying constraints at run time using a matrix signal.
If the OutputVariables(i).Min
property of the controller is
specified as a vector (that is, the constraint varies over the prediction horizon),
the i
th element of ymin replaces the first
finite entry in this vector, and the remaining values shift to retain the same
constraint profile.
To enable this port, select the Lower OV limits parameter.
ymax
— Maximum output variable constraintsMaximum output variable constraints, specified as a row vector that contains
N_{y} finite values, where
N_{y} is the number of outputs. Each
element specifies the upper bound for an output variable. The i
th
element of ymax replaces the
OutputVariables(i).Max
property of the controller at run
time.
If an output variable does not have an upper bound specified in the controller object, then the corresponding connected signal value is ignored.
If this parameter is not selected, the block uses the constant constraint values
stored within its mpc
object.
You cannot specify timevarying constraints at run time using a matrix signal.
If the OutputVariables(i).Max
property of the controller is
specified as a vector (that is, the constraint varies over the prediction horizon),
the i
th element of ymax replaces the first
finite entry in this vector, and the remaining values shift to retain the same
constraint profile.
To enable this port, select the Upper OV limits parameter.
umin
— Minimum manipulated variable constraintsMinimum manipulated variable constraints, specified as a row vector that contains
N_{mv} finite values, where
N_{mv} is the number of manipulated
variables. Each element specifies the lower bound for a manipulated variable. The
i
th element of umin replaces the
ManipulatedVariables(i).Min
property of the controller at run
time.
If a manipulated variable does not have a lower bound specified in the controller object, then the corresponding connected signal value is ignored.
If this parameter is not selected, the block uses the constant constraint values
stored within its mpc
object.
You cannot specify timevarying constraints at run time using a matrix signal.
If the ManipulatedVariables(i).Min
property of the controller
is specified as a vector (that is, the constraint varies over the prediction
horizon), the i
th element of umin replaces
the first finite entry in this vector, and the remaining values shift to retain the
same constraint profile.
To enable this port, select the Lower MV limits parameter.
umax
— Maximum manipulated variable constraintsMaximum manipulated variable constraints, specified as a row vector that contains
N_{mv} finite values, where
N_{mv} is the number of manipulated
variables. Each element specifies the upper bound for a manipulated variable. The
i
th element of umax replaces the
ManipulatedVariables(i).Max
property of the controller at run
time.
If a manipulated variable does not have an upper bound specified in the controller object, then the corresponding connected signal value is ignored.
If this parameter is not selected, the block uses the constant constraint values
stored within its mpc
object.
You cannot specify timevarying constraints at run time using a matrix signal.
If the ManipulatedVariables(i).Max
property of the controller
is specified as a vector (that is, the constraint varies over the prediction
horizon), the i
th element of umax replaces
the first finite entry in this vector, and the remaining values shift to retain the
same constraint profile.
To enable this port, select the Upper MV limits parameter.
y.wt
— Output variable tuning weightsTo specify runtime output variable tuning weights, enable this input port. If this port is disabled, the block uses the tuning weights specified in the Weights.OutputVariables
property of its controller object. These tuning weights penalize deviations from output references.
If the MPC controller object uses constant output tuning weights over the prediction horizon, you can specify only constant output tuning weights at runtime. Similarly, if the MPC controller object uses output tuning weights that vary over the prediction horizon, you can specify only timevarying output tuning weights at runtime
To use constant tuning weights over the prediction horizon, connect y.wt to a row vector signal with N_{y} elements, where N_{y} is the number of outputs. Each element specifies a nonnegative tuning weight for an output variable. For more information on specifying tuning weights, see Tune Weights.
To vary the tuning weights over the prediction horizon from time k+1 to time k+p, connect y.wt to a matrix signal with N_{y} columns and up to p rows. Here, k is the current time and p is the prediction horizon. Each row contains the tuning weights for one prediction horizon step. If you specify fewer than p rows, the tuning weights in the final row apply for the remainder of the prediction horizon. For more information on varying weights over the prediction horizon, see TimeVarying Weights and Constraints.
To enable this port, select the OV weights parameter.
u.wt
— Manipulated variable tuning weightsTo specify runtime manipulated variable tuning weights, enable this input port. If
this port is disabled, the block uses the tuning weights specified in the
Weights.ManipulatedVariables
property of its controller object.
These tuning weights penalize deviations from MV targets.
If the MPC controller object uses constant manipulated variable tuning weights over the prediction horizon, you can specify only constant manipulated variable tuning weights at runtime. Similarly, if the MPC controller object uses manipulated variable tuning weights that vary over the prediction horizon, you can specify only timevarying manipulated variable tuning weights at runtime
To use the same tuning weights over the prediction horizon, connect u.wt to a row vector signal with N_{mv} elements, where N_{mv} is the number of manipulated variables. Each element specifies a nonnegative tuning weight for a manipulated variable. For more information on specifying tuning weights, see Tune Weights.
To vary the tuning weights over the prediction horizon from time k to time k+p1, connect u.wt to a matrix signal with N_{mv} columns and up to p rows. Here, k is the current time and p is the prediction horizon. Each row contains the tuning weights for one prediction horizon step. If you specify fewer than p rows, the tuning weights in the final row apply for the remainder of the prediction horizon. For more information on varying weights over the prediction horizon, see TimeVarying Weights and Constraints.
To enable this port, select the MV weights parameter.
du.wt
— Manipulated variable rate tuning weightsTo specify runtime manipulated variable rate tuning weights, enable this input port. If this port is disabled, the block uses the tuning weights specified in the Weights.ManipulatedVariablesRate
property of its controller object. These tuning weights penalize large changes in control moves.
If the MPC controller object uses constant manipulated variable rate tuning weights over the prediction horizon, you can specify only constant manipulated variable tuning rate weights at runtime. Similarly, if the MPC controller object uses manipulated variable rate tuning weights that vary over the prediction horizon, you can specify only timevarying manipulated variable rate tuning weights at runtime
To use the same tuning weights over the prediction horizon, connect du.wt to a row vector signal with N_{mv} elements, where N_{mv} is the number of manipulated variables. Each element specifies a nonnegative tuning weight for a manipulated variable rate. For more information on specifying tuning weights, see Tune Weights.
To vary the tuning weights over the prediction horizon from time k to time k+p1, connect du.wt to a matrix signal with N_{mv} columns and up to p rows. Here, k is the current time and p is the prediction horizon. Each row contains the tuning weights for one prediction horizon step. If you specify fewer than p rows, the tuning weights in the final row apply for the remainder of the prediction horizon. For more information on varying weights over the prediction horizon, see TimeVarying Weights and Constraints.
To enable this port, select the MVRate weights parameter.
ecr.wt
— Slack variable tuning weightTo specify a runtime slack variable tuning weight, enable this input port and connect a scalar signal. If this port is disabled, the block uses the tuning weight specified in the Weights.ECR
property of its controller object.
The slack variable tuning weight has no effect unless your controller object defines soft constraints whose associated ECR values are nonzero. If there are soft constraints, increasing the ecr.wt value makes these constraints relatively harder. The controller then places a higher priority on minimizing the magnitude of the predicted worstcase constraint violation.
To enable this port, select the ECR weight parameter.
mv
— Optimal manipulated variable control actionOptimal manipulated variable control action, output as a column vector signal of length N_{mv}, where N_{mv} is the number of manipulated variables. The Multiple MPC Controllers block passes the output of the active controller to the mv output port.
If the solver of the active controller converges to a local optimum solution (qp.status is positive), then mv contains the optimal solution.
If the solver fails (qp.status is negative), then mv remains at its most recent successful solution; that is, the controller output freezes.
If the solver reaches the maximum number of iterations without finding an optimal
solution (qp.status is zero) and the
Optimization.UseSuboptimalSolution
property of the active
controller is:
true
, then mv contains the suboptimal
solution
false
, then mv then
mv remains at its most recent successful solution
cost
— Objective function costObjective function cost, output as a nonnegative scalar signal. The cost quantifies the degree to which the controller has achieved its objectives. The cost value is calculated using the scaled MPC cost function in which every term is offsetfree and dimensionless.
The cost value is only meaningful when the qp.status output is nonnegative.
To enable this port, select the Optimal cost parameter.
qp.status
— Optimization statusOptimization status of the active controller, output as an integer signal.
If the active controller solves the QP problem for a given control interval, the qp.status output returns the number of QP solver iterations used in computation. This value is a finite, positive integer and is proportional to the time required for the calculations. Therefore, a large value means a relatively slow block execution for this time interval.
The QP solver can fail to find an optimal solution for the following reasons:
qp.status = 0
— The QP solver cannot
find a solution within the maximum number of iterations specified in the
mpc
object. In this case, if the
Optimizer.UseSuboptimalSolution
property of the active
controller is false
, the block holds its
mv output at the most recent successful solution.
Otherwise, it uses the suboptimal solution found during the last solver
iteration.
qp.status = 1
— The QP solver
detects an infeasible QP problem. See Monitoring Optimization Status to Detect Controller Failures for an example
where a large, sustained disturbance drives the output variable outside its
specified bounds. In this case, the block holds its mv
output at the most recent successful solution.
qp.status = 2
— The QP solver has
encountered numerical difficulties in solving a severely illconditioned QP
problem. In this case, the block holds its mv output at the
most recent successful solution.
In a realtime application, you can use qp.status to set an alarm or take other special action.
To enable this port, select the Optimization status parameter.
est.state
— Estimated controller statesEstimated controller states of the active controller, output as a vector signal. The estimated states include the plant, disturbance, and noise model states.
To enable this port, select the Estimated controller states parameter.
mv.seq
— Optimal manipulated variable sequenceOptimal manipulated variable sequence, returned as a matrix signal with p+1 rows and N_{mv} columns, where p is the prediction horizon and N_{mv} is the number of manipulated variables.
The first p rows of mv.seq contain the calculated optimal manipulated variable values from current time k to time k+p1. The first row of mv.seq contains the current manipulated variable values (output mv). Since the controller does not calculate optimal control moves at time k+p, the final two rows of mv.seq are identical.
To enable this port, select the Optimal control sequence parameter.
x.seq
— Optimal prediction model state sequenceOptimal prediction model state sequence, returned as a matrix signal with p+1 rows and N_{x} columns, where p is the prediction horizon and N_{x} is the number of states.
The first p rows of x.seq contain the calculated optimal state values from current time k to time k+p1. The first row of x.seq contains the current estimated state values. Since the controller does not calculate optimal states at time k+p, the final two rows of x.seq are identical.
To enable this port, select the Optimal state sequence parameter.
y.seq
— Optimal output variable sequenceOptimal output variable sequence, returned as a matrix signal with p+1 rows and N_{y} columns, where p is the prediction horizon and N_{y} is the number of output variables.
The first p rows of y.seq contain the calculated optimal output values from current time k to time k+p1. The first row of y.seq is computed based on the current estimated states and the current measured disturbances (first row of input md). Since the controller does not calculate optimal output values at time k+p, the final two rows of y.seq are identical.
To enable this port, select the Optimal output sequence parameter.
Cell Array of MPC Controllers
— Candidate controllersmpc
objects  cell array of strings  cell array of character vectorsCandidate controllers, specified as one of the following:
The specified array must contain at least two candidate controllers. The first entry in the cell array is the controller that corresponds to a switch input value of 1, the second corresponds to a switch input value of 2, and so on.
Block Parameter:
mpcobjs 
Type: string, character vector, cell array of strings, cell array of character vectors 
Default:
"" 
Cell Array of Initial Controller States
— Initial statempcstate
objects  cell array of strings  cell array of character vectorsInitial states for the candidate controllers, specified as one of the following:
Cell array of mpcstate
objects.
Cell array of strings or a cell array of character vectors, where each element
is the name of an mpcstate
object in the MATLAB workspace.
{[],[],...}
, {'[]','[]',...}
, or
{"[]","[]",...}
— Use the nominal condition defined in
Model.Nominal
property of each candidate controller as its
initial state.
Use this parameter make the controller states reflect the true plant environment at
the start of your simulation to the best of your knowledge. This initial states can
differ from the nominal states defined in the mpc
objects.
If custom state estimation is enabled, the block ignores Cell Array of Initial Controller States parameter.
Block Parameter:
x0s 
Type: string, character vector, cell array of strings, cell array of character vectors 
Default:
"" 
Measured disturbances
— Add measured disturbance input portIf your controller has measured disturbances, you must select this parameter to add the md output port to the block.
Block Parameter:
md_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"on" 
External manipulated variable
— Add external manipulated variable input portSelect this parameter to add the ext.mv input port to the block.
Block Parameter:
mv_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Targets for manipulated variables
— Add manipulated variable target input portSelect this parameter to add the mv.target input port to the block.
Block Parameter:
uref_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Optimal cost
— Odd optimal cost output portSelect this parameter to add the cost output port to the block.
Block Parameter:
return_cost_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Optimization status
— Add optimization status output portSelect this parameter to add the qp.status output port to the block.
Block Parameter:
return_qpstatus_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Estimated controller states
— Add estimated states output portSelect this parameter to add the est.state output port to the block.
Block Parameter:
return_state_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Optimal control sequence
— Add optimal control sequence output portSelect this parameter to add the mv.seq output port to the block.
Block Parameter:
return_mvseq_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Optimal state sequence
— Add optimal state sequence output portSelect this parameter to add the x.seq output port to the block.
Block Parameter:
return_xseq_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Optimal output sequence
— Add optimal output sequence output portSelect this parameter to add the y.seq output port to the block.
Block Parameter:
return_ovseq_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Use custom state estimation instead of using the builtin Kalman filter
— Use custom state estimate input portSelect this parameter to remove the mo input port and add the x[kk] input port.
Block Parameter:
state_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Lower OV limits
— Add minimum OV constraint input portSelect this parameter to add the ymin input port to the block.
Block Parameter:
ymin_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Upper OV limits
— Add maximum OV constraint input portSelect this parameter to add the ymax input port to the block.
Block Parameter:
ymax_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Lower MV limits
— Add minimum MV constraint input portSelect this parameter to add the umin input port to the block.
Block Parameter:
umin_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Upper MV limits
— Add maximum MV constraint input portSelect this parameter to add the umax input port to the block.
Block Parameter:
umax_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Custom constraints
— Add custom constraints input portsSelect this parameter to add the E, F, G, and S input ports to the block.
Block Parameter:
cc_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
OV weights
— Add OV tuning weights input portSelect this parameter to add the y.wt input port to the block.
Block Parameter:
ywt_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
MV weights
— Add MV tuning weights input portSelect this parameter to add the u.wt input port to the block.
Block Parameter:
uwt_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
MVRate weights
— Add MV rate tuning weights input portSelect this parameter to add the du.wt input port to the block.
Block Parameter:
duwt_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Slack variable weight
— Add ECR tuning weight input portSelect this parameter to add the ecr.wt input port to the block.
Block Parameter:
rhoeps_inport_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
Inherit sample time
— Inherit block sample time from parent subsystemSelect this parameter to inherit the sample time of the parent subsystem as the block sample time. Doing so allows you to conditionally execute this block inside FunctionCall Subsystem or Triggered Subsystem blocks. For an example, see Using MPC Controller Block Inside FunctionCall and Triggered Subsystems.
You must execute FunctionCall Subsystem or Triggered Subsystem blocks at the sample rate of the controller. Otherwise, you can see unexpected results.
To view the sample time of a block, in the Simulink^{®} Editor, select Display > Sample Time. Select Colors, Annotations, or All. For more information, see View Sample Time Information (Simulink).
Block Parameter:
SampleTimeInherited_multiple 
Type: string, character vector 
Values:
"off" , "on" 
Default:
"off" 
mv.seq
output port signal dimensions have changedBehavior changed in R2018b
The signal dimensions of the mv.seq
output port of the
Multiple MPC Controllers block have changed. Previously, this signal was a
pbyN_{mv} matrix, where
p is the prediction horizon and
N_{mv} is the number of manipulated variables. Now,
mv.seq
is a
(p+1)byN_{mv} matrix, where
row p+1 duplicates row p.
您点击了调用以下 MATLAB 命令的链接:
Web 浏览器不支持 MATLAB 命令。请在 MATLAB 命令窗口中直接输入该命令以运行它。
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.