Skip to content

Commit 80124f2

Browse files
authored
Fix the rewire() of rrt* path planning (AtsushiSakai#550) (AtsushiSakai#812)
* Update rrt_star_reeds_shepp.py to fix AtsushiSakai#550 Add step_size attribute to RRTStarReedsShepp, and a method set_random_seed() to set the random seed, with two test cases. * Update rewire() of rrt_star.py Update rewire() of rrt_star.py to fix AtsushiSakai#550. Since the old version didn't assign path_yaw of edge_node to near_node, the old rewire() doesn't fit rrt_star_reeds_shepp.py * Update reeds_shepp_path_planning.py Limit the range of phi for the sake of planning speed, and simplify the the calculation process in straight_left_straight(). * Update reeds_shepp_path_planning.py * Remove unnecessary cost calculation Cost of edge_node is calculated in line 221, and self.node_list[i] is replaced to edge_node, so no need to update. * Update reeds_shepp_path_planning.py
1 parent 28004c7 commit 80124f2

File tree

4 files changed

+56
-20
lines changed

4 files changed

+56
-20
lines changed

PathPlanning/RRTStar/rrt_star.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,11 @@ def rewire(self, new_node, near_inds):
225225
improved_cost = near_node.cost > edge_node.cost
226226

227227
if no_collision and improved_cost:
228-
near_node.x = edge_node.x
229-
near_node.y = edge_node.y
230-
near_node.cost = edge_node.cost
231-
near_node.path_x = edge_node.path_x
232-
near_node.path_y = edge_node.path_y
233-
near_node.parent = edge_node.parent
234-
self.propagate_cost_to_leaves(new_node)
228+
for node in self.node_list:
229+
if node.parent == self.node_list[i]:
230+
node.parent = edge_node
231+
self.node_list[i] = edge_node
232+
self.propagate_cost_to_leaves(self.node_list[i])
235233

236234
def calc_new_cost(self, from_node, to_node):
237235
d, _ = self.calc_distance_and_angle(from_node, to_node)

PathPlanning/RRTStarReedsShepp/rrt_star_reeds_shepp.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, x, y, yaw):
3636
self.path_yaw = []
3737

3838
def __init__(self, start, goal, obstacle_list, rand_area,
39-
max_iter=200,
39+
max_iter=200, step_size=0.2,
4040
connect_circle_dist=50.0,
4141
robot_radius=0.0
4242
):
@@ -55,6 +55,7 @@ def __init__(self, start, goal, obstacle_list, rand_area,
5555
self.min_rand = rand_area[0]
5656
self.max_rand = rand_area[1]
5757
self.max_iter = max_iter
58+
self.step_size = step_size
5859
self.obstacle_list = obstacle_list
5960
self.connect_circle_dist = connect_circle_dist
6061
self.robot_radius = robot_radius
@@ -63,6 +64,9 @@ def __init__(self, start, goal, obstacle_list, rand_area,
6364
self.goal_yaw_th = np.deg2rad(1.0)
6465
self.goal_xy_th = 0.5
6566

67+
def set_random_seed(self, seed):
68+
random.seed(seed)
69+
6670
def planning(self, animation=True, search_until_max_iter=True):
6771
"""
6872
planning
@@ -147,8 +151,8 @@ def plot_start_goal_arrow(self):
147151
def steer(self, from_node, to_node):
148152

149153
px, py, pyaw, mode, course_lengths = reeds_shepp_path_planning.reeds_shepp_path_planning(
150-
from_node.x, from_node.y, from_node.yaw,
151-
to_node.x, to_node.y, to_node.yaw, self.curvature)
154+
from_node.x, from_node.y, from_node.yaw, to_node.x,
155+
to_node.y, to_node.yaw, self.curvature, self.step_size)
152156

153157
if not px:
154158
return None
@@ -169,8 +173,8 @@ def steer(self, from_node, to_node):
169173
def calc_new_cost(self, from_node, to_node):
170174

171175
_, _, _, _, course_lengths = reeds_shepp_path_planning.reeds_shepp_path_planning(
172-
from_node.x, from_node.y, from_node.yaw,
173-
to_node.x, to_node.y, to_node.yaw, self.curvature)
176+
from_node.x, from_node.y, from_node.yaw, to_node.x,
177+
to_node.y, to_node.yaw, self.curvature, self.step_size)
174178
if not course_lengths:
175179
return float("inf")
176180

PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,14 @@ def mod2pi(x):
5353

5454
def straight_left_straight(x, y, phi):
5555
phi = mod2pi(phi)
56-
if y > 0.0 and 0.0 < phi < math.pi * 0.99:
56+
# only take phi in (0.01*math.pi, 0.99*math.pi) for the sake of speed.
57+
# phi in (0, 0.01*math.pi) will make test2() in test_rrt_star_reeds_shepp.py
58+
# extremely time-consuming, since the value of xd, t will be very large.
59+
if math.pi * 0.01 < phi < math.pi * 0.99 and y != 0:
5760
xd = - y / math.tan(phi) + x
5861
t = xd - math.tan(phi / 2.0)
5962
u = phi
60-
v = math.hypot(x - xd, y) - math.tan(phi / 2.0)
61-
return True, t, u, v
62-
elif y < 0.0 < phi < math.pi * 0.99:
63-
xd = - y / math.tan(phi) + x
64-
t = xd - math.tan(phi / 2.0)
65-
u = phi
66-
v = -math.hypot(x - xd, y) - math.tan(phi / 2.0)
63+
v = np.sign(y) * math.hypot(x - xd, y) - math.tan(phi / 2.0)
6764
return True, t, u, v
6865

6966
return False, 0.0, 0.0, 0.0

tests/test_rrt_star_reeds_shepp.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,43 @@ def test1():
66
m.show_animation = False
77
m.main(max_iter=5)
88

9+
obstacleList = [
10+
(5, 5, 1),
11+
(4, 6, 1),
12+
(4, 8, 1),
13+
(4, 10, 1),
14+
(6, 5, 1),
15+
(7, 5, 1),
16+
(8, 6, 1),
17+
(8, 8, 1),
18+
(8, 10, 1)
19+
] # [x,y,size(radius)]
20+
21+
start = [0.0, 0.0, m.np.deg2rad(0.0)]
22+
goal = [6.0, 7.0, m.np.deg2rad(90.0)]
23+
24+
def test2():
25+
step_size = 0.2
26+
rrt_star_reeds_shepp = m.RRTStarReedsShepp(start, goal,
27+
obstacleList, [-2.0, 15.0],
28+
max_iter=100, step_size=step_size)
29+
rrt_star_reeds_shepp.set_random_seed(seed=8)
30+
path = rrt_star_reeds_shepp.planning(animation=False)
31+
for i in range(len(path)-1):
32+
# + 0.00000000000001 for acceptable errors arising from the planning process
33+
assert m.math.dist(path[i][0:2], path[i+1][0:2]) < step_size + 0.00000000000001
34+
35+
def test3():
36+
step_size = 20
37+
rrt_star_reeds_shepp = m.RRTStarReedsShepp(start, goal,
38+
obstacleList, [-2.0, 15.0],
39+
max_iter=100, step_size=step_size)
40+
rrt_star_reeds_shepp.set_random_seed(seed=8)
41+
path = rrt_star_reeds_shepp.planning(animation=False)
42+
for i in range(len(path)-1):
43+
# + 0.00000000000001 for acceptable errors arising from the planning process
44+
assert m.math.dist(path[i][0:2], path[i+1][0:2]) < step_size + 0.00000000000001
45+
946

1047
if __name__ == '__main__':
1148
conftest.run_this_test(__file__)

0 commit comments

Comments
 (0)