-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsiso_mpc_control.m
85 lines (52 loc) · 1.58 KB
/
siso_mpc_control.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
% THIS SCRIPT IMPLEMENTS A MPC CONTROLLER FOR TRAJECTORY TRACKING OF ROBOT
% MOTION
%% CONFIGURATION SPACE
% X-AXIS: 0...50
% Y_AXIS: 0...50
%% INITIALIZE
% Scenario 1
%init_scen_1;
% Scenario 2
init_scen_2;
% Scenario 3
%init_scen_3;
%% OBTAIN MODEL
% Lateral model
robot_sys_ss= lateral_2_dof_model(robot_vel, mass, I_zz, C_f, C_r, l_f, l_r);
robot_sys_ss= c2d(robot_sys_ss, h);
%% OBTAIN TRAJECTORY
%trajectory= robot_motion(robot_vel, robot_init_pos_path, h);
trajectory= trajectory_generator_apf(robot_vel, robot_init_pos_path, h);
% Get lateral coordinates
x_traj= trajectory(3,:);
% Get time vector
t_traj= trajectory(1,:);
% Reference Trajectory
ref_traj= timeseries(trajectory(3,:), trajectory(1,:), 'Name', 'reference_input');
%% MPC
% Prediction horizon and control horizon
% Crashes into obstacle
%prediction_horizon= 15;
%control_horizon= 4;
% prediction_horizon= 35;
prediction_horizon= 25;
control_horizon= 4;
mpcobj = mpc(robot_sys_ss, h);
mpcobj.PredictionHorizon= prediction_horizon;
mpcobj.ControlHorizon= control_horizon;
% INPUT CONSTRAINTS
% Maxmimum rate of change of wheel angle
max_delta_u= 30*(pi/180); %(rad/sec)
mpcobj.ManipulatedVariables.RateMin= -max_delta_u*h;
mpcobj.ManipulatedVariables.RateMax= max_delta_u*h;
% Maximum wheel angle
max_u= 40*(pi/180); %(rad)
mpcobj.ManipulatedVariables.Min= -max_u;
mpcobj.ManipulatedVariables.Max= max_u;
% Output weight
mpcobj.Weights.OutputVariables= 5;
%% SIMULATE SYSTEM RESPONSE (STATE SPACE)
% Run simulation
sim_out= sim('dof_dyn_mpc_control_sim', max(t_traj));
%% PLOT CONTROLLED MOTION
robot_motion_plot;