@@ -53,7 +53,7 @@ def __init__(self, start, goal, obstacle_list, rand_area,
53
53
"""
54
54
self .connect_circle_dist = connect_circle_dist
55
55
56
- def planning (self , animation = True , search_until_maxiter = True ):
56
+ def planning (self , animation = True , search_until_max_iter = True ):
57
57
"""
58
58
rrt star path planning
59
59
@@ -63,7 +63,7 @@ def planning(self, animation=True, search_until_maxiter=True):
63
63
64
64
self .node_list = [self .start ]
65
65
for i in range (self .max_iter ):
66
- print (i , len (self .node_list ))
66
+ print ("Iter:" , i , ", number of nodes:" , len (self .node_list ))
67
67
rnd = self .get_random_node ()
68
68
nearest_ind = self .get_nearest_list_index (self .node_list , rnd )
69
69
new_node = self .steer (self .node_list [nearest_ind ], rnd , self .expand_dis )
@@ -78,10 +78,10 @@ def planning(self, animation=True, search_until_maxiter=True):
78
78
if animation and i % 5 == 0 :
79
79
self .draw_graph (rnd )
80
80
81
- if (not search_until_maxiter ) and new_node : # check reaching the goal
82
- d , _ = self .calc_distance_and_angle ( new_node , self . end )
83
- if d <= self . expand_dis :
84
- return self .generate_final_course (len ( self . node_list ) - 1 )
81
+ if (not search_until_max_iter ) and new_node : # check reaching the goal
82
+ last_index = self .search_best_goal_node ( )
83
+ if last_index :
84
+ return self .generate_final_course (last_index )
85
85
86
86
print ("reached max iteration" )
87
87
@@ -91,25 +91,6 @@ def planning(self, animation=True, search_until_maxiter=True):
91
91
92
92
return None
93
93
94
- def connect_nodes (self , from_node , to_node ):
95
- new_node = self .Node (from_node .x , from_node .y )
96
- d , theta = self .calc_distance_and_angle (new_node , to_node )
97
-
98
- new_node .path_x = [new_node .x ]
99
- new_node .path_y = [new_node .y ]
100
-
101
- n_expand = math .floor (d / self .path_resolution )
102
-
103
- for _ in range (n_expand ):
104
- new_node .x += self .path_resolution * math .cos (theta )
105
- new_node .y += self .path_resolution * math .sin (theta )
106
- new_node .path_x .append (new_node .x )
107
- new_node .path_y .append (new_node .y )
108
-
109
- new_node .parent = from_node
110
-
111
- return new_node
112
-
113
94
def choose_parent (self , new_node , near_inds ):
114
95
if not near_inds :
115
96
return None
@@ -130,8 +111,8 @@ def choose_parent(self, new_node, near_inds):
130
111
return None
131
112
132
113
min_ind = near_inds [costs .index (min_cost )]
114
+ new_node = self .steer (self .node_list [min_ind ], new_node )
133
115
new_node .parent = self .node_list [min_ind ]
134
- new_node = self .steer (new_node .parent , new_node )
135
116
new_node .cost = min_cost
136
117
137
118
return new_node
@@ -162,21 +143,22 @@ def rewire(self, new_node, near_inds):
162
143
for i in near_inds :
163
144
near_node = self .node_list [i ]
164
145
edge_node = self .steer (new_node , near_node )
165
- edge_node .cost = self .calc_new_cost (near_node , new_node )
146
+ edge_node .cost = self .calc_new_cost (new_node , near_node )
166
147
167
148
no_collision = self .check_collision (edge_node , self .obstacle_list )
168
149
improved_cost = near_node .cost > edge_node .cost
169
150
170
151
if no_collision and improved_cost :
152
+ near_node = edge_node
171
153
near_node .parent = new_node
172
- near_node .cost = edge_node .cost
173
154
self .propagate_cost_to_leaves (new_node )
174
155
175
156
def calc_new_cost (self , from_node , to_node ):
176
157
d , _ = self .calc_distance_and_angle (from_node , to_node )
177
158
return from_node .cost + d
178
159
179
160
def propagate_cost_to_leaves (self , parent_node ):
161
+
180
162
for node in self .node_list :
181
163
if node .parent == parent_node :
182
164
node .cost = self .calc_new_cost (parent_node , node )
0 commit comments