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!