Nonlinear MPC Controller Toolbox error
1 view (last 30 days)
Show older comments
When using the Nonlinear MPC Controller toolbox, the internal MV port width is always reported error , but no errors were found after several checks. Please help me to look at it!
The code and error are as follows:
%% Lane Following Using Nonlinear Model Predictive Control
%% Overview of Simulink Model
% Open the Simulink model:
mdl = 'LaneFollowingNMPC';
open_system(mdl)
%% Parameters of Vehicle Dynamics and Road Curvature.
% Specify the vehicle dynamics parameters
m = 1575; % Mass of car
Iz = 2875; % Moment of inertia about Z axis
lf = 1.2; % Distance between Center of Gravity and Front axle
lr = 1.6; % Distance between Center of Gravity and Rear axle
Cf = 19000; % Cornering stiffness of the front tires (N/rad)
Cr = 33000; % Cornering stiffness of the rear tires (N/rad).
%%
% Set the initial and driver-set velocities.
v0 = 20; % Initial velocity
v_set = 20; % Driver set velocity
%%
% Set the controller sample time.
Ts = 0.1;
%%
% Obtain the lane curvature information.
% seconds.
Duration = 15; % Simulation duration
t = 0:Ts:Duration; % Time vector
rho = LaneFollowingGetCurvature(v_set,t); % Signal containing curvature information
%%
nlobj = nlmpc(4,2,'MV',1,'MD',2);
%%
% Specify the controller sample time, prediction horizon, and control horizon.
nlobj.Ts = Ts;
nlobj.PredictionHorizon = 10;
nlobj.ControlHorizon = 2;
%%
% Specify the state function for the nonlinear plant model and its
% Jacobian.
nlobj.Model.StateFcn = @(x,u) LaneFollowingStateFcn(x,u);
nlobj.Jacobian.StateFcn = @(x,u) LaneFollowingStateJacFcn(x,u);
%%
% Specify the output function for the nonlinear plant model and its
% Jacobian. The output variables are:
%
% * Lateral deviation
% * the yaw angle
%
nlobj.Model.OutputFcn = @(x,u) [x(3);x(4)];
nlobj.Jacobian.OutputFcn = @(x,u) [0 0 1 0 ;0 0 0 1];
%%
% Set the constraints for manipulated variables.
nlobj.MV(1).Min = -1.13; % Minimum steering angle -65
nlobj.MV(1).Max = 1.13; % Maximum steering angle 65
%%
nlobj.OV(1).ScaleFactor = 0.5; % Range for lateral deviation
nlobj.OV(2).ScaleFactor = 0.5; % Range for relative yaw angle
nlobj.MV(1).ScaleFactor = 2.26; % Range of steering angle
nlobj.MD(1).ScaleFactor = 0.2; % Range of Curvature
%%
% Specify the weights in the standard MPC cost function. The third output,
% yaw angle, is allowed to float because there are only two manipulated
% variables to make it a square system. In this example, there is no
% steady-state error in the yaw angle as long as the second output, lateral
% deviation, reaches 0 at steady state.
nlobj.Weights.OutputVariables = [1 0];
%%
% Penalize acceleration change more for smooth driving experience.
nlobj.Weights.ManipulatedVariablesRate = 0.1;
%%
% Validate prediction model functions at an arbitrary operating point using
% the |validateFcns| command. At this operating point:
%
% * |x0| contains the state values
% * |u0| contains the input values
% * |ref0| contains the output reference values
% * |md0| contains the measured disturbance value
%
x0 = [0.1 0.5 0.1 0.001];
u0 = 0.4;
ref0 = [0 0];
md0 = 0.1;
validateFcns(nlobj,x0,u0,md0,{},ref0);
%% Compare Controller Performance
% To compare the results of NLMPC and AMPC, simulate the model and
% save the logged data.
%%
% First, simulate the model using nonlinear MPC.
controller_type = 1; % Set the variant for nonlinear MPC.
sim(mdl)
logsout1 = logsout;
%%
% Second, simulate the model using adaptive MPC.
% controller_type = 2; % Set the variant for adaptive MPC.
% sim(mdl)
logsout2 = logsout;
%%
% Plot and compare simulation results.
LaneFollowingCompareResults(logsout1,logsout2)
%%
% Copyright 2018 The MathWorks, Inc.

0 Comments
Answers (0)
See Also
Categories
Find more on Nonlinear MPC Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!