Why does my Nonlinear MPC stop working in Accelerator mode after I change any parameter?

5 次查看(过去 30 天)
Hi everyone,
I’m using a Nonlinear MPC controller inside the Powertrain Blockset (MATLAB 2022b). The project was sent to me by someone else, and if I run it exactly as received, everything works fine — especially in Accelerator mode.
However, as soon as I change any parameter in the NMPC controller (even something simple like a weight), the simulation throws this error when I try to run it in Accelerator mode:
Function 'optimoptions' not supported for code generation.
Function 'Nonlinear MPC Controller/MPC/NLMPC' (#2417.5243.5834), line 131, column 11:
"optimoptions(..."
Component: MATLAB Function | Category: Coder error
I tried switching the simulation to Normal mode instead. It starts, but after about 40 seconds, it fails — probably because the solver can’t satisfy the constraints anymore (maybe due to tuning of weights or rate limits).
I’m a bit stuck now. Why does simply editing the NMPC break Accelerator mode? Is there any workaround? And how can I prevent the simulation from failing in Normal mode after editing?

回答(1 个)

Jaskirat
Jaskirat 2025-6-10
Hello @Jacopo,
Accelerator mode relies on Simulink coder to generate and compile C/C++ code.However the built-in NMPC controller’s internal MATLAB function uses the “optimoptions” function, which is not supported for code generation. Hence once you make any change which forces recompilation, the Accelerator mode fails.
As a workaround, you can create a MATLAB function that calls “optimoptions”, declare it as extrinsic, and call it from within your NMPC block.You can refer to the following MATLAB Answer to know more about the given workaround:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Powertrain Blockset 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by