Validating MPC controller with parameters

9 views (last 30 days)
I have an MPC controller, and build it with the following script:
nx = 11;
ny = 11;
nu = 13;
nlobj = nlmpc(nx,ny,nu);
nlobj.Model.NumberOfParameters=28;
nlobj.Model.StateFcn="nonlinear_eom";
% nlobj.Jacobian.StateFcn=???;
Ts=0.4;
p=20;
nlobj.Ts=Ts;
nlobj.PredictionHorizon=p;
nlobj.ControlHorizon=p;
nlobj.Optimization.CustomCostFcn= @(X,U,e,data) Ts*sum(sum(U(1:(p+1),1:4)));
% nlobj.Optimization.CustomCostFcn= @(X,U,e,data) Ts*sum(sum(U(1:p,1:4)));
nlobj.Optimization.ReplaceStandardCost=true;
% nlobj.Optimization.CustomEqConFcn=???;% @(X,U,data) X(end,:)';
for ct=1:nu
if ct>=1 && ct<=4
nlobj.MV(ct).Min=-3;
nlobj.MV(ct).Min=3;
elseif ct==5 || ct==7
nlobj.MV(ct).Min=-1;
nlobj.MV(ct).Max=1;
elseif ct==6
nlobj.MV(ct).Min=-1;
nlobj.MV(ct).Max=10;
else
nlobj.MV(ct).Min=-6;
nlobj.MV(ct).Max=6;
end
end
x0 = rand(1,nx);
u0 = rand(1,nu);
validateFcns(nlobj,x0,u0,params)
Where params is defined as a 1x28 cell array. When I validate nlobj as:
validateFcns(nlobj,x0,u0,[],params)
It gives me the following error:
Error using nlmpc/validateFcns (line 175)
Expecting 30 input arguments but "Model.StateFcn" appears to take 3 inputs.
Error in mpc_validation_test (line 129)
validateFcns(nlobj,x0,u0,[],params)
The equation of motion contain 11 states and 13 control variables, so I have no clue where the number 30 is coming from.
  2 Comments
Alessandro Maria Laspina
Alessandro Maria Laspina on 16 Mar 2022
Edited: Alessandro Maria Laspina on 16 Mar 2022
No, I could not figure it out from the documentation so I abandoned the method. Althought I would still appreciate any insight if you know how the parameters are meant to be written.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!