Too many input arguments in nmpcblock_interface
5 次查看(过去 30 天)
显示 更早的评论
I am trying to define a simple cost function for my Nonlinear Model Predictive Control, but it seems to throw error as you can see below:
Error:Too many input arguments.
Error in nmpcblock_interface.m (line 165)
throw(ME)
Error in 'MPC_v2/MPC/Nonlinear MPC Controller/MPC/NLMPC' (line 24)
%% Interface to solver
[mv, cost, mvseq, xseq, yseq, nlpstatus, e] = nmpcblock_interface(blkData, ...
x, ref, lastMV, md, MVTarget, MVMin, MVMax, OutputMin, OutputMax, ...
MVRateMin, MVRateMax, StateMin, StateMax, OutputWeights, MVWeights, ...
MVRateWeights, ECRWeight, Parameters, MV0, X0, e0); %line 24
try
[mv, ~, Info] = nlmpcmove(nlobj, x, lastmv, ref, md, Options);
catch ME
throw(ME) %line165
This is my simple cost function that I used
function J = customCostFcn(U, data)
p = data.PredictionHorizon;
P_consumption = sum((U(1:p,1).^3));
J = P_consumption;
end
Can someone please help me solve this issue?
0 个评论
回答(1 个)
Sreeram
2025-5-7
According to the documentation "Specify Cost Function for Nonlinear MPC," a custom cost function for Nonlinear MPC must have one of the following signatures:
1. If your controller does not use optional parameters:
function J = myCostFunction(X,U,e,data)
2. If your controller uses parameters:
function J = myCostFunction(X,U,e,data,params)
In the code provided above, the 'customCostFcn' does not follow these requirements. Most likely, the NMPC controller is passing more arguments than 'customCostFcn' is designed to accept, which results in the "Too many input arguments" error.
For more details, please refer to the documentation: https://www.mathworks.com/help/releases/R2023b/mpc/ug/specify-cost-function-for-nonlinear-mpc.html#mw_e92b2434-4b1a-414f-9f32-413936351fdb
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model Predictive Control Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!