Main Content

Explicit MPC Controller

Explicit model predictive controller

  • Explicit MPC Controller block

Libraries:
Model Predictive Control Toolbox

Description

The Explicit MPC Controller block uses the following input signals:

  • Either measured plant outputs (mo) or custom state estimate (x[k|k])

  • Reference or setpoint (ref)

  • Measured plant disturbance (md), if any

The Explicit MPC Controller block uses a lookup table to store the precalculated piecewise-affine optimal control law instead of solving a quadratic programming optimization problem at runtime at each control interval like the MPC Controller block. Given the same MPC problem, the two blocks return the same solution. The Explicit MPC Controller block requires less online computational effort, which is useful for applications that need a short control interval. It has, however, a heavier offline computational effort and a larger memory footprint. Indeed, the combinatorial nature of explicit MPC restricts its usage to applications with relatively few inputs, outputs, and state variables, a short prediction horizon, and few output constraints.

The Explicit MPC Controller supports only a subset of optional MPC features, as outlined in the following table.

Supported FeaturesUnsupported Features
  • Built-in (Kalman filter) and custom state estimation

  • Outport for state estimation results

  • External manipulated variable feedback signal inport

  • Single-precision block data (default is double precision)

  • Inherited sample time

  • Online tuning (penalty weight adjustments)

  • Online constraint adjustments

  • Online manipulated variable target adjustments

  • Reference and/or measured disturbance previewing

Ports

Input

expand all

Required Inputs

Measured outputs, specified as a vector signal. The block uses the measured plant outputs to improve its state estimates. If your controller uses default state estimation, you must connect the measured plant outputs to the mo input port. If your controller uses custom state estimation, you must connect the estimated plant states to the x[k|k] input port.

Dependencies

To enable this port, clear the Use custom state estimation instead of using the built-in Kalman filter parameter.

Custom state estimate, specified as a vector signal. The block uses the connected state estimates instead of estimating the states using the built-in estimator. If your controller uses custom state estimation, you must connect the current state estimates to the x[k|k] input port. If your controller uses default state estimation, you must connect the measured output to the mo input port.

Even though noise model states (if any) are not used in MPC optimization, the custom state vector must contain all the states defined in the mpcstate object of the controller, including the plant, disturbance, and noise model states.

Use custom state estimates when an alternative estimation technique is considered superior to the built-in estimator or when the states are fully measurable.

Dependencies

To enable this port, select the Use custom state estimation instead of using the built-in Kalman filter parameter.

At each control instant, the ref signal must contain the current reference values (targets or setpoints) for the ny output variables, where ny is the total number of outputs, including measured and unmeasured outputs. Since this block does not support reference previewing, ref must be a vector signal.

Additional Inputs

If your controller prediction model has measured disturbances, you must enable this port and connect to it a row vector signal containing Nmd elements, where Nmd is the number of measured disturbances.

Since this block does not support measured disturbance previewing, md must be a vector signal.

Dependencies

To enable this port, select the Measured disturbances parameter.

Control signals used in the plant at the previous control interval, specified as a vector signal of length Nmv, where Nmv is the number of manipulated variables. Use this input port to improve state estimation accuracy when:

  • You know your controller is not always in control of the plant.

  • The actual MV signals applied to the plant can potentially differ from the values generated by the controller, such as in control signal saturation.

Controller state estimation assumes that the MVs are piecewise constant. Therefore, at time tk, the ext.mv value must contain the effective MVs between times tk–1 and tk. For example, if the MVs are actually varying over this interval, you might supply the time-averaged value evaluated at time tk.

Note

  • Connect ext.mv to the MV signals actually applied to the plant in the previous control interval. Typically, these MV signals are the values generated by the controller, though this is not always the case. For example, if your controller is offline and running in tracking mode (that is, the controller output is not driving the plant), then feeding the actual control signal to ext.mv can help achieve bumpless transfer when the controller is switched back online.

  • When the controller is driving the plant, insert a Memory block or Unit Delay block to feed back the MV signal applied to the plant at the previous control interval. This also avoids a direct feedthrough from the ext.mv inport to the mv outport, therefore preventing algebraic loops in the Simulink® model.

For an example that uses the external manipulated variable input port for bumpless transfer, see Switch Controller Online and Offline with Bumpless Transfer.

Dependencies

To enable this port, select the External manipulated variable parameter.

To turn off the controller evaluation, connect switch to a nonzero signal.

Disabling controller evaluation reduces computational effort when the controller output is not needed, such as when the system is operating manually or another controller has taken over. However, the controller continues to update its internal state estimates in the usual way. Therefore, it is ready to resume evaluations whenever the switch signal returns to zero. While controller evaluation is off, the block passes the current ext.mv signal to the controller output. If the ext.mv inport is not enabled, the controller output is held at the value it had when evaluation was disabled.

For an example that uses the external manipulated variable input port for bumpless transfer, see Switch Controller Online and Offline with Bumpless Transfer.

Dependencies

To enable this port, select the Use external signal to enable controller evaluation parameter.

Output

expand all

Required Output

Optimal manipulated variable control action, returned as a column vector signal of length Nmv, where Nmv is the number of manipulated variables.

The controller updates its mv output at each control instant using the control law contained in the explicit MPC controller object. If the control law evaluation is not successful, mv is unchanged (that is, it is held at the previous successful result) and the status output, if present, becomes either 0 or –1.

Additional Outputs

This output indicates whether the latest explicit MPC control-law evaluation succeeded. The outport provides a scalar signal that has one of the following values:

  • 1 — Successful explicit control law evaluation

  • 0 — Failure due to one or more control law parameters out of range

  • –1 — Control law parameters were within the valid range but an extrapolation was necessary

If status is either 0 or –1, the mv outport remains at the last known good value.

Dependencies

To enable this port, select the Status of piecewise affine function evaluation parameter.

This output provides the index of the polyhedral region used in the latest explicit control law evaluation. If the control law evaluation fails, the signal at this outport is zero.

Dependencies

To enable this port, select the Region number of evaluated piecewise affine function parameter.

Estimated controller states at each control instant, returned as a vector signal. The estimated states include the plant, disturbance, and noise model states. If custom state estimation is used, this output signal has the same value as the x[k|k] input signal.

Dependencies

To enable this port, select the Estimated controller states parameter.

Parameters

expand all

An explicitMPC object containing the control law to be used. It must exist in the MATLAB® workspace. Use the generateExplicitMPC command to create this object.

Programmatic Use

Block Parameter: empcobj
Type: string, character vector
Default: ""

An optional mpcstate object specifying the initial controller state. If you leave this parameter blank, the block uses the nominal values defined in the Model.Nominal property of the explicitMPC object. To override the default values, create an mpcstate object in your workspace, and enter its name in the field. You can use this parameter to make the controller states reflect the true plant environment at the start of your simulation to the best of your knowledge.

If custom state estimation is enabled, the block ignores the Initial Controller State parameter.

Programmatic Use

Block Parameter: x0
Type: string, character vector
Default: ""
General Tab

If your controller has measured disturbances, you must select this parameter to add the md output port to the block.

Programmatic Use

Block Parameter: md_inport
Type: string, character vector
Values: "off", "on"
Default: "on"

Select this parameter to add the ext.mv input port to the block.

Programmatic Use

Block Parameter: mv_inport
Type: string, character vector
Values: "off", "on"
Default: "off"

Select this parameter to add the status output port to the block.

Programmatic Use

Block Parameter: return_status
Type: string, character vector
Values: "off", "on"
Default: "on"

Select this parameter to add the region output port to the block.

Programmatic Use

Block Parameter: return_region
Type: string, character vector
Values: "off", "on"
Default: "off"

Select this parameter to add the est.state output port to the block.

Programmatic Use

Block Parameter: return_state
Type: string, character vector
Values: "off", "on"
Default: "off"

Select this parameter to remove the mo input port and add the x[k|k] input port.

Programmatic Use

Block Parameter: state_inport
Type: string, character vector
Values: "off", "on"
Default: "off"
Others Tab

Specify the block data type of the manipulated variables as one of the following:

  • double — Double-precision floating point

  • single — Single-precision floating point

    If you are implementing the block on a single-precision target, specify the output data type as single.

  • data type expression — An expression that evaluates to either double or single. For more information, see Control Data Types of Signals (Simulink).

Programmatic Use

Block Parameter: BlockDataType
Type: string, character vector
Values: "double", "single", data type expression
Default: "double"

Select 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 Function-Call Subsystem (Simulink) or Triggered Subsystem (Simulink) blocks. For an example, see Using MPC Controller Block Inside Function-Call and Triggered Subsystems.

Note

You must execute Function-Call Subsystem or Triggered Subsystem blocks at the sample rate of the controller. Otherwise, you can see unexpected results for two reasons.

  • The first element of the MV rate vector (which is the difference between the current and the last value of the manipulated variable) is normally weighted and constrained assuming that the last MV value occurred in the past at the sample time specified in the MPC object, and when the block is executed with a different sample rate, this assumption no longer holds.

  • The built-in Kalman estimator uses the sample time specified in the MPC object to provide an estimation of the current state to the MPC optimization problem, so when the block is executed with a different sample time, the estimated state is no longer correct.

If you clear this parameter (default), the sample time of the block is inherited from the controller object.

To view the sample time of a block, in the Simulink model window, on the Debug tab, under Information Overlays, select either colors or Text. For more information, see View Sample Time Information (Simulink).

Programmatic Use

Block Parameter: SampleTimeInherited
Type: string, character vector
Values: "off", "on"
Default: "off"

Select this parameter to add the switch input port to the block. Whenever a nonzero signal is fed to the switch input port, the controller evaluation is turned off. See the switch input port for more details.

Programmatic Use

Block Parameter: switch_inport
Type: string, character vector
Values: "off", "on"
Default: "off"

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Version History

Introduced in R2014b