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.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:
Compilation of model 'Robot_model' failed while trying to resolve underspecified signal dimensions.
• Enable 'warning' or 'error' diagnostics for the list of underspecified signal dimensions. - Open
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
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