Nonlinear MPC hard constraints
Afficher commentaires plus anciens
Is there a way to make custom inequality constraint functions in the nonlinear mpc functions to be a hard constraint and not a slacked constraint? I have been trying to design a nonlinear mpc that needs a custom constraint but it seems by default this is slacked, and it would be highly infeasible if it was strictly enforced.
Réponses (1)
In the Model Predictive Control Toolbox, the default implementation of MPC uses slack variables to handle constraints. Setting these slack variables to zero converts the constraints into hard constraints. The constraint violation penalty weight indicates the weightage given to the slack variable in a minimization problem, as detailed here:
Raising this weight to a high value makes the constraints stricter.
Here's how it can be done:
- If using the standard cost function and the propertynlmpc.Optimization.ReplaceStandardCostis set tofalse, increasing thenlmpc.Weights.ECRvalue raises the weight on the slack variables. More details are available here:
- When specifying a custom cost function for a nonlinear MPC controller, it's possible to replace or augment the standard quadratic MPC cost function. By default, anlmpccontroller replaces the standard cost function with the custom one, treating all constraints as hard constraints.
- To combine standard and custom costs, setnlmpc.Optimization.ReplaceStandardCostto false, similar to the first scenario, allowing adjustments to thenlmpc.Weights.ECR property.

The attached file example_R2024b.m contains a simple example with a custom cost function andnlmpc.Optimization.ReplaceStandardCostset totrue, treating the constraint
as a hard constraint.
The plot of the states shows that state x remains within 5, even when the reference/desired state is 10.
For more detailed information, check out these pages:
- Specify Constraints for Nonlinear MPC:https://www.mathworks.com/help/releases/R2024b/mpc/ug/specify-constraints-for-nonlinear-mpc.html
- Specify Cost Function for Nonlinear MPC:https://www.mathworks.com/help/releases/R2024b/mpc/ug/specify-cost-function-for-nonlinear-mpc.html
I believe this will assist you!
2 commentaires
Tristan
le 26 Nov 2024
The attached example specifies a custom cost function named 'customCostFcn' along with a custom inequality constraint funtion named 'customConstraintFcn'. They are added to the nlmpc object, 'nlobj' by the following lines in the attached code.

Catégories
En savoir plus sur Nonlinear MPC Design dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!