Main Content

Implement MPC Controllers using Embotech FORCES PRO Solvers

You can use FORCES PRO, 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 FORCES PRO. 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 FORCES PRO MPC plugin, see the FORCES PRO Documentation. You can also use Forces PRO solvers for other optimization applications in both MATLAB® and Simulink®. For more information, see the FORCES PRO 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 (prediction model does not change at run time) in MATLAB using the Embotech FORCES PRO 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, states, and online data using mpcToForces.

  4. If needed, adjust the controller states in the variables containing the states 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 myMPCmoveMex
    codegen('-config',cfg,'mpcmoveForces','-o','myMex',...
            '-args',{coder.Constant(coredata), statedata, onlinedata});

    % call the executable from the MATLAB command line
    [mv, statedata, info] = myMex(coredata, statedata, onlinedata)

To design and simulate a linear time-invariant MPC controller in Simulink using the Embotech FORCES PRO 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 FORCES PRO 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, see the Embotech FORCES PRO QP solver documentation.

Note

Using the QP Embotech FORCES PRO 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 FORCES PRO NLP solver, follow these steps.

  1. Design a nonlinear controller using an nlmpc object.

  2. Specify custom solver generation options using nlmpcToForcesOptions. You can choose to use an interior-point (IP) solver or a sequential quadratic programming (SQP) solver. Use the IP solver if your nonlinear MPC problem has 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 nlmpcToForces.

  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. A MEX file is automatically generated from nlmpcmoveForces to speed up the simulation in MATLAB.

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

  1. Design a nonlinear controller using an nlmpc object.

  2. Specify custom solver generation options using nlmpcToForcesOptions. You can choose to use an Interior-Point (IP) solver or a Sequential Quadratic Programming (SQP) solver. Use the IP solver if your nonlinear MPC problem has long prediction horizon and a large number of constraints.

  3. Generate the custom solver and the related variables using nlmpcToForces.

  4. Open the Simulink library browser, find the FORCES Nonlinear MPC block under the FORCES PRO 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 FORCES PRO Solver is only supported when the nonlinear MPC problem satisfies all the following conditions:

  • The custom cost and constraint functions are not used.

  • The state and output functions are compatible with MATLAB code generation and with CasADi.

  • 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 a Pendulum Using Nonlinear Model Predictive Control.

Related Topics