@@ -53,7 +53,7 @@ def __init__(self, start, goal, obstacle_list, rand_area,
5353 """
5454 self .connect_circle_dist = connect_circle_dist
5555
56- def planning (self , animation = True , search_until_maxiter = True ):
56+ def planning (self , animation = True , search_until_max_iter = True ):
5757 """
5858 rrt star path planning
5959
@@ -63,7 +63,7 @@ def planning(self, animation=True, search_until_maxiter=True):
6363
6464 self .node_list = [self .start ]
6565 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 ))
6767 rnd = self .get_random_node ()
6868 nearest_ind = self .get_nearest_list_index (self .node_list , rnd )
6969 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):
7878 if animation and i % 5 == 0 :
7979 self .draw_graph (rnd )
8080
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 )
8585
8686 print ("reached max iteration" )
8787
@@ -91,25 +91,6 @@ def planning(self, animation=True, search_until_maxiter=True):
9191
9292 return None
9393
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-
11394 def choose_parent (self , new_node , near_inds ):
11495 if not near_inds :
11596 return None
@@ -130,8 +111,8 @@ def choose_parent(self, new_node, near_inds):
130111 return None
131112
132113 min_ind = near_inds [costs .index (min_cost )]
114+ new_node = self .steer (self .node_list [min_ind ], new_node )
133115 new_node .parent = self .node_list [min_ind ]
134- new_node = self .steer (new_node .parent , new_node )
135116 new_node .cost = min_cost
136117
137118 return new_node
@@ -162,21 +143,22 @@ def rewire(self, new_node, near_inds):
162143 for i in near_inds :
163144 near_node = self .node_list [i ]
164145 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 )
166147
167148 no_collision = self .check_collision (edge_node , self .obstacle_list )
168149 improved_cost = near_node .cost > edge_node .cost
169150
170151 if no_collision and improved_cost :
152+ near_node = edge_node
171153 near_node .parent = new_node
172- near_node .cost = edge_node .cost
173154 self .propagate_cost_to_leaves (new_node )
174155
175156 def calc_new_cost (self , from_node , to_node ):
176157 d , _ = self .calc_distance_and_angle (from_node , to_node )
177158 return from_node .cost + d
178159
179160 def propagate_cost_to_leaves (self , parent_node ):
161+
180162 for node in self .node_list :
181163 if node .parent == parent_node :
182164 node .cost = self .calc_new_cost (parent_node , node )
0 commit comments