Validating MPC controller with parameters
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
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 Center 和 File Exchange 中查找有关 Refinement 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!