Using NLMPC on vehicle dynamics

6 views (last 30 days)
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)
sys = Continuous-time nonlinear grey-box model defined by 'vehicle_c' (MEX-file): dx/dt = F(t, u(t), x(t), p1, ..., p6) y(t) = H(t, u(t), x(t), p1, ..., p6) + e(t) with 5 input(s), 3 state(s), 3 output(s), and 6 free parameter(s) (out of 6). Inputs: u(1) (t) u(2) (t) u(3) (t) u(4) (t) u(5) (t) States: Initial value x(1) x1(t) xinit@exp1 1 (fixed) in [-Inf, Inf] x(2) x2(t) xinit@exp1 0 (fixed) in [-Inf, Inf] x(3) x3(t) xinit@exp1 0 (fixed) in [-Inf, Inf] Outputs: y(1) (t) y(2) (t) y(3) (t) Parameters: Value p1 p1 1700 (estimated) in [-Inf, Inf] p2 p2 1.5 (estimated) in [-Inf, Inf] p3 p3 1.5 (estimated) in [-Inf, Inf] p4 p4 404 (estimated) in [-Inf, Inf] p5 p5 404 (estimated) in [-Inf, Inf] p6 p6 0.5 (estimated) in [-Inf, Inf] Name: vehicle model Status: Created by direct construction or transformation. Not estimated. More information in model's "Report" property. Model Properties
%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 =
nlmpc with properties: Ts: 0.1000 PredictionHorizon: 10 ControlHorizon: 2 Dimensions: [1×1 struct] Model: [1×1 struct] States: [1×3 struct] OutputVariables: [1×3 struct] ManipulatedVariables: [1×5 struct] MeasuredDisturbances: [] Weights: [1×1 struct] Optimization: [1×1 struct] Jacobian: [1×1 struct] Passivity: [1×1 struct]
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

Accepted Answer

Emmanouil Tzorakoleftherakis
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:

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!