-
Notifications
You must be signed in to change notification settings - Fork 13
/
dubinsParameters.m
executable file
·161 lines (154 loc) · 5.58 KB
/
dubinsParameters.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
% dubinsParameters
% - Find Dubin's parameters between two configurations
%
% input is:
% start_node - [wn_s, we_s, wd_s, chi_s, 0, 0]
% end_node - [wn_e, wn_e, wd_e, chi_e, 0, 0]
% R - minimum turn radius
%
% output is:
% dubinspath - a matlab structure with the following fields
% dubinspath.ps - the start position in re^3
% dubinspath.chis - the start course angle
% dubinspath.pe - the end position in re^3
% dubinspath.chie - the end course angle
% dubinspath.R - turn radius
% dubinspath.L - length of the Dubins path
% dubinspath.cs - center of the start circle
% dubinspath.lams - direction of the start circle
% dubinspath.ce - center of the end circle
% dubinspath.lame - direction of the end circle
% dubinspath.w1 - vector in re^3 defining half plane H1
% dubinspath.q1 - unit vector in re^3 along straight line path
% dubinspath.w2 - vector in re^3 defining position of half plane H2
% dubinspath.w3 - vector in re^3 defining position of half plane H3
% dubinspath.q3 - unit vector defining direction of half plane H3
%
function dubinspath = dubinsParameters(start_node, end_node, R)
ell = norm(start_node(1:2)-end_node(1:2));
if ell<2*R,
disp('The distance between nodes must be larger than 2R.');
dubinspath = [];
else
ps = start_node(1:3);
chis = start_node(4);
pe = end_node(1:3);
chie = end_node(4);
crs = ps' + R*rotz(pi/2)*[cos(chis); sin(chis); 0];
cls = ps' + R*rotz(-pi/2)*[cos(chis); sin(chis); 0];
cre = pe' + R*rotz(pi/2)*[cos(chie); sin(chie); 0];
cle = pe' + R*rotz(-pi/2)*[cos(chie); sin(chie); 0];
% compute L1
connecting_line = cre-crs;
north_unit = [1; 0; 0];
% theta = acos(dot(connecting_line,north_unit)/norm(connecting_line));
theta = atan2(connecting_line(2), connecting_line(1));
L1 = norm(crs-cre) + R*mod(2*pi + mod(theta-pi/2, 2*pi) - mod(chis-pi/2, 2*pi), 2*pi) ...
+ R*mod(2*pi + mod(chie-pi/2, 2*pi) - mod(theta-pi/2, 2*pi), 2*pi);
% compute L2
connecting_line = cle-crs;
ell = norm(connecting_line);
% theta = acos(dot(connecting_line,north_unit)/norm(connecting_line));
theta = atan2(connecting_line(2), connecting_line(1));
theta2 = theta - pi/2 + asin(2*R/ell);
if isreal(theta2)==0,
L2 = 9999;
else
L2 = sqrt(ell^2-4*R^2) + R*mod(2*pi + mod(theta2, 2*pi) - mod(chis-pi/2, 2*pi), 2*pi) ...
+ R*mod(2*pi + mod(theta2+pi, 2*pi) - mod(chie+pi/2, 2*pi), 2*pi);
end
% compute L3
connecting_line = cre-cls;
ell = norm(connecting_line);
% theta = acos(dot(connecting_line,north_unit)/norm(connecting_line));
theta = atan2(connecting_line(2), connecting_line(1));
theta2 = acos(2*R/ell);
if isreal(theta2)==0,
L3 = 9999;
else
L3 = sqrt(ell^2-4*R^2) + R*mod(2*pi + mod(chis+pi/2, 2*pi) - mod(theta+theta2, 2*pi), 2*pi) ...
+ R*mod(2*pi + mod(chie-pi/2, 2*pi) - mod(theta+theta2-pi, 2*pi), 2*pi);
end
% compute L4
connecting_line = cle-cls;
% theta = acos(dot(connecting_line,north_unit)/norm(connecting_line));
theta = atan2(connecting_line(2), connecting_line(1));
L4 = norm(cls-cle) + R*mod(2*pi + mod(chis+pi/2, 2*pi) - mod(theta+pi/2, 2*pi), 2*pi) ...
+ R*mod(2*pi + mod(theta+pi/2, 2*pi) - mod(chie+pi/2, 2*pi), 2*pi);
% L is the minimum distance
[L,idx] = min([L1,L2,L3,L4]);
e1 = [1; 0; 0]; % north unit vector
switch(idx),
case 1,
cs = crs;
lams = 1;
ce = cre;
lame = 1;
q1 = (ce-cs)/norm(ce-cs);
w1 = cs + R*rotz(-pi/2)*q1;
w2 = ce + R*rotz(-pi/2)*q1;
case 2,
cs = crs;
lams = 1;
ce = cle;
lame = -1;
ell = norm(ce-cs);
connecting_line = ce - cs;
theta = atan2(connecting_line(2), connecting_line(1));
% theta = acos(dot(ce-cs,e1)/ell);
theta2 = theta - pi/2 + asin(2*R/ell);
q1 = rotz(theta2+pi/2)*e1;
w1 = cs + R*rotz(theta2)*e1;
w2 = ce + R*rotz(theta2+pi)*e1;
case 3,
cs = cls;
lams = -1;
ce = cre;
lame = 1;
ell = norm(ce-cs);
connecting_line = ce - cs;
% theta = acos(dot(ce-cs,e1)/ell);
theta = atan2(connecting_line(2), connecting_line(1));
theta2 = acos(2*R/ell);
q1 = rotz(theta+theta2-pi/2)*e1;
w1 = cs + R*rotz(theta+theta2)*e1;
w2 = ce + R*rotz(theta+theta2-pi)*e1;
case 4,
cs = cls;
lams = -1;
ce = cle;
lame = -1;
q1 = (ce-cs)/norm(ce-cs);
w1 = cs + R*rotz(pi/2)*q1;
w2 = ce + R*rotz(pi/2)*q1;
end
w3 = pe';
q3 = rotz(chie)*e1;
% assign path variables
dubinspath.ps = ps;
dubinspath.chis = chis;
dubinspath.pe = pe;
dubinspath.chie = chie;
dubinspath.R = R;
dubinspath.L = L;
dubinspath.cs = cs;
dubinspath.lams = lams;
dubinspath.ce = ce;
dubinspath.lame = lame;
dubinspath.w1 = w1;
dubinspath.q1 = q1;
dubinspath.w2 = w2;
dubinspath.w3 = w3;
dubinspath.q3 = q3;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% rotz(theta)
%% rotation matrix about the z axis.
function R = rotz(theta)
R = [...
cos(theta), -sin(theta), 0;...
sin(theta), cos(theta), 0;...
0, 0, 1;...
];
end