Custom cost function nlmpc

7 ビュー (過去 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 日
編集済み: 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 Center および File ExchangeLinear Plant Specification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by