Simulate switching between multiple MPC controllers
The Multiple MPC Controllers block receives the current measured output, reference signal, and measured disturbance signal. It then solves a quadratic program to calculate the optimal manipulated variables. It also receives a switching signal that designates which one of two or more controllers is to perform the calculation (i.e., the active controller). The block contains these controllers as MPC objects, each of which is designed for a particular operating region of a nonlinear plant.
The Multiple MPC Controllers block allows you to achieve better control of a nonlinear plant over a range of operating conditions. A controller that works well initially can degrade if the plant is nonlinear and its operating point changes. In conventional feedback control, you might compensate for this degradation by gain scheduling. In a similar manner, the Multiple MPC Controllers block allows you to transition between multiple MPC controllers in real time in a preordained manner. You design each controller to work well in a particular region of the operating space. When the plant moves away from this region, you instruct another MPC controller to take over.
The Multiple MPC Controllers block does not provide all the optional features found in the MPC Controller block. The following ports are currently not available:
Optional outports such as optimal cost, optimal control sequence, and optimization status
Optional inports for online tuning
The MPC Controller block has the following parameter groupings:
The table is an ordered list of MPC objects. The first row designates the controller to be used when the switch input equals a certain number. The first designates which controller is used when the switch input equals 1, the second when the switch input equals 2, and so on. These controllers must refer to objects that already exist in your base workspace.
Note After entering each MPC object name, press Enter. Also press Enter after editing an object name.
Use Add and Delete to add and remove rows. When deleting, indicate any rows to delete using the Delete It check box.
When the edit box is empty, and the block is connected to the plant, clicking the Design button constructs a default MPC controller. This controller is constructed using a linearized plant model from the Simulink diagram. This action also opens the design tool so you can modify the default behavior.
You can also start the design tool by selecting one or more MPC objects using the Design It check box and then clicking Design. All selected MPC objects are loaded into the design tool where you can review and edit their properties.
Initial state of each MPC object in the ordered list. Each must be a valid mpcstate object. If no value is supplied, the default is the nominal value defined in the Model.Nominal property of the mpc object.
The switch input signal must be a scalar integer between 1 and nc, where nc is the number of controllers listed in your block mask. At each control instant, this signal designates the controller that will be used.
At each control instant, the mo signal must contain the current output variable measurements. Let nym be the number of measured output variables (MO) defined in your predictive controller. If nym=1, connect a scalar signal to the mo inport. Otherwise, connect a row or column vector signal containing nym real, double-precision elements.
At each control instant, the ref signal must contain the current reference values (targets or setpoints) for the ny output variables (ny = nym+ number of unmeasured outputs). You have the option to specify future reference values (previewing).
The ref signal must be size N by ny, where is the number of time steps for which you are specifying reference values and p is the prediction horizon. Each element must be a real, double-precision number. The ref dimension must not change from one control instant to the next.
When N=1, you cannot preview. To specify future reference values, choose N such that to enable previewing. Doing so usually improves performance via feedforward information. The first row specifies the ny references for the first step in the prediction horizon (at the next control interval k=1), and so on for N steps. If N<p, the last row designates constant reference values to be used for the remaining p-N steps.
For example, suppose ny=2 and p=6. At a given control instant, the signal connected to the controller's ref inport is
[2 5 ← k=1 2 6 ← k=2 2 7 ← k=3 2 8] ← k=4
The signal informs the controller that:
Reference values for the first prediction horizon step (k=1) are 2 and 5.
The first reference value remains at 2, but the second increases gradually.
The second reference value becomes 8 at the beginning of the fourth step (k=4) in the prediction horizon.
Both values remain constant at 2 and 8 respectively for steps 5–6 of the prediction horizon.
The mv outport provides a signal defining the manipulated variables, which are to be implemented in the plant. The controller updates its mv outport by solving a quadratic program at each control instant. The elements are real, double-precision values.
Add an inport (md) to which you can connect a measured disturbance signal.
Your measured disturbance signal (MD) must be size Nxnmd, where is the number of measured disturbances defined in your Model Predictive Controller and is the number of time steps for which the MD is known. Each element must be a real, double-precision number. The signal dimensions must not change from one control instant to the next.
If N=1 you cannot preview. At each control instant, the MD signal must contain the most recent measurements at the current time k=0 (as a row vector, length nmd). The controller assumes that the MDs remain constant at their current values for the entire prediction horizon.
If you are able to predict future MD values, choose N such that to enable previewing. Doing so usually improves performance via feedforward. In this case, the first row must contain the nmd current values at k=0, and the remaining rows designate variations over the next N-1 control instants. If N<p+1, the last row designates constant MD values to be used for the remaining p+1-N steps of the prediction horizon.
For example suppose nmd=2 and p=6. At a given control instant, the signal connected to the controller's md inport is:
[2 5 ← k=0 2 6 ← k=1 2 7 ← k=2 2 8] ← k=3
This signal informs the controller that:
The current MDs are 2 and 5 at k=0.
The first MD remains at 2, but the second increases gradually.
The second MD becomes 8 at the beginning of the step 3 (k=3) in the prediction horizon.
Both values remain constant at 2 and 8 respectively for steps 4–6 of the prediction horizon.
mpcpreview shows how to use MD previewing in a specific case.
Add an inport (ext.mv), which you can connect to the actual manipulated variables (MV) used in the plant. The block uses these to update its internal state estimates. For example, suppose the actual signals saturate at physical limits or the MV is under manual control. In both cases, feeding the actual value back to the MPC Controller block can improve performance significantly, because the prediction model's state estimates are updated more accurately.
The following example shows how a manual switch may override the controller's output. Also see Turning Controller Online and Offline with Bumpless TransferTurning Controller Online and Offline with Bumpless Transfer.
Do not connect this option to leave the ext.mv inport unconnected. In either case, the model predictive controller assumes that the plant uses the MV signals sent by the MPC Controller block. In the preceding example, the external MV signal always provides the model predictive controller that the control signal actually used in the plant. Otherwise, the model predictive controller's internal state estimate would be inaccurate.
Note The MPC Controller block is a discrete-time block with sampling time inherited from the MPC object. The MPC block has direct feedthrough from measured outputs (mo), output references (ref), and measured disturbances (md) to MPC-manipulated variables (mv). There is no direct feedthrough from externally supplied manipulated variables (ext.mv) to MPC-manipulated variables (mv).
Add inports (umin,umax,ymin,ymax ), which you can connect to run-time constraint signals. If this check box is not selected, the block uses the constant constraint values stored within its mpc object. Example connections appear in the following model. See Varying Input and Output ConstraintsVarying Input and Output Constraints for an example of using this option.
Each unconnected limit inport, such as ymin in the following model, is treated as an unbounded signal. The corresponding constraint settings in the mpc object must also be unbounded. For connected limit inports, such as ymax, the signals must be finite and the corresponding variables in the mpc object must also be bounded.
All constraint signals connected to the block must be finite. Also, you cannot change the number or identity of constrained and unconstrained variables. For example, if your mpc object specifies that your first MV has a lower bound, you must supply a umin signal for it.
Specify the data type of the manipulated variables (MV) as one of the following:
double — Double-precision floating point (default).
single — Single-precision floating point.
You specify the output data type as single if you are implementing the model predictive controller on a single-precision target.
For an example of double- and single-precision simulation and code generation for an MPC controller, see Simulation and Code Generation Using Simulink Coder.
To view the port data types in a model, in the Simulink® Editor, select Display > Signals & PortsPort Data Types. For more information, see Display Port Data Types.
Use the sample time inherited from the parent subsystem as the Multiple MPC Controllers block's sample time.
Inheriting the sample time allows you to conditionally execute the Multiple MPC Controllers block inside the Function-Call Subsystem or Triggered Subsystem blocks. For an example, see Using MPC Controller Block Inside Function-Call and Triggered Subsystems.
Note: When you place an MPC controller inside a Function-Call Subsystem or Triggered Subsystem block, you must execute the subsystem at the controller's design sample rate. You may see unexpected results if you use an alternate sample rate.
To view the sample time of a block, in the Simulink model window, select Display > Sample Time. Select Colors, Annotations, or All. For more information, see View Sample Time Information.