Skip to content

Commit 7e697d8

Browse files
authored
Merge pull request AtsushiSakai#227 from AtsushiSakai/fix-last-expansion-collision-check
fix last expansion collision detection
2 parents 09596b3 + 295645f commit 7e697d8

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

PathPlanning/RRT/rrt.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, x, y):
3333
self.parent = None
3434

3535
def __init__(self, start, goal, obstacle_list, rand_area,
36-
expand_dis=3.0, path_resolution=1.0, goal_sample_rate=5, max_iter=500):
36+
expand_dis=3.0, path_resolution=0.5, goal_sample_rate=5, max_iter=500):
3737
"""
3838
Setting Parameter
3939
@@ -76,8 +76,9 @@ def planning(self, animation=True):
7676
self.draw_graph(rnd_node)
7777

7878
if self.calc_dist_to_goal(self.node_list[-1].x, self.node_list[-1].y) <= self.expand_dis:
79-
print("Goal!!")
80-
return self.generate_final_course(len(self.node_list) - 1)
79+
final_node = self.steer(self.node_list[-1], self.end, self.expand_dis)
80+
if self.check_collision(final_node, self.obstacle_list):
81+
return self.generate_final_course(len(self.node_list) - 1)
8182

8283
if animation and i % 5:
8384
self.draw_graph(rnd_node)
@@ -141,7 +142,7 @@ def draw_graph(self, rnd=None):
141142
plt.plot(rnd.x, rnd.y, "^k")
142143
for node in self.node_list:
143144
if node.parent:
144-
plt.plot(node.path_x, node.path_y, "-xg")
145+
plt.plot(node.path_x, node.path_y, "-g")
145146

146147
for (ox, oy, size) in self.obstacle_list:
147148
self.plot_circle(ox, oy, size)
@@ -200,7 +201,8 @@ def main(gx=6.0, gy=10.0):
200201
(3, 8, 2),
201202
(3, 10, 2),
202203
(7, 5, 2),
203-
(9, 5, 2)
204+
(9, 5, 2),
205+
(8, 10, 1)
204206
] # [x, y, radius]
205207
# Set Initial parameters
206208
rrt = RRT(start=[0, 0],

PathPlanning/RRT/rrt_with_pathsmoothing.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ def line_collision_check(first, second, obstacleList):
7676
if d <= size:
7777
return False
7878

79-
# print("OK")
80-
8179
return True # OK
8280

8381

@@ -127,7 +125,7 @@ def main():
127125
(7, 5, 2),
128126
(9, 5, 2)
129127
] # [x,y,size]
130-
rrt = RRT(start=[0, 0], goal=[5, 10],
128+
rrt = RRT(start=[0, 0], goal=[6, 10],
131129
rand_area=[-2, 15], obstacle_list=obstacleList)
132130
path = rrt.planning(animation=show_animation)
133131

@@ -141,7 +139,7 @@ def main():
141139
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
142140

143141
plt.plot([x for (x, y) in smoothedPath], [
144-
y for (x, y) in smoothedPath], '-b')
142+
y for (x, y) in smoothedPath], '-c')
145143

146144
plt.grid(True)
147145
plt.pause(0.01) # Need for Mac

PathPlanning/RRTStar/rrt_star.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(self, start, goal, obstacle_list, rand_area,
5252
5353
"""
5454
self.connect_circle_dist = connect_circle_dist
55+
self.goal_node = self.Node(goal[0], goal[1])
5556

5657
def planning(self, animation=True, search_until_max_iter=True):
5758
"""
@@ -121,7 +122,14 @@ def search_best_goal_node(self):
121122
dist_to_goal_list = [self.calc_dist_to_goal(n.x, n.y) for n in self.node_list]
122123
goal_inds = [dist_to_goal_list.index(i) for i in dist_to_goal_list if i <= self.expand_dis]
123124

124-
if not goal_inds:
125+
# safe_goal_inds = goal_inds
126+
safe_goal_inds = []
127+
for goal_ind in goal_inds:
128+
t_node = self.steer(self.node_list[goal_ind], self.goal_node)
129+
if self.check_collision(t_node, self.obstacle_list):
130+
safe_goal_inds.append(goal_ind)
131+
132+
if not safe_goal_inds:
125133
return None
126134

127135
min_cost = min([self.node_list[i].cost for i in goal_inds])
@@ -177,12 +185,13 @@ def main():
177185
(3, 8, 2),
178186
(3, 10, 2),
179187
(7, 5, 2),
180-
(9, 5, 2)
188+
(9, 5, 2),
189+
(8, 10, 1),
181190
] # [x,y,size(radius)]
182191

183192
# Set Initial parameters
184193
rrt_star = RRTStar(start=[0, 0],
185-
goal=[10, 10],
194+
goal=[6, 10],
186195
rand_area=[-2, 15],
187196
obstacle_list=obstacle_list)
188197
path = rrt_star.planning(animation=show_animation)

0 commit comments

Comments
 (0)