Using NLMPC on vehicle dynamics
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ragavendra Joshi
am 28 Apr. 2023
Beantwortet: Emmanouil Tzorakoleftherakis
am 1 Mai 2023
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 Kommentare
Akzeptierte Antwort
Emmanouil Tzorakoleftherakis
am 1 Mai 2023
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Code Generation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!