Using NLMPC on vehicle dynamics
6 ビュー (過去 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 件のコメント
採用された回答
Emmanouil Tzorakoleftherakis
2023 年 5 月 1 日
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:
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!