@@ -62,9 +62,15 @@ class NodePath:
6262
6363 def __init__ (self , path : list [Node ]):
6464 self .path = path
65- for node in path :
66- self .positions_at_time [node .time ] = node .position
65+ for (i , node ) in enumerate (path ):
66+ if i > 0 :
67+ # account for waiting in interval at previous node
68+ prev_node = path [i - 1 ]
69+ for t in range (prev_node .time , node .time ):
70+ self .positions_at_time [t ] = prev_node .position
6771
72+ self .positions_at_time [node .time ] = node .position
73+
6874 """
6975 Get the position of the path at a given time
7076 """
@@ -97,7 +103,6 @@ def __init__(self, grid: Grid, start: Position, goal: Position):
97103 def plan (self , verbose : bool = False ) -> NodePath :
98104
99105 safe_intervals = self .grid .get_safe_intervals ()
100- print (safe_intervals [0 , 0 ])
101106
102107 open_set : list [Node ] = []
103108 first_node_interval = safe_intervals [self .start .x , self .start .y ][0 ]
@@ -164,7 +169,7 @@ def generate_successors(
164169 ]
165170 for diff in diffs :
166171 new_pos = parent_node .position + diff
167- if not self .grid .valid_position (new_pos ):
172+ if not self .grid .inside_grid_bounds (new_pos ):
168173 continue
169174
170175 current_interval = parent_node .interval
@@ -218,20 +223,18 @@ def calculate_heuristic(self, position) -> int:
218223
219224
220225show_animation = True
221- verbose = True
226+ verbose = False
222227
223- # TODO: viz shows obstacle finish 1 cell above the goal?
224228def main ():
225- start = Position (1 , 18 )
229+ start = Position (1 , 1 )
226230 goal = Position (19 , 19 )
227231 grid_side_length = 21
228232 grid = Grid (
229233 np .array ([grid_side_length , grid_side_length ]),
230- # TODO: if this is set to 0, still get some obstacles with random set
231- num_obstacles = 22 ,
234+ num_obstacles = 250 ,
232235 obstacle_avoid_points = [start , goal ],
233- obstacle_arrangement = ObstacleArrangement .ARRANGEMENT1 ,
234- # obstacle_arrangement=ObstacleArrangement.RANDOM,
236+ # obstacle_arrangement=ObstacleArrangement.ARRANGEMENT1,
237+ obstacle_arrangement = ObstacleArrangement .RANDOM ,
235238 )
236239
237240 planner = SafeIntervalPathPlanner (grid , start , goal )
@@ -265,7 +268,7 @@ def main():
265268 "key_release_event" , lambda event : [exit (0 ) if event .key == "escape" else None ]
266269 )
267270
268- for i in range (0 , path .goal_reached_time ()):
271+ for i in range (0 , path .goal_reached_time () + 1 ):
269272 obs_positions = grid .get_obstacle_positions_at_time (i )
270273 obs_points .set_data (obs_positions [0 ], obs_positions [1 ])
271274 path_position = path .get_position (i )
0 commit comments