-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplotWaypointDubins.m
139 lines (110 loc) · 3.15 KB
/
plotWaypointDubins.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
function [hAx, pDubins] = plotWaypointDubins(V, E, X, opts)
% PLOTWAYPOINTDubins plots dubins paths on top of figure
% =================== Check Arguments ========================
if nargin < 1
error('No input arguments given!');
elseif nargin > 4
error('Too many arguments given!');
end
if isempty(V)
error('V is empty!');
end
if isempty(E)
error('E is empty!');
end
if isempty(X)
error ('X is empty');
end
if (min(X) < 0 || max(X) > 2*pi)
error('X has invalid elements');
end
[n, ~] = size(V);
[m, ~] = size(E);
if (n ~= length(X))
error('Length of V and X do not match');
end
if (m ~= (n + strcmp(opts.Circuit, 'on') - 1))
error('E dimensions not compatible with V');
end
%================= Dependencies ====================
% Add Dubins plot tool
if exist('dubins') ~= 3
if exist('lib/DubinsPlot') ~= 7
error('Could not find the DubinsPlot folder.');
end
addpath('lib/DubinsPlot');
if exist('dubins') ~= 3
error('Could not find compiled dubins mex file.');
end
end
% ======================== Setup ============================
PATH_COLOR = opts.DubinsPathColor;
% Normalization
%V = normalizePoints(V);
if strcmp(opts.NormalizePlots, 'on')
md = normalizationCoeff(V);
else
md = 1;
end
% Get waypoint order
order = getVertexOrder(E);
% ====================== Plot Dubins =========================
position = V(1,:);
heading = X(1);
C_total = 0;
pDubins = [];
if strcmp(opts.Debug,'on')
vertexOrder = order;
end
for i=2:(m+1)
% Generate Dubins path
theta_0 = heading2angle(heading);
q0 = [position(1:2) theta_0];
vi = order(i); % get index of vertex in tour
if i < (m+1) || (i <= (m+1) && strcmp(opts.Circuit,'off'))
theta_1 = heading2angle(X(vi));
q1 = [V(vi,:) theta_1];
else
% Return to start or first node
if (strcmp(opts.CircuitInitial,'on'))
theta_1 = heading2angle(X(1));
q1 = [V(1,:) theta_1];
else
theta_1 = heading2angle(X(order(2)));
q1 = [V(order(2),:) theta_1];
end
end
path = dubins(q0, q1, opts.TurnRadius, opts.DubinsStepSize);
pDubins = [pDubins; path(1,:)', path(2,:)'];
if strcmp(opts.Debug,'on')
c = 0;
for j=2:length(path)
c_i = sqrt((path(1,j) - path(1,j-1))^2 + (path(2,j) - path(2,j-1))^2);
c = c + c_i;
end % for
C_total = C_total + c;
%fprintf('Cost of leg (%i,%i) is %0.2f\n', order(i-1), vi, c);
end
% Update position
position = q1(1:2);
heading = X(order(i));
% Plot path
hold on;
hPath = plot(path(1,1:end)/md,path(2,1:end)/md, 'Color', PATH_COLOR);
hold off;
% Remove legend entries for duplicates
if (i > 2)
disableLegendEntry(hPath);
end
end
if strcmp(opts.Debug,'on')
fprintf('Simulated Dubins'' path with cost %0.2f\n', C_total);
end
% set(hAx,'DataAspectRatioMode', 'auto');
% set(hAx,'PlotBoxAspectRatioMode', 'auto');
% set(hAx,'DataAspectRatio', [1 1 1]);
% set(hAx,'PlotBoxAspectRatio', [1 1 1]);
% Plot headings
hAx = gca;
plotWaypointHeadings(hAx, V./md, X, opts);
end % function plotWaypointDubins