Too many input arguments in nmpcblock_interface
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Sreeram
el 7 de Mayo de 2025
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 comentarios
Ver también
Categorías
Más información sobre Model Predictive Control Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!