pathplanning 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CurvesGenerator/__init__.py +1 -0
- CurvesGenerator/bezier_path.py +145 -0
- CurvesGenerator/bspline_curve.py +80 -0
- CurvesGenerator/cubic_spline.py +262 -0
- CurvesGenerator/draw.py +66 -0
- CurvesGenerator/dubins_path.py +351 -0
- CurvesGenerator/quartic_polynomial.py +43 -0
- CurvesGenerator/quintic_polynomial.py +143 -0
- CurvesGenerator/reeds_shepp.py +720 -0
- Sampling_based_Planning/__init__.py +1 -0
- Sampling_based_Planning/rrt_2D/__init__.py +1 -0
- Sampling_based_Planning/rrt_2D/adaptively_informed_trees.py +0 -0
- Sampling_based_Planning/rrt_2D/advanced_batch_informed_trees.py +0 -0
- Sampling_based_Planning/rrt_2D/batch_informed_trees.py +402 -0
- Sampling_based_Planning/rrt_2D/dubins_rrt_star.py +321 -0
- Sampling_based_Planning/rrt_2D/dynamic_rrt.py +342 -0
- Sampling_based_Planning/rrt_2D/env.py +45 -0
- Sampling_based_Planning/rrt_2D/extended_rrt.py +251 -0
- Sampling_based_Planning/rrt_2D/fast_marching_trees.py +220 -0
- Sampling_based_Planning/rrt_2D/informed_rrt_star.py +305 -0
- Sampling_based_Planning/rrt_2D/plotting.py +115 -0
- Sampling_based_Planning/rrt_2D/queue.py +62 -0
- Sampling_based_Planning/rrt_2D/rrt.py +114 -0
- Sampling_based_Planning/rrt_2D/rrt_connect.py +156 -0
- Sampling_based_Planning/rrt_2D/rrt_sharp.py +0 -0
- Sampling_based_Planning/rrt_2D/rrt_star.py +184 -0
- Sampling_based_Planning/rrt_2D/rrt_star_smart.py +311 -0
- Sampling_based_Planning/rrt_2D/utils.py +138 -0
- Sampling_based_Planning/rrt_3D/ABIT_star3D.py +148 -0
- Sampling_based_Planning/rrt_3D/BIT_star3D.py +353 -0
- Sampling_based_Planning/rrt_3D/FMT_star3D.py +192 -0
- Sampling_based_Planning/rrt_3D/__init__.py +1 -0
- Sampling_based_Planning/rrt_3D/dynamic_rrt3D.py +239 -0
- Sampling_based_Planning/rrt_3D/env3D.py +148 -0
- Sampling_based_Planning/rrt_3D/extend_rrt3D.py +102 -0
- Sampling_based_Planning/rrt_3D/informed_rrt_star3D.py +234 -0
- Sampling_based_Planning/rrt_3D/plot_util3D.py +167 -0
- Sampling_based_Planning/rrt_3D/queue.py +86 -0
- Sampling_based_Planning/rrt_3D/rrt3D.py +72 -0
- Sampling_based_Planning/rrt_3D/rrt_connect3D.py +187 -0
- Sampling_based_Planning/rrt_3D/rrt_star3D.py +107 -0
- Sampling_based_Planning/rrt_3D/rrt_star_smart3D.py +0 -0
- Sampling_based_Planning/rrt_3D/utils3D.py +416 -0
- Search_based_Planning/Search_3D/Anytime_Dstar3D.py +245 -0
- Search_based_Planning/Search_3D/Astar3D.py +119 -0
- Search_based_Planning/Search_3D/Dstar3D.py +192 -0
- Search_based_Planning/Search_3D/DstarLite3D.py +219 -0
- Search_based_Planning/Search_3D/LP_Astar3D.py +194 -0
- Search_based_Planning/Search_3D/LRT_Astar3D.py +87 -0
- Search_based_Planning/Search_3D/RTA_Astar3D.py +78 -0
- Search_based_Planning/Search_3D/__init__.py +1 -0
- Search_based_Planning/Search_3D/bidirectional_Astar3D.py +115 -0
- Search_based_Planning/Search_3D/env3D.py +147 -0
- Search_based_Planning/Search_3D/plot_util3D.py +155 -0
- Search_based_Planning/Search_3D/queue.py +154 -0
- Search_based_Planning/Search_3D/utils3D.py +359 -0
- Search_based_Planning/__init__.py +1 -0
- Search_based_Planning/plan2d/__init__.py +17 -0
- Search_based_Planning/plan2d/anytime_dstar.py +314 -0
- Search_based_Planning/plan2d/anytime_repairing_astar.py +220 -0
- Search_based_Planning/plan2d/astar.py +225 -0
- Search_based_Planning/plan2d/best_first_search.py +67 -0
- Search_based_Planning/plan2d/bidirectional_astar.py +229 -0
- Search_based_Planning/plan2d/breadth_first_search.py +69 -0
- Search_based_Planning/plan2d/depth_first_search.py +69 -0
- Search_based_Planning/plan2d/dijkstra.py +68 -0
- Search_based_Planning/plan2d/dstar.py +304 -0
- Search_based_Planning/plan2d/dstar_lite.py +239 -0
- Search_based_Planning/plan2d/learning_realtime_astar.py +230 -0
- Search_based_Planning/plan2d/lifelong_planning_astar.py +254 -0
- Search_based_Planning/plan2d/plan2d_facade.py +494 -0
- Search_based_Planning/plan2d/realtime_adaptive_astar.py +234 -0
- Search_based_Planning/plan2d/run.py +55 -0
- Search_based_Planning/plan2d/utils/__init__.py +1 -0
- Search_based_Planning/plan2d/utils/env.py +48 -0
- Search_based_Planning/plan2d/utils/plotting.py +258 -0
- Search_based_Planning/plan2d/utils/queue.py +62 -0
- pathplanning-0.1.0.dist-info/LICENSE +21 -0
- pathplanning-0.1.0.dist-info/METADATA +354 -0
- pathplanning-0.1.0.dist-info/RECORD +86 -0
- pathplanning-0.1.0.dist-info/WHEEL +5 -0
- pathplanning-0.1.0.dist-info/top_level.txt +4 -0
- pathplanningv2/__init__.py +29 -0
- pathplanningv2/api.py +18 -0
- pathplanningv2/registry.py +107 -0
- pathplanningv2/search2d.py +15 -0
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Batch Informed Trees (BIT*)
|
|
3
|
+
@author: damminhtien
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
import math
|
|
9
|
+
import random
|
|
10
|
+
import numpy as np
|
|
11
|
+
import matplotlib.pyplot as plt
|
|
12
|
+
import matplotlib.patches as patches
|
|
13
|
+
from scipy.spatial.transform import Rotation as Rot
|
|
14
|
+
|
|
15
|
+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
|
|
16
|
+
"/../../Sampling_based_Planning/")
|
|
17
|
+
|
|
18
|
+
from Sampling_based_Planning.rrt_2D import env, plotting, utils
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Node:
|
|
22
|
+
def __init__(self, x, y):
|
|
23
|
+
self.x = x
|
|
24
|
+
self.y = y
|
|
25
|
+
self.parent = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Tree:
|
|
29
|
+
def __init__(self, x_start, x_goal):
|
|
30
|
+
self.x_start = x_start
|
|
31
|
+
self.goal = x_goal
|
|
32
|
+
|
|
33
|
+
self.r = 4.0
|
|
34
|
+
self.V = set()
|
|
35
|
+
self.E = set()
|
|
36
|
+
self.QE = set()
|
|
37
|
+
self.QV = set()
|
|
38
|
+
|
|
39
|
+
self.V_old = set()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class BITStar:
|
|
43
|
+
def __init__(self, x_start, x_goal, eta, iter_max):
|
|
44
|
+
self.x_start = Node(x_start[0], x_start[1])
|
|
45
|
+
self.x_goal = Node(x_goal[0], x_goal[1])
|
|
46
|
+
self.eta = eta
|
|
47
|
+
self.iter_max = iter_max
|
|
48
|
+
|
|
49
|
+
self.env = env.Env()
|
|
50
|
+
self.plotting = plotting.Plotting(x_start, x_goal)
|
|
51
|
+
self.utils = utils.Utils()
|
|
52
|
+
|
|
53
|
+
self.fig, self.ax = plt.subplots()
|
|
54
|
+
|
|
55
|
+
self.delta = self.utils.delta
|
|
56
|
+
self.x_range = self.env.x_range
|
|
57
|
+
self.y_range = self.env.y_range
|
|
58
|
+
|
|
59
|
+
self.obs_circle = self.env.obs_circle
|
|
60
|
+
self.obs_rectangle = self.env.obs_rectangle
|
|
61
|
+
self.obs_boundary = self.env.obs_boundary
|
|
62
|
+
|
|
63
|
+
self.Tree = Tree(self.x_start, self.x_goal)
|
|
64
|
+
self.X_sample = set()
|
|
65
|
+
self.g_T = dict()
|
|
66
|
+
|
|
67
|
+
def init(self):
|
|
68
|
+
self.Tree.V.add(self.x_start)
|
|
69
|
+
self.X_sample.add(self.x_goal)
|
|
70
|
+
|
|
71
|
+
self.g_T[self.x_start] = 0.0
|
|
72
|
+
self.g_T[self.x_goal] = np.inf
|
|
73
|
+
|
|
74
|
+
cMin, theta = self.calc_dist_and_angle(self.x_start, self.x_goal)
|
|
75
|
+
C = self.RotationToWorldFrame(self.x_start, self.x_goal, cMin)
|
|
76
|
+
xCenter = np.array([[(self.x_start.x + self.x_goal.x) / 2.0],
|
|
77
|
+
[(self.x_start.y + self.x_goal.y) / 2.0], [0.0]])
|
|
78
|
+
|
|
79
|
+
return theta, cMin, xCenter, C
|
|
80
|
+
|
|
81
|
+
def planning(self):
|
|
82
|
+
theta, cMin, xCenter, C = self.init()
|
|
83
|
+
|
|
84
|
+
for k in range(500):
|
|
85
|
+
if not self.Tree.QE and not self.Tree.QV:
|
|
86
|
+
if k == 0:
|
|
87
|
+
m = 350
|
|
88
|
+
else:
|
|
89
|
+
m = 200
|
|
90
|
+
|
|
91
|
+
if self.x_goal.parent is not None:
|
|
92
|
+
path_x, path_y = self.ExtractPath()
|
|
93
|
+
plt.plot(path_x, path_y, linewidth=2, color='r')
|
|
94
|
+
plt.pause(0.5)
|
|
95
|
+
|
|
96
|
+
self.Prune(self.g_T[self.x_goal])
|
|
97
|
+
self.X_sample.update(self.Sample(m, self.g_T[self.x_goal], cMin, xCenter, C))
|
|
98
|
+
self.Tree.V_old = {v for v in self.Tree.V}
|
|
99
|
+
self.Tree.QV = {v for v in self.Tree.V}
|
|
100
|
+
# self.Tree.r = self.radius(len(self.Tree.V) + len(self.X_sample))
|
|
101
|
+
|
|
102
|
+
while self.BestVertexQueueValue() <= self.BestEdgeQueueValue():
|
|
103
|
+
self.ExpandVertex(self.BestInVertexQueue())
|
|
104
|
+
|
|
105
|
+
vm, xm = self.BestInEdgeQueue()
|
|
106
|
+
self.Tree.QE.remove((vm, xm))
|
|
107
|
+
|
|
108
|
+
if self.g_T[vm] + self.calc_dist(vm, xm) + self.h_estimated(xm) < self.g_T[self.x_goal]:
|
|
109
|
+
actual_cost = self.cost(vm, xm)
|
|
110
|
+
if self.g_estimated(vm) + actual_cost + self.h_estimated(xm) < self.g_T[self.x_goal]:
|
|
111
|
+
if self.g_T[vm] + actual_cost < self.g_T[xm]:
|
|
112
|
+
if xm in self.Tree.V:
|
|
113
|
+
# remove edges
|
|
114
|
+
edge_delete = set()
|
|
115
|
+
for v, x in self.Tree.E:
|
|
116
|
+
if x == xm:
|
|
117
|
+
edge_delete.add((v, x))
|
|
118
|
+
|
|
119
|
+
for edge in edge_delete:
|
|
120
|
+
self.Tree.E.remove(edge)
|
|
121
|
+
else:
|
|
122
|
+
self.X_sample.remove(xm)
|
|
123
|
+
self.Tree.V.add(xm)
|
|
124
|
+
self.Tree.QV.add(xm)
|
|
125
|
+
|
|
126
|
+
self.g_T[xm] = self.g_T[vm] + actual_cost
|
|
127
|
+
self.Tree.E.add((vm, xm))
|
|
128
|
+
xm.parent = vm
|
|
129
|
+
|
|
130
|
+
set_delete = set()
|
|
131
|
+
for v, x in self.Tree.QE:
|
|
132
|
+
if x == xm and self.g_T[v] + self.calc_dist(v, xm) >= self.g_T[xm]:
|
|
133
|
+
set_delete.add((v, x))
|
|
134
|
+
|
|
135
|
+
for edge in set_delete:
|
|
136
|
+
self.Tree.QE.remove(edge)
|
|
137
|
+
else:
|
|
138
|
+
self.Tree.QE = set()
|
|
139
|
+
self.Tree.QV = set()
|
|
140
|
+
|
|
141
|
+
if k % 5 == 0:
|
|
142
|
+
self.animation(xCenter, self.g_T[self.x_goal], cMin, theta)
|
|
143
|
+
|
|
144
|
+
path_x, path_y = self.ExtractPath()
|
|
145
|
+
plt.plot(path_x, path_y, linewidth=2, color='r')
|
|
146
|
+
plt.pause(0.01)
|
|
147
|
+
plt.show()
|
|
148
|
+
|
|
149
|
+
def ExtractPath(self):
|
|
150
|
+
node = self.x_goal
|
|
151
|
+
path_x, path_y = [node.x], [node.y]
|
|
152
|
+
|
|
153
|
+
while node.parent:
|
|
154
|
+
node = node.parent
|
|
155
|
+
path_x.append(node.x)
|
|
156
|
+
path_y.append(node.y)
|
|
157
|
+
|
|
158
|
+
return path_x, path_y
|
|
159
|
+
|
|
160
|
+
def Prune(self, cBest):
|
|
161
|
+
self.X_sample = {x for x in self.X_sample if self.f_estimated(x) < cBest}
|
|
162
|
+
self.Tree.V = {v for v in self.Tree.V if self.f_estimated(v) <= cBest}
|
|
163
|
+
self.Tree.E = {(v, w) for v, w in self.Tree.E
|
|
164
|
+
if self.f_estimated(v) <= cBest and self.f_estimated(w) <= cBest}
|
|
165
|
+
self.X_sample.update({v for v in self.Tree.V if self.g_T[v] == np.inf})
|
|
166
|
+
self.Tree.V = {v for v in self.Tree.V if self.g_T[v] < np.inf}
|
|
167
|
+
|
|
168
|
+
def cost(self, start, end):
|
|
169
|
+
if self.utils.is_collision(start, end):
|
|
170
|
+
return np.inf
|
|
171
|
+
|
|
172
|
+
return self.calc_dist(start, end)
|
|
173
|
+
|
|
174
|
+
def f_estimated(self, node):
|
|
175
|
+
return self.g_estimated(node) + self.h_estimated(node)
|
|
176
|
+
|
|
177
|
+
def g_estimated(self, node):
|
|
178
|
+
return self.calc_dist(self.x_start, node)
|
|
179
|
+
|
|
180
|
+
def h_estimated(self, node):
|
|
181
|
+
return self.calc_dist(node, self.x_goal)
|
|
182
|
+
|
|
183
|
+
def Sample(self, m, cMax, cMin, xCenter, C):
|
|
184
|
+
if cMax < np.inf:
|
|
185
|
+
return self.SampleEllipsoid(m, cMax, cMin, xCenter, C)
|
|
186
|
+
else:
|
|
187
|
+
return self.SampleFreeSpace(m)
|
|
188
|
+
|
|
189
|
+
def SampleEllipsoid(self, m, cMax, cMin, xCenter, C):
|
|
190
|
+
r = [cMax / 2.0,
|
|
191
|
+
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0,
|
|
192
|
+
math.sqrt(cMax ** 2 - cMin ** 2) / 2.0]
|
|
193
|
+
L = np.diag(r)
|
|
194
|
+
|
|
195
|
+
ind = 0
|
|
196
|
+
delta = self.delta
|
|
197
|
+
Sample = set()
|
|
198
|
+
|
|
199
|
+
while ind < m:
|
|
200
|
+
xBall = self.SampleUnitNBall()
|
|
201
|
+
x_rand = np.dot(np.dot(C, L), xBall) + xCenter
|
|
202
|
+
node = Node(x_rand[(0, 0)], x_rand[(1, 0)])
|
|
203
|
+
in_obs = self.utils.is_inside_obs(node)
|
|
204
|
+
in_x_range = self.x_range[0] + delta <= node.x <= self.x_range[1] - delta
|
|
205
|
+
in_y_range = self.y_range[0] + delta <= node.y <= self.y_range[1] - delta
|
|
206
|
+
|
|
207
|
+
if not in_obs and in_x_range and in_y_range:
|
|
208
|
+
Sample.add(node)
|
|
209
|
+
ind += 1
|
|
210
|
+
|
|
211
|
+
return Sample
|
|
212
|
+
|
|
213
|
+
def SampleFreeSpace(self, m):
|
|
214
|
+
delta = self.utils.delta
|
|
215
|
+
Sample = set()
|
|
216
|
+
|
|
217
|
+
ind = 0
|
|
218
|
+
while ind < m:
|
|
219
|
+
node = Node(random.uniform(self.x_range[0] + delta, self.x_range[1] - delta),
|
|
220
|
+
random.uniform(self.y_range[0] + delta, self.y_range[1] - delta))
|
|
221
|
+
if self.utils.is_inside_obs(node):
|
|
222
|
+
continue
|
|
223
|
+
else:
|
|
224
|
+
Sample.add(node)
|
|
225
|
+
ind += 1
|
|
226
|
+
|
|
227
|
+
return Sample
|
|
228
|
+
|
|
229
|
+
def radius(self, q):
|
|
230
|
+
cBest = self.g_T[self.x_goal]
|
|
231
|
+
lambda_X = len([1 for v in self.Tree.V if self.f_estimated(v) <= cBest])
|
|
232
|
+
radius = 2 * self.eta * (1.5 * lambda_X / math.pi * math.log(q) / q) ** 0.5
|
|
233
|
+
|
|
234
|
+
return radius
|
|
235
|
+
|
|
236
|
+
def ExpandVertex(self, v):
|
|
237
|
+
self.Tree.QV.remove(v)
|
|
238
|
+
X_near = {x for x in self.X_sample if self.calc_dist(x, v) <= self.Tree.r}
|
|
239
|
+
|
|
240
|
+
for x in X_near:
|
|
241
|
+
if self.g_estimated(v) + self.calc_dist(v, x) + self.h_estimated(x) < self.g_T[self.x_goal]:
|
|
242
|
+
self.g_T[x] = np.inf
|
|
243
|
+
self.Tree.QE.add((v, x))
|
|
244
|
+
|
|
245
|
+
if v not in self.Tree.V_old:
|
|
246
|
+
V_near = {w for w in self.Tree.V if self.calc_dist(w, v) <= self.Tree.r}
|
|
247
|
+
|
|
248
|
+
for w in V_near:
|
|
249
|
+
if (v, w) not in self.Tree.E and \
|
|
250
|
+
self.g_estimated(v) + self.calc_dist(v, w) + self.h_estimated(w) < self.g_T[self.x_goal] and \
|
|
251
|
+
self.g_T[v] + self.calc_dist(v, w) < self.g_T[w]:
|
|
252
|
+
self.Tree.QE.add((v, w))
|
|
253
|
+
if w not in self.g_T:
|
|
254
|
+
self.g_T[w] = np.inf
|
|
255
|
+
|
|
256
|
+
def BestVertexQueueValue(self):
|
|
257
|
+
if not self.Tree.QV:
|
|
258
|
+
return np.inf
|
|
259
|
+
|
|
260
|
+
return min(self.g_T[v] + self.h_estimated(v) for v in self.Tree.QV)
|
|
261
|
+
|
|
262
|
+
def BestEdgeQueueValue(self):
|
|
263
|
+
if not self.Tree.QE:
|
|
264
|
+
return np.inf
|
|
265
|
+
|
|
266
|
+
return min(self.g_T[v] + self.calc_dist(v, x) + self.h_estimated(x)
|
|
267
|
+
for v, x in self.Tree.QE)
|
|
268
|
+
|
|
269
|
+
def BestInVertexQueue(self):
|
|
270
|
+
if not self.Tree.QV:
|
|
271
|
+
print("QV is Empty!")
|
|
272
|
+
return None
|
|
273
|
+
|
|
274
|
+
v_value = {v: self.g_T[v] + self.h_estimated(v) for v in self.Tree.QV}
|
|
275
|
+
|
|
276
|
+
return min(v_value, key=v_value.get)
|
|
277
|
+
|
|
278
|
+
def BestInEdgeQueue(self):
|
|
279
|
+
if not self.Tree.QE:
|
|
280
|
+
print("QE is Empty!")
|
|
281
|
+
return None
|
|
282
|
+
|
|
283
|
+
e_value = {(v, x): self.g_T[v] + self.calc_dist(v, x) + self.h_estimated(x)
|
|
284
|
+
for v, x in self.Tree.QE}
|
|
285
|
+
|
|
286
|
+
return min(e_value, key=e_value.get)
|
|
287
|
+
|
|
288
|
+
@staticmethod
|
|
289
|
+
def SampleUnitNBall():
|
|
290
|
+
while True:
|
|
291
|
+
x, y = random.uniform(-1, 1), random.uniform(-1, 1)
|
|
292
|
+
if x ** 2 + y ** 2 < 1:
|
|
293
|
+
return np.array([[x], [y], [0.0]])
|
|
294
|
+
|
|
295
|
+
@staticmethod
|
|
296
|
+
def RotationToWorldFrame(x_start, x_goal, L):
|
|
297
|
+
a1 = np.array([[(x_goal.x - x_start.x) / L],
|
|
298
|
+
[(x_goal.y - x_start.y) / L], [0.0]])
|
|
299
|
+
e1 = np.array([[1.0], [0.0], [0.0]])
|
|
300
|
+
M = a1 @ e1.T
|
|
301
|
+
U, _, V_T = np.linalg.svd(M, True, True)
|
|
302
|
+
C = U @ np.diag([1.0, 1.0, np.linalg.det(U) * np.linalg.det(V_T.T)]) @ V_T
|
|
303
|
+
|
|
304
|
+
return C
|
|
305
|
+
|
|
306
|
+
@staticmethod
|
|
307
|
+
def calc_dist(start, end):
|
|
308
|
+
return math.hypot(start.x - end.x, start.y - end.y)
|
|
309
|
+
|
|
310
|
+
@staticmethod
|
|
311
|
+
def calc_dist_and_angle(node_start, node_end):
|
|
312
|
+
dx = node_end.x - node_start.x
|
|
313
|
+
dy = node_end.y - node_start.y
|
|
314
|
+
return math.hypot(dx, dy), math.atan2(dy, dx)
|
|
315
|
+
|
|
316
|
+
def animation(self, xCenter, cMax, cMin, theta):
|
|
317
|
+
plt.cla()
|
|
318
|
+
self.plot_grid("Batch Informed Trees (BIT*)")
|
|
319
|
+
|
|
320
|
+
plt.gcf().canvas.mpl_connect(
|
|
321
|
+
'key_release_event',
|
|
322
|
+
lambda event: [exit(0) if event.key == 'escape' else None])
|
|
323
|
+
|
|
324
|
+
for v in self.X_sample:
|
|
325
|
+
plt.plot(v.x, v.y, marker='.', color='lightgrey', markersize='2')
|
|
326
|
+
|
|
327
|
+
if cMax < np.inf:
|
|
328
|
+
self.draw_ellipse(xCenter, cMax, cMin, theta)
|
|
329
|
+
|
|
330
|
+
for v, w in self.Tree.E:
|
|
331
|
+
plt.plot([v.x, w.x], [v.y, w.y], '-g')
|
|
332
|
+
|
|
333
|
+
plt.pause(0.001)
|
|
334
|
+
|
|
335
|
+
def plot_grid(self, name):
|
|
336
|
+
for (ox, oy, w, h) in self.obs_boundary:
|
|
337
|
+
self.ax.add_patch(
|
|
338
|
+
patches.Rectangle(
|
|
339
|
+
(ox, oy), w, h,
|
|
340
|
+
edgecolor='black',
|
|
341
|
+
facecolor='black',
|
|
342
|
+
fill=True
|
|
343
|
+
)
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
for (ox, oy, w, h) in self.obs_rectangle:
|
|
347
|
+
self.ax.add_patch(
|
|
348
|
+
patches.Rectangle(
|
|
349
|
+
(ox, oy), w, h,
|
|
350
|
+
edgecolor='black',
|
|
351
|
+
facecolor='gray',
|
|
352
|
+
fill=True
|
|
353
|
+
)
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
for (ox, oy, r) in self.obs_circle:
|
|
357
|
+
self.ax.add_patch(
|
|
358
|
+
patches.Circle(
|
|
359
|
+
(ox, oy), r,
|
|
360
|
+
edgecolor='black',
|
|
361
|
+
facecolor='gray',
|
|
362
|
+
fill=True
|
|
363
|
+
)
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
plt.plot(self.x_start.x, self.x_start.y, "bs", linewidth=3)
|
|
367
|
+
plt.plot(self.x_goal.x, self.x_goal.y, "rs", linewidth=3)
|
|
368
|
+
|
|
369
|
+
plt.title(name)
|
|
370
|
+
plt.axis("equal")
|
|
371
|
+
|
|
372
|
+
@staticmethod
|
|
373
|
+
def draw_ellipse(x_center, c_best, dist, theta):
|
|
374
|
+
a = math.sqrt(c_best ** 2 - dist ** 2) / 2.0
|
|
375
|
+
b = c_best / 2.0
|
|
376
|
+
angle = math.pi / 2.0 - theta
|
|
377
|
+
cx = x_center[0]
|
|
378
|
+
cy = x_center[1]
|
|
379
|
+
t = np.arange(0, 2 * math.pi + 0.1, 0.2)
|
|
380
|
+
x = [a * math.cos(it) for it in t]
|
|
381
|
+
y = [b * math.sin(it) for it in t]
|
|
382
|
+
rot = Rot.from_euler('z', -angle).as_dcm()[0:2, 0:2]
|
|
383
|
+
fx = rot @ np.array([x, y])
|
|
384
|
+
px = np.array(fx[0, :] + cx).flatten()
|
|
385
|
+
py = np.array(fx[1, :] + cy).flatten()
|
|
386
|
+
plt.plot(cx, cy, marker='.', color='darkorange')
|
|
387
|
+
plt.plot(px, py, linestyle='--', color='darkorange', linewidth=2)
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def main():
|
|
391
|
+
x_start = (18, 8) # Starting node
|
|
392
|
+
x_goal = (37, 18) # Goal node
|
|
393
|
+
eta = 2
|
|
394
|
+
iter_max = 200
|
|
395
|
+
print("start!!!")
|
|
396
|
+
bit = BITStar(x_start, x_goal, eta, iter_max)
|
|
397
|
+
# bit.animation("Batch Informed Trees (BIT*)")
|
|
398
|
+
bit.planning()
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
if __name__ == '__main__':
|
|
402
|
+
main()
|