Too many input arguments in nmpcblock_interface

5 visualizaciones (últimos 30 días)
Ashwin
Ashwin el 28 de Abr. de 2025
Respondida: Sreeram el 7 de Mayo de 2025
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?

Respuestas (1)

Sreeram
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.
Hope this helps!

Categorías

Más información sobre Model Predictive Control Toolbox en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by