-
Notifications
You must be signed in to change notification settings - Fork 8
/
initialize_si.m
executable file
·122 lines (116 loc) · 4.28 KB
/
initialize_si.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
%% initialization script
% common pre-run set up for simulation and experiment
%% Setup path
setPath;
%% Problem setup
global pr
% environment dimension
pr.dim = mode_dim; % problem dimension
xdim = [-5, 5]; % workspace
ydim = [-5, 5];
zdim = [ 0, 3];
if pr.dim == 2
pr.ws = [xdim; ydim];
elseif pr.dim == 3
zdim = [0, 10];
pr.ws = [xdim; ydim; zdim];
end
% robot physics
pr.robot_type = 0; % robot type
pr.radius = 0.2; % robot radius
pr.maxSpeed = 0.4; % robot maximal speed
pr.boundLocalRadius = 2.0; % local bound radius, m
% simulation setup
pr.dtSim = 0.1; % time step, s
pr.N = 10; % number of stage
pr.ifSimRobotNoise = 1; % if simulating measurement noise
pr.ifSimBoxObsNoise= 1;
% collision probability threshold
pr.collision_probability = 0.10;
pr.collision_parameter = erfinv(2*sqrt(1-pr.collision_probability) - 1);
% BVC or BUAVC
pr.method = mode_region; % 0 - BVC; 1 - BUAVC
if pr.ifSimRobotNoise == 0
pr.method = 0;
fprintf('Simulate robot localization noise: No. \n');
fprintf('Computation of safe region: BVC. \n');
else
fprintf('Simulate robot localization noise: Yes. \n');
if pr.method == 0
fprintf('Computation of safe region: BVC. \n');
elseif pr.method == 1
fprintf('Computation of safe region: BUAVC. \n');
else
error('Safe region mode is not defined!');
end
end
pr.control = mode_control; % 0 - one-step; 1 - mpc
if pr.control == 0
fprintf('Controller mode: Feedback reactive. \n');
elseif pr.control == 1
fprintf('Controller mode: MPC. \n');
else
error('Controller mode is not defined!');
end
% weights
pr.weights = [0.0, 0.0; 1.0, 0.0]'; % w_pos, w_input, stage and terminal weights
%% Simulation configuration
global cfg
% visualization setup
cfg.ifShowHistoryTra = 1; % if plotting the history trajectory of the robot
cfg.ifShowSafeRegion = 1; % if plotting the obstacle-free safe region for each robot
cfg.ifShowVelocity = 0; % if plotting robot velocity
%% Scenario setup
% static obstacles
if pr.dim == 2
vert_m = 4;
[nBoxObs, boxPos, boxSize, boxYaw] = box_initial_2D(3);
elseif pr.dim == 3
vert_m = 8;
[nBoxObs, boxPos, boxSize, boxYaw] = box_initial_3D(3);
end
boxVert = zeros(pr.dim, vert_m, nBoxObs);
for iBox = 1 : nBoxObs
[temp_vert, ~] = box2PolyVertsCons(pr.dim, boxPos(:, iBox), ...
boxSize(:, iBox), boxYaw(:, iBox));
boxVert(:, :, iBox) = temp_vert; % dim * m * nBoxObs
end
% multiple robot, robot initial and end position should not collide with each other and with obstacles
nRobot = 5; % number of robots
collision_mtx = ones(nRobot, nRobot+nBoxObs);
while (sum(sum(collision_mtx)) > 0)
fprintf('Generating robot initial positions and goals ... \n');
if pr.dim == 2
robotStartPos = robotStartPos_2D(nRobot, 3, pr.ws(1,:), pr.ws(2,:), pr.radius);
% robotEndPos = robotStartPos_2D(nRobot, 2, pr.ws(1,:), pr.ws(2,:), pr.radius);
robotEndPos = -robotStartPos; % robot final goal position
elseif pr.dim == 3
robotStartPos = robotStartPos_3D(nRobot, 2, pr.ws(1,:), pr.ws(2,:), pr.ws(3,:), pr.radius);
robotEndPos(1:2, :) = -robotStartPos(1:2, :); % robot final goal position
robotEndPos(3, :) = zdim(1) + zdim(2) - robotStartPos(3, :);
end
collision_mtx_start = collision_check(nRobot, nBoxObs, robotStartPos, 1.2*pr.radius, boxVert);
collision_mtx_end = collision_check(nRobot, nBoxObs, robotEndPos, 1.2*pr.radius, boxVert);
collision_mtx = [collision_mtx_start; collision_mtx_end];
end
% robot localization measurement noise
robotPosNoise = zeros(pr.dim, pr.dim, nRobot);
for iRobot = 1 : nRobot
robotPosNoise(:, :, iRobot) = 0.10^2 * eye(pr.dim);
end
% obs localization measurment noise
boxPosNoise = zeros(pr.dim, pr.dim, nBoxObs);
for iBox = 1 : nBoxObs
boxPosNoise(:, :, iBox) = 0.10^2 * eye(pr.dim);
end
pr.nRobot = nRobot;
pr.robotStartPos = robotStartPos;
pr.robotEndPos = robotEndPos;
pr.robotPosNoise = robotPosNoise;
pr.nBoxObs = nBoxObs;
pr.boxPos = boxPos;
pr.boxSize = boxSize;
pr.boxYaw = boxYaw;
pr.boxPosNoise = boxPosNoise;
%% For mpc
si_mpc_setup;