Validating MPC controller with parameters

조회 수: 15 (최근 30일)
Alessandro Maria Laspina
Alessandro Maria Laspina 2021년 7월 4일
댓글: Ayorinde Bamimore 2023년 5월 24일
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
Alessandro Maria Laspina
Alessandro Maria Laspina 2022년 3월 16일
편집: Alessandro Maria Laspina 2022년 3월 16일
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 2023년 5월 24일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Refinement에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by