Main Content

Update Constraints at Run Time

To compensate for changing operating conditions, you can update constraints on plant inputs and outputs at run time. You can update the saturation limits for input and output signals as well as linear mixed input/output constraints.

Run-time constraint updating supports code generation.

Update Bounds on Input and Output Signals at Run Time

You can update the bounds on plant input and output signals at run time. To do so, first define initial signal bounds when designing your MPC controller. For more information, see Specify Constraints. If you do not specify initial bounds for a given signal, you cannot constrain that signal at run time.

To update signal bounds during a command-line simulation, at each control interval, set the corresponding properties of an mpcmoveopt object before calling mpcmove, mpcmoveAdaptive, or mpcmoveMultiple. To update:

  • Manipulated variable lower and upper bounds, set the MVMin and MVMax properties, respectively.

  • Output variable lower and upper bounds, set the OutputMin and OutputMax properties, respectively.

You can also update input and output bounds at run-time in Simulink® for the MPC Controller, Adaptive MPC Controller, and Multiple MPC Controllers blocks. The following table lists the bounds, their associated block ports, and the block parameters to select to enable the ports.

BoundsPort NameBlock Parameter
Lower bounds on manipulated variablesuminLower MV Limits
Upper bounds on manipulated variablesumaxUpper MV Limits
Lower bounds on output variablesyminLower OV Limits
Upper bounds on output variablesymaxUpper OV Limits

Connect signals to these ports that specify the run-time values of the bounds for each variable. If there is more than one manipulated variable or output variable, connect a vector signal to the corresponding ports. For example, if there are three output variables, connect a three-element vector signal to the ymin and ymax ports. If a variable is unconstrained in the controller object, then the connected signal value is ignored.


For any constraint that you set to -Inf or Inf, either across the whole prediction horizon (uniform) or at individual prediction horizon steps (time-varying), the corresponding variable remains unconstrained at run time; that is, you cannot modify it.

However, you can keep a variable unconstrained, so as to not distort your offline controller design, while maintaining the ability to add constraints online. To do so, set the bound to a large value when you create the controller. Do not use realmax as the large value, since doing so causes numerical issues at run time. You can then modify the constraint at run-time.

If you define time-varying constraints in your controller object, the new bounds are applied to the first finite values in the prediction horizon. All subsequent prediction horizon values adjust to maintain the same profile across the prediction horizon; that is, they change by the same amount.

For an example, see Vary Input and Output Bounds at Run Time.

Update Mixed Input/Output Constraints at Run Time

You can update mixed input/output constraints at run time. For more information on these constraints, see Constraints on Linear Combinations of Inputs and Outputs. This feature is not supported for gain-scheduled MPC controllers.

You can update the following constraint matrices during your simulation:

  • E — Manipulated variable constraint constant

  • F — Controlled output constraint constant

  • G — Mixed input/output constraint constant

  • S — Measured disturbance constraint constant

To do so, first define initial constraints using the setconstraint command. You cannot add additional constraints at run time.

To update mixed input/output constraints during a command-line simulation, in each control interval set the CustomConstraint property of an mpcmoveopt object before calling mpcmove or mpcmoveAdaptive. Specify CustomConstraint as a structure with E, F, G, and S fields. Specify each field as an array with dimensions that match the initial constraint arrays specified using setconstraint.

To update mixed input/output constraints during a Simulink simulation, select the Custom constraints parameter of your MPC Controller or Adaptive MPC Controller block. Doing so adds E, F, G, and S input ports to the block. The S input port is added only if your controller has measured disturbances.

Connect matrix signals to these ports that specify the run-time values for each array. If you define E, F, G, or S in your MPC controller, you must connect a signal to the corresponding input port, and that signal must have the same dimensions as the array specified in the controller. If an array is not defined in the controller object, use a zero matrix with the correct size.

For an example that updates mixed input/output constraints for an adaptive MPC controller, see Obstacle Avoidance Using Adaptive Model Predictive Control.

See Also


Related Examples

More About