@@ -30,7 +30,8 @@ class MovingDirection(IntEnum):
3030        RIGHT  =  1 
3131        LEFT  =  - 1 
3232
33-     def  __init__ (self , moving_direction , sweep_direction , x_inds_goal_y , goal_y ):
33+     def  __init__ (self ,
34+                  moving_direction , sweep_direction , x_inds_goal_y , goal_y ):
3435        self .moving_direction  =  moving_direction 
3536        self .sweep_direction  =  sweep_direction 
3637        self .turing_window  =  []
@@ -88,6 +89,8 @@ def is_search_done(self, grid_map):
8889        return  True 
8990
9091    def  update_turning_window (self ):
92+         # turning window definition 
93+         # robot can move grid based on it. 
9194        self .turing_window  =  [
9295            (self .moving_direction , 0.0 ),
9396            (self .moving_direction , self .sweep_direction ),
@@ -189,35 +192,34 @@ def search_free_grid_index_at_edge_y(grid_map, from_upper=False):
189192def  setup_grid_map (ox , oy , reso , sweep_direction , offset_grid = 10 ):
190193    width  =  math .ceil ((max (ox ) -  min (ox )) /  reso ) +  offset_grid 
191194    height  =  math .ceil ((max (oy ) -  min (oy )) /  reso ) +  offset_grid 
192-     center_x  =  np .mean (ox )
193-     center_y  =  np .mean (oy )
195+     center_x  =  ( np .max (ox )+ np . min ( ox )) / 2.0 
196+     center_y  =  ( np .max (oy )+ np . min ( oy )) / 2.0 
194197
195198    grid_map  =  GridMap (width , height , reso , center_x , center_y )
196- 
199+      grid_map . print_grid_map_info () 
197200    grid_map .set_value_from_polygon (ox , oy , 1.0 , inside = False )
198- 
199201    grid_map .expand_grid ()
200202
201-     xinds_goaly  =  []
202-     goaly  =  0 
203+     x_inds_goal_y  =  []
204+     goal_y  =  0 
203205    if  sweep_direction  ==  SweepSearcher .SweepDirection .UP :
204-         xinds_goaly ,  goaly  =  search_free_grid_index_at_edge_y (grid_map ,
206+         x_inds_goal_y ,  goal_y  =  search_free_grid_index_at_edge_y (grid_map ,
205207                                                              from_upper = True )
206208    elif  sweep_direction  ==  SweepSearcher .SweepDirection .DOWN :
207-         xinds_goaly ,  goaly  =  search_free_grid_index_at_edge_y (grid_map ,
209+         x_inds_goal_y ,  goal_y  =  search_free_grid_index_at_edge_y (grid_map ,
208210                                                              from_upper = False )
209211
210-     return  grid_map , xinds_goaly ,  goaly 
212+     return  grid_map , x_inds_goal_y ,  goal_y 
211213
212214
213- def  sweep_path_search (sweep_searcher , gmap , grid_search_animation = False ):
215+ def  sweep_path_search (sweep_searcher , grid_map , grid_search_animation = False ):
214216    # search start grid 
215-     cxind , cyind  =  sweep_searcher .search_start_grid (gmap )
216-     if  not  gmap .set_value_from_xy_index (cxind , cyind , 0.5 ):
217+     cxind , cyind  =  sweep_searcher .search_start_grid (grid_map )
218+     if  not  grid_map .set_value_from_xy_index (cxind , cyind , 0.5 ):
217219        print ("Cannot find start grid" )
218220        return  [], []
219221
220-     x , y  =  gmap .calc_grid_central_xy_position_from_xy_index (cxind , cyind )
222+     x , y  =  grid_map .calc_grid_central_xy_position_from_xy_index (cxind , cyind )
221223    px , py  =  [x ], [y ]
222224
223225    fig , ax  =  None , None 
@@ -229,26 +231,26 @@ def sweep_path_search(sweep_searcher, gmap, grid_search_animation=False):
229231                                   exit (0 ) if  event .key  ==  'escape'  else  None ])
230232
231233    while  True :
232-         cxind , cyind  =  sweep_searcher .move_target_grid (cxind , cyind , gmap )
234+         cxind , cyind  =  sweep_searcher .move_target_grid (cxind , cyind , grid_map )
233235
234-         if  sweep_searcher .is_search_done (gmap ) or  (
236+         if  sweep_searcher .is_search_done (grid_map ) or  (
235237                cxind  is  None  or  cyind  is  None ):
236238            print ("Done" )
237239            break 
238240
239-         x , y  =  gmap .calc_grid_central_xy_position_from_xy_index (
241+         x , y  =  grid_map .calc_grid_central_xy_position_from_xy_index (
240242            cxind , cyind )
241243
242244        px .append (x )
243245        py .append (y )
244246
245-         gmap .set_value_from_xy_index (cxind , cyind , 0.5 )
247+         grid_map .set_value_from_xy_index (cxind , cyind , 0.5 )
246248
247249        if  grid_search_animation :
248-             gmap .plot_grid_map (ax = ax )
250+             grid_map .plot_grid_map (ax = ax )
249251            plt .pause (1.0 )
250252
251-     gmap .plot_grid_map ()
253+     grid_map .plot_grid_map ()
252254
253255    return  px , py 
254256
@@ -307,11 +309,6 @@ def planning_animation(ox, oy, reso):  # pragma: no cover
307309def  main ():  # pragma: no cover 
308310    print ("start!!" )
309311
310-     ox  =  [0.0 , 50.0 , 50.0 , 0.0 , 0.0 ]
311-     oy  =  [0.0 , 0.0 , 50.0 , 50.0 , 0.0 ]
312-     reso  =  0.4 
313-     planning_animation (ox , oy , reso )
314- 
315312    ox  =  [0.0 , 20.0 , 50.0 , 100.0 , 130.0 , 40.0 , 0.0 ]
316313    oy  =  [0.0 , - 20.0 , 0.0 , 30.0 , 60.0 , 80.0 , 0.0 ]
317314    reso  =  5.0 
@@ -328,7 +325,6 @@ def main():  # pragma: no cover
328325    planning_animation (ox , oy , reso )
329326
330327    plt .show ()
331- 
332328    print ("done!!" )
333329
334330
0 commit comments