Skip to content

Commit eefa6bf

Browse files
committed
try to check collision check bug
1 parent ae32cb3 commit eefa6bf

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

PathPlanning/RRT/rrt.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import random
1111

1212
import matplotlib.pyplot as plt
13+
import numpy as np
1314

1415
show_animation = True
1516

@@ -104,10 +105,8 @@ def steer(self, from_node, to_node, extend_length=float("inf")):
104105

105106
d, _ = self.calc_distance_and_angle(new_node, to_node)
106107
if d <= self.path_resolution:
107-
new_node.x = to_node.x
108-
new_node.y = to_node.y
109-
new_node.path_x[-1] = to_node.x
110-
new_node.path_y[-1] = to_node.y
108+
new_node.path_x.append(to_node.x)
109+
new_node.path_y.append(to_node.y)
111110

112111
new_node.parent = from_node
113112

@@ -142,17 +141,26 @@ def draw_graph(self, rnd=None):
142141
plt.plot(rnd.x, rnd.y, "^k")
143142
for node in self.node_list:
144143
if node.parent:
145-
plt.plot(node.path_x, node.path_y, "-g")
144+
plt.plot(node.path_x, node.path_y, "-xg")
146145

147146
for (ox, oy, size) in self.obstacle_list:
148-
plt.plot(ox, oy, "ok", ms=30 * size)
147+
self.plot_circle(ox, oy, size)
149148

150149
plt.plot(self.start.x, self.start.y, "xr")
151150
plt.plot(self.end.x, self.end.y, "xr")
151+
plt.axis("equal")
152152
plt.axis([-2, 15, -2, 15])
153153
plt.grid(True)
154154
plt.pause(0.01)
155155

156+
@staticmethod
157+
def plot_circle(x, y, size, color="-b"): # pragma: no cover
158+
deg = list(range(0, 360, 5))
159+
deg.append(0)
160+
xl = [x + size * math.cos(np.deg2rad(d)) for d in deg]
161+
yl = [y + size * math.sin(np.deg2rad(d)) for d in deg]
162+
plt.plot(xl, yl, color)
163+
156164
@staticmethod
157165
def get_nearest_node_index(node_list, rnd_node):
158166
dlist = [(node.x - rnd_node.x) ** 2 + (node.y - rnd_node.y)
@@ -182,7 +190,7 @@ def calc_distance_and_angle(from_node, to_node):
182190
return d, theta
183191

184192

185-
def main(gx=5.0, gy=10.0):
193+
def main(gx=6.0, gy=10.0):
186194
print("start " + __file__)
187195

188196
# ====Search Path with RRT====
@@ -193,7 +201,7 @@ def main(gx=5.0, gy=10.0):
193201
(3, 10, 2),
194202
(7, 5, 2),
195203
(9, 5, 2)
196-
] # [x,y,size]
204+
] # [x, y, radius]
197205
# Set Initial parameters
198206
rrt = RRT(start=[0, 0],
199207
goal=[gx, gy],

0 commit comments

Comments
 (0)