Custom cost function nlmpc

5 次查看(过去 30 天)
Kasper
Kasper 2023-5-11
Hi I designed a Non linear mpc for a differential wheeled robot using the nlmpc function. The mpc has 7 states and 2 manipulated variables.
I want to design my own cost function to be J = x_e'*Q*x_e + u_e'*R*u_e;
where x_e is the state error and u_e is the input error (Q and R are weight matrices).
I d the following
nlobj = nlmpc(nx,ny,nu);
nlobj.Ts = Ts_mpc;
nlobj.PredictionHorizon = N;
nlobj.ControlHorizon = Nc;
nlobj.Model.IsContinuousTime = false;
nlobj.Optimization.ReplaceStandardCost = true;
nlobj.Model.StateFcn = @MPC_state_function;
nlobj.Optimization.CustomCostFcn = @Cost_function;
However doing this I get a dimensioning error in simulink (using the nonlinear mpc block), it states that my manipulated variables (mv) output from the block is 1 for some reason.
The error is:
Error using Main
Compilation of model 'Robot_model' failed while trying to resolve underspecified signal dimensions.
Suggested Actions:
Enable 'warning' or 'error' diagnostics for the list of underspecified signal dimensions. - Open
Caused by:
Error using Main
Error in port widths or dimensions. The signal connected to the "last_mv" port of the "Robot_model/Control/Nonlinear MPC Controller" block must be a row or column vector signal with 2
elements.
What is causing this? if I go back to not specify my own cost function it works fine, there should be no error in the cost function as the help page states that the output of the cost function should be a scalar.
Best regards
  1 个评论
Emmanouil Tzorakoleftherakis
编辑:Emmanouil Tzorakoleftherakis 2023-5-16
Hi,
There is not enough information to find the reason you are getting this error. If you share a reproduction model I can take a look.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Plant Specification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by