Main Content

Implement MPC Controllers Using Embotech FORCESPRO Solvers

You can use FORCESPRO, a real-time embedded optimization software tool developed by Embotech AG, to simulate and generate code for linear and nonlinear MPC controllers designed using Model Predictive Control Toolbox™ software. Embotech provides a plugin that leverages the design capabilities of Model Predictive Control Toolbox software and the computational performance of FORCESPRO. Using the plugin, you can generate custom solvers that allow deployment on real-time hardware and that are highly optimized, based on your specific MPC problem, to achieve satisfactory real-time performance.

For more information on using the FORCESPRO MPC plugin, see the FORCESPRO Documentation. You can also use FORCESPRO solvers for other optimization applications in both MATLAB® and Simulink®. For more information, see the FORCESPRO Third Party Products and Services.

For information on generating code in MATLAB and Simulink for Model Predictive Control Toolbox controllers, see Generate Code and Deploy Controller to Real-Time Targets.

Embotech Quadratic Programming (QP) Solver

To design and simulate a linear time-invariant MPC controller (one in which the prediction model does not change at run time) in MATLAB using the Embotech FORCESPRO QP solver, follow these steps.

  1. Design a linear controller using an mpc object.

  2. Create a custom solver generation option object for the solver using mpcToForcesOptions with a string input argument that is either "sparse" (to build a sparse QP problem), or "dense" (to build a dense QP problem). Use "sparse" if your MPC problem has a long prediction horizon and a large number of constraints.

  3. Generate the custom solver and the related variables containing structures for the core, state, and online data using mpcToForces.

  4. If needed, adjust the controller state in the variables containing the state data structure, and specify run-time signals in the variable containing the online data structure.

  5. Simulate the system by iteratively calling mpcmoveFORCES. For sparse QP problems, a MEX file is automatically generated and used to speed up the simulation.

You can also generate production code. For example, to generate a MEX file from mpcmoveForces with a dense QP formulation, where the variables coredata, statedata, and onlinedata were created by mpcToForces, you can use this code:

% configure code generation to create a MATLAB executable
cfg = coder.config('mex'); % or LIB, EXE, etc.
cfg.ConstantInputs = 'IgnoreValues';

% create an executable named myMex
codegen('-config',cfg,'mpcmoveForces','-o','myMex',...
        '-args',{coder.Constant(coredata), statedata, onlinedata});

% calculate the manipulated variables by calling the myMex executable
[mv, statedata, info] = myMex(coredata, statedata, onlinedata)

To design and simulate a linear time-invariant MPC controller in Simulink using the Embotech FORCESPRO QP solver solver, follow these steps.

  1. Design a linear controller using an mpc object.

  2. Create a custom solver generation option object for the solver using mpcToForcesOptions with a string input argument that is either "sparse" (to build a sparse QP problem), or "dense" (to build a dense QP problem). Use "sparse" if your MPC problem has a long prediction horizon and a large number of constraints.

  3. Generate the custom solver and the related variables containing structures for the core, states, and online data using mpcToForces.

  4. Add the appropriate block to your model:

    • For a sparse QP problem, open the Simulink library browser, find the FORCES MPC (Sparse QP) block under the FORCESPRO MPC Blocks category, and add it to your model.

    • For a dense QP problem, open the Simulink library browser, find the MPC Controller block under the Model Predictive Control Toolbox category, and add it to your model.

  5. Specify structure variables in the block dialog:

    • For a sparse QP problem, specify the variables containing the core and states data structures.

    • For a dense QP problem, specify the mpc object.

  6. Simulate the system.

  7. When needed, generate code directly from the model or the block.

For more information on how to use QP solvers with Model Predictive Control Toolbox, see QP Solvers.

For more information on the FORCESPRO QP solver, see the Embotech FORCESPRO QP solver documentation.

Note

Using the QP Embotech FORCESPRO Solver for Adaptive MPC controllers or MPC controllers with custom constraints is not supported.

Embotech Nonlinear Programming (NLP) Solver

To design and simulate a nonlinear MPC controller in MATLAB using the Embotech FORCESPRO NLP solver, follow these steps.

  1. Design a nonlinear controller using an nlmpc or nlmpcMultistage object.

  2. Specify custom solver generation options using nlmpcToForcesOptions (or nlmpcMultistageToForcesOptions, if you designed a multistage controller in the previous step). For an nlmpc object, you can choose to use the sequential quadratic programming (SQP) solver instead of the interior-point (IP) solver. Use the IP solver if your nonlinear MPC problem has long prediction horizon and a large number of constraints. For nlmpcMultistage objects only the IP solver is available.

  3. Generate the custom solver and the related variables containing structures for the core, states, and online data using nlmpcToForces, (or nlmpcMultistageToForces).

  4. Specify current controller states, last control action, and use the variable containing the online data structure to specify other run-time signals.

  5. Simulate the system by iteratively calling nlmpcmoveForces (or nlmpcmoveForcesMultistage). A MEX file is automatically generated for the two functions to speed up the simulation in MATLAB.

To design and simulate a nonlinear MPC controller in Simulink using the Embotech FORCESPRO NLP solver, follow these steps.

  1. Design a nonlinear controller using an nlmpc or nlmpcMultistage object.

  2. Specify custom solver generation options using nlmpcToForcesOptions (or nlmpcMultistageToForcesOptions, if you designed a multistage controller in the previous step). For an nlmpc object, you can choose to use the sequential quadratic programming (SQP) solver instead of the interior-point (IP) solver. Use the IP solver if your nonlinear MPC problem has long prediction horizon and a large number of constraints. For nlmpcMultistage objects only the IP solver is available.

  3. Generate the custom solver and the related variables containing structures for the core, states, and online data using nlmpcToForces, (or nlmpcMultistageToForces).

  4. Open the Simulink library browser, find the FORCES Multistage Nonlinear MPC block under the FORCESPRO MPC Blocks category, and add it to your model.

  5. Specify the variable containing the core data structure in the block dialog.

  6. Simulate the system.

  7. When needed, generate code directly from the model or the block.

You can also generate code for your Simulink model as described in the section Code Generation in Simulink.

Note

Using the NLP Embotech FORCESPRO Solver is only supported when the state and output functions are compatible with MATLAB code generation and with CasADi. Additionally, for generic (that is non multistage) nonlinear MPC problems:

  • You must not use the custom cost and constraint functions.

  • If the nonlinear MPC controller uses multiple optional parameters, you must group them in a single column vector and set the Model.NumberOfParameters property of the controller to 1.

For an example on using the FORCES Nonlinear MPC block see Swing-Up Control of Pendulum Using Nonlinear Model Predictive Control.

See Also

Functions

Objects

Related Examples

More About

External Websites