The error seems to be in your bus definition. You don't provide that so take a closer look and see if you set things properly. Also, since you are using parameters in your NMPC design, make sure that you provide the same parameters as input arguments to your model functions, cost function, constraint functions, and Jacobians. See example below for more details:
Using NLMPC on vehicle dynamics
5 次查看(过去 30 天)
显示 更早的评论
Ragavendra Joshi
2023-4-28
回答: Emmanouil Tzorakoleftherakis
2023-5-1
The code below generates NLMPC objects and uses greycar model for vehicle dynamics system. And also there is simulink implementation of the code. But there is an error. So, please help me with this.
%making grey car model
FileName = 'vehicle_c'; % File describing the model structure.
Order = [3 5 3]; % Model orders [ny nx nu].
Parameters = [1700; 1.5; 1.5; 404; 404; 0.5]; % Initial parameters.
InitialStates = [1; 0; 0]; % Initial value of initial states.
ts= 0;
sys = idnlgrey(FileName, Order, Parameters, InitialStates, ts, ...
'Name', 'vehicle model', 'TimeUnit', 's');
present(sys)
%non linear mpc parameters
nx=3; %no of states
nu=5; %no of parameters
ny=3; %no of outputs
%defining non linear mpc
nlobj= nlmpc(nx,ny,nu);
%defining parameters
Ts=0.1;
nlobj.Ts=Ts
nlobj.PredictionHorizon=10;
nl.ControlHorizon=2;
%parameters of mpc variables
nlobj.Weights.OutputVariables = [3,3,3];
nlobj.Weights.ManipulatedVariablesRate = [10,10,10,10,10];
nlobj.OV(1).Min = 1;
nlobj.OV(1).Max = 10;
nlobj.OV(2).Min = 1;
nlobj.OV(2).Max = 10;
nlobj.OV(3).Min = 1;
nlobj.OV(3).Max = 10;
nlobj.MV(1).Min = 1;
nlobj.MV(1).Max = 10;
nlobj.MV(2).Min = 1;
nlobj.MV(2).Max = 10;
nlobj.MV(3).Min = 1;
nlobj.MV(3).Max = 10;
nlobj.MV(4).Min = 1;
nlobj.MV(4).Max = 10;
nlobj.MV(5).Min = 1;
nlobj.MV(5).Max = 10;
%assigning values to mpc model
nlobj.Model.StateFcn = "sys";
nlobj.Model.IsContinuousTime = true;
nlobj.Model.NumberOfParameters = 6;
nlobj.Model.OutputFcn = @(x,u,Ts) [y(1) ;y(2) ;y(3)];
%initial state
x0=[0.1,0.2,-pi/2];
% Set the parameter values
mass = 1700;
lf = 1.5;
lr = 1.5;
car = 404;
caf = 404;
air = 0.5;
%createParameterBus(nlobj, 'myBusObject',Parameters
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Code Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!