-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrunScenario_Triangle.m
213 lines (192 loc) · 6.26 KB
/
runScenario_Triangle.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
%% Greedy point to point and line to line solution comparison
% Compares greedy PTP with brute force PTP for various scenarios.
%
% 2015.01.13
close all;
clear all;
clc;
% Add graph theory toolbox
if exist('grBase') ~= 2
if exist('GrTheory') ~= 7
error('Could not find the GrTheory folder.');
end
addpath('GrTheory');
end
% Add Dubins plot tool
if exist('dubins') ~= 3
if exist('DubinsPlot') ~= 7
error('Could not find the DubinsPlot folder.');
end
addpath('DubinsPlot');
if exist('dubins') ~= 3
error('Could not find compiled dubins mex file.');
end
end
%=============== Settings ===============
Va = 10; % (m/s) fixed airspeed
phi_max = degtorad(45); % (rad) maximum bank angle (+ and -)
g = 9.8; %(m/s^2)
% Path options
opts = PathOptions;
opts.LineTolTheta = degtorad(0.5);
opts.LineStepTheta = degtorad(45);
opts.TurnRadius = Va^2/(tan(phi_max)*g); % (m) turn radius for dubins path
opts.Circuit = 'on';
opts.Debug = 'on';
opts.MaximizeCost = 'off';
opts.BruteForce = 'off';
if strcmp(opts.Debug, 'on')
opts
end
% Plot settings
subplotDim = [2 2];
opts.ShowEdgeCosts = 'on';
opts.DubinsStepSize = 0.01; % [sec]
opts.EdgeArrowSize = 1;
opts.HeadingArrowSize = 0.15;
% Camera/sensor settings (assumes Theta_v = Theta_h)
Theta_horizontal = deg2rad(57.8); % [rad]
Theta_vertical = Theta_horizontal;
h = 120; % [m] altitude
A = (h*sin(Theta_horizontal)) * (h*sin(Theta_vertical)); % [m^2]
%================= Waypoints =================
% Create a triangle
triangleSize = 500;% [m]
xv = [0 1 0]' * triangleSize;
yv = [0 0 -10]' * triangleSize;
waypoints = polygrid(xv, yv, 1/A);
%plot(inPoints(:, 1),inPoints(:,2), '.k');
% Start position
startPosition = [0 -1]*triangleSize;
startHeading = 0; % [rad]
C = [startPosition, startHeading];
%waypoints = [xv, yv];
%waypointList = {[3,0; 3,-2]*50}; % 2 WPS
%waypointList = {[3,0; 5,0; 3,-2]*50}; % 3 WPS
%waypointList = {[3,0; 5,0; 3,-2; 5,-2 ]*50};
if strcmp(opts.Debug, 'on')
fprintf('# %s is running triangle (%i meter) scenario...\n-------------------------------------\n',...
mfilename, triangleSize);
end
%========================= Start ==============================
waypoints
V = sort(waypoints,2,'descend')
[n, ~] = size(V);
if strcmp(opts.Debug, 'on')
fprintf('## Solving scenario with %d waypoints...\n\n',...
n);
end
%%% Point to Point
%%=============== Initial Graph ===============
%figure('units','normalized','outerposition',[0 0 1 1])
%titleStr = sprintf('%d WP Scenario', n);
%fig = plotWaypointScenario(V, [], C, subplotDim, 1, titleStr, opts);
%uicontrol('Style', 'text',...
% 'String', sprintf('Point to Point Solutions'),...
% 'Units','normalized',...
% 'FontSize',15,...
% 'BackgroundColor', 'white',...
% 'Position', [0.345 0.965 0.29 0.037]);
%pause(0.5)
%
%%=================== Solve ==================
%% Greedy PTP Solution
%tic;
%[E, X, Cost] = solveGreedyPointToPoint(C,V,opts);
%c = Cost(1);
%vertexOrder = getVertexOrder(E)
%elapsedTime = toc;
%
%if strcmp(opts.Debug,'on')
% fprintf(['Found greedy PTP solution with a total cost of %.2f in %.2f seconds.\n\n'],...
% c, elapsedTime);
%end
%titleStr = sprintf('Greedy Solution (cost = %.2f)',c);
%hAx = plotWaypointScenario(V, E, C, subplotDim, 2, titleStr, opts);
%plotWaypointDubins(hAx, V, E, X, C, opts);
%
%% Brute force PTP Solution
%if strcmp(opts.BruteForce, 'on')
% % best
% opts.MaximizeCost = 'off';
% tic;
% [E, X, Cost] = solveBruteforcePointToPoint(C,V,opts);
% c = Cost(1);
% vertexOrder = getVertexOrder(E)
% if strcmp(opts.Debug,'on')
% disp('Best headings:')
% % Reorder X to match E
% Xhat = reorderHeadingsFromEdges(V, E, X, opts);
% rad2deg(Xhat)
% end
%
% elapsedTime = toc;
%
% if strcmp(opts.Debug,'on')
% fprintf(['Found brute force PTP solution with a total cost of %.2f in %.2f seconds.\n\n'],...
% c, elapsedTime);
% end
% titleStr = sprintf('Brute Force Solution (cost = %.2f)',c);
% hAx = plotWaypointScenario(V, E, C, subplotDim, 4, titleStr, opts, Cost(2), Cost(3));
% plotWaypointDubins(hAx, V, E, X, C, opts);
%
% % worst
% opts.MaximizeCost = 'on';
% [E, X, Cost] = solveBruteforcePointToPoint(C,V,opts);
% c = Cost(1);
% vertexOrder = getVertexOrder(E)
% if strcmp(opts.Debug,'on')
% disp('Worst headings:')
% % Reorder X to match E
% Xhat = reorderHeadingsFromEdges(V, E, X, opts);
% rad2deg(Xhat)
% end
%
% if strcmp(opts.Debug,'on')
% fprintf(['Found worst brute force PTP solution with a total cost of %.2f in %.2f seconds.\n\n'],...
% c, elapsedTime);
% end
% titleStr = sprintf('Brute Force Solution worst-case (cost = %.2f)',c);
% hAx = plotWaypointScenario(V, E, C, subplotDim, 3, titleStr, opts, Cost(2), Cost(3));
% plotWaypointDubins(hAx, V, E, X, C, opts);
%
%end % end of PTP brute force
%% Line to Line
%=============== Initial Graph ===============
figure();
titleStr = sprintf('%d WP Scenario', n);
fig = plotWaypointScenario(V, [], C, subplotDim, 1, titleStr, opts);
uicontrol('Style', 'text',...
'String', sprintf('Line to Line Solutions'),...
'Units','normalized',...
'FontSize',15,...
'BackgroundColor', 'white',...
'Position', [0.345 0.965 0.29 0.037]);
%=================== Solve ==================
% Greedy LTL Solution
tic;
V = sort(V,2);
[E, X, Cost] = solveGreedyLineToLine(C,V,opts);
c = Cost(1);
elapsedTime = toc;
if strcmp(opts.Debug,'on')
fprintf(['Found greedy LTL solution with a total cost of %.2f in %.2f seconds.\n\n'],...
c, elapsedTime);
end
titleStr = sprintf('Greedy Solution (cost = %.2f)',c);
hAx = plotWaypointScenario(V, E, C, subplotDim, 2, titleStr, opts, Cost(2), Cost(3));
plotWaypointDubins(hAx, V, E, X, C, opts);
% Brute Force LTL Solution
if strcmp(opts.BruteForce, 'on')
tic;
[E, X, Cost] = solveBruteforceLineToLine(C,V,opts);
c = Cost(1);
elapsedTime = toc;
if strcmp(opts.Debug,'on')
fprintf(['Found brute force LTL solution with a total cost of %.2f in %.2f seconds.\n\n'],...
c, elapsedTime);
end
titleStr = sprintf('Brute force Solution (cost = %.2f)',c);
hAx = plotWaypointScenario(V, E, C, subplotDim, 4, titleStr, opts, Cost(2), Cost(3));
plotWaypointDubins(hAx, V, E, X, C, opts);
end