@@ -62,9 +62,15 @@ class NodePath:
62
62
63
63
def __init__ (self , path : list [Node ]):
64
64
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
67
71
72
+ self .positions_at_time [node .time ] = node .position
73
+
68
74
"""
69
75
Get the position of the path at a given time
70
76
"""
@@ -97,7 +103,6 @@ def __init__(self, grid: Grid, start: Position, goal: Position):
97
103
def plan (self , verbose : bool = False ) -> NodePath :
98
104
99
105
safe_intervals = self .grid .get_safe_intervals ()
100
- print (safe_intervals [0 , 0 ])
101
106
102
107
open_set : list [Node ] = []
103
108
first_node_interval = safe_intervals [self .start .x , self .start .y ][0 ]
@@ -164,7 +169,7 @@ def generate_successors(
164
169
]
165
170
for diff in diffs :
166
171
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 ):
168
173
continue
169
174
170
175
current_interval = parent_node .interval
@@ -218,20 +223,18 @@ def calculate_heuristic(self, position) -> int:
218
223
219
224
220
225
show_animation = True
221
- verbose = True
226
+ verbose = False
222
227
223
- # TODO: viz shows obstacle finish 1 cell above the goal?
224
228
def main ():
225
- start = Position (1 , 18 )
229
+ start = Position (1 , 1 )
226
230
goal = Position (19 , 19 )
227
231
grid_side_length = 21
228
232
grid = Grid (
229
233
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 ,
232
235
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 ,
235
238
)
236
239
237
240
planner = SafeIntervalPathPlanner (grid , start , goal )
@@ -265,7 +268,7 @@ def main():
265
268
"key_release_event" , lambda event : [exit (0 ) if event .key == "escape" else None ]
266
269
)
267
270
268
- for i in range (0 , path .goal_reached_time ()):
271
+ for i in range (0 , path .goal_reached_time () + 1 ):
269
272
obs_positions = grid .get_obstacle_positions_at_time (i )
270
273
obs_points .set_data (obs_positions [0 ], obs_positions [1 ])
271
274
path_position = path .get_position (i )
0 commit comments