This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Adjust Horizons at Run Time

For both implicit and adaptive MPC controllers, you can adjust the prediction and control horizons while the controller operates. Doing so can be useful for:

  • Efficiently evaluating different horizon choices at run time during prototyping

  • Adjusting horizons without redeployment after plant dynamics change significantly, such as in a batch process

Adjust Horizons in MATLAB

To adjust the horizons at run time from the command line, at each control interval, specify the following properties of the mpcmoveopt object.

  • PredictionHorizon — Run-time prediction horizon signal, specified as a positive integer

  • ControlHorizon — Run-time control horizon signal, specified as a positive integer or a vector of positive integers

You can then pass the mpcmoveopt object to either mpcmove or mpcmoveAdaptive.

Adjust Horizons in Simulink

In Simulink®, to adjust the horizons for an MPC Controller or Adaptive MPC Controller block, select the Adjust prediction horizon and control horizon at run time parameter. Doing so adds the following input ports to the block:

  • p — Run-time prediction horizon signal, specified as a scalar integer signal

  • m — Run-time control horizon signal, specified as a scalar or vector signal

You must specify the maximum prediction horizon using the Maximum prediction horizon parameter. Doing so ensures that the optimal sequence output ports of the block (mv.seq, x.seq, and y.seq) have constant sizes with pmax+1 rows, where pmax is the maximum prediction horizon.

Code Generation

Run-time horizon tuning supports code generation in both MATLAB® and Simulink. Generating code for a controller that supports run-time horizon changes allows you to tune your horizon values on your deployed controller hardware.

After tuning the horizon values, to improve the computational efficiency of your final deployed controller, you can generate code for a constant-horizon controller using the tuned values.

Deploying your controller with run-time horizon tuning enabled significantly increases the computational load and memory footprint of your MPC application. If you plan to use run-time horizon tuning only for prototyping to find the proper horizon values, after tuning, ensure that this feature is disabled. You can then generate code with a constant-horizon controller using the tuned values.

If your controller uses manipulated variable blocking and you generate code for your controller, the size of the control horizon vector must remain constant at run-time. In this case, you can still tune the values within the control horizon vector.

Note

To generate code for a controller that uses run-time horizon tuning, your deployed hardware target must support dynamic memory allocation. For example, if your embedded system does not support the malloc C function, then the generated code will not run.

To generate code in MATLAB, set the 'UseVariableHorizon' name-value pair of getCodeGenerationData to true. At each control interval, you can then specify the horizons before calling mpcmoveCodeGeneration.

[configData,stateData,onlineData] = getCodeGenerationData(mpcobj,'UseVariableHorizon',true);
...
onlineData.Horizons.p = 10;
onlineData.Horizons.m = 3;
[u,stateData] = mpcmoveCodeGeneration(configData,stateData,onlineData);

Affect on Time-Varying Controller Parameters

If your application uses controller parameters that vary over the prediction horizon, adjusting the prediction horizon at run time affects the behavior of these time-varying parameters.

Constraints

If you define time-varying constraints in your controller object, the profile of the constraints across the prediction horizon does not change at run time. If your run-time prediction horizon value Pr is:

  • Greater than the length of the constraint profile specified in your controller, then the controller uses the final value of the constraint profile for the remainder of the prediction horizon

  • Less than the length of the constraint profile specified in your controller, then the controller truncates the constraint profile after Pr steps

For more information on adjusting constraints, see Update Constraints at Run Time.

Weights

To vary tuning weights at run-time, you specify weight arrays where the number of rows must not exceed the prediction horizons length. If you adjust the prediction horizon at run time, it is best practice to also adjust the number of rows in your tuning weight arrays to be consistent with the new horizon value.

If you do not adjust the sizes of your tuning weight arrays, the number of rows is extended or truncated in a manner similar to the time-varying constraint profile length.

For more information on tuning weights, see Tune Weights at Run Time.

Model and Nominal Conditions

For a linear time-varying MPC controller, you vary the plant model and nominal conditions across the prediction horizon. If you adjust the prediction horizon at run time, it is best practice to also adjust the lengths of your time-varying model and nominal condition arrays to be consistent with the new horizon value.

If you do not adjust the lengths of the model and nominal condition arrays, the arrays are extended or truncated in a manner similar to the time-varying constraint profile.

For more information on linear time-varying MPC, see Time-Varying MPC.

See Also

Blocks

Functions

Related Topics