Validating MPC controller with parameters

8 Ansichten (letzte 30 Tage)
Alessandro Maria Laspina
Alessandro Maria Laspina am 4 Jul. 2021
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.
  3 Kommentare
Alessandro Maria Laspina
Alessandro Maria Laspina am 16 Mär. 2022
Bearbeitet: Alessandro Maria Laspina am 16 Mär. 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.
Ayorinde Bamimore
Ayorinde Bamimore am 24 Mai 2023
You are experiencing the errors because those 28 extra parameters are not defined in the "StateFcn". Although the parameters may not be used by the StateFcn but they still need to be defined.
You probably defined your StateFcn function as follows:
function dxdt = nonlinear_eom(x,u)
This basically contains two inuts arguments. By specifying the extra 28, that makes the total input arguments 30 (which is what the error is all about). So, your state function should be specified as follows:
function dxdt = nonlinear_eom(x,u,d1,d2,d3,....,d28).
In addition, you specify the extra parameters as input arguments in your output function as well.
I hope this helps.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by