Skip to content

Commit 19d0cb7

Browse files
committed
some bug fixes from testing different scenarios
1 parent 54a33ee commit 19d0cb7

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

PathPlanning/TimeBasedPathPlanning/GridWithDynamicObstacles.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(
9090
"""
9191
def generate_dynamic_obstacles(self, obs_count: int) -> list[list[Position]]:
9292
obstacle_paths = []
93-
for _ in (0, obs_count):
93+
for _ in range(0, obs_count):
9494
# Sample until a free starting space is found
9595
initial_position = self.sample_random_position()
9696
while not self.valid_obstacle_position(initial_position, 0):
@@ -184,13 +184,10 @@ def obstacle_arrangement_1(self, obs_count: int) -> list[list[Position]]:
184184
output:
185185
bool: True if position/time combination is valid, False otherwise
186186
"""
187-
def valid_position(self, position: Position, t: int = None) -> bool:
187+
def valid_position(self, position: Position, t: int) -> bool:
188188
# Check if new position is in grid
189189
if not self.inside_grid_bounds(position):
190190
return False
191-
192-
if not t:
193-
return True
194191

195192
# Check if new position is not occupied at time t
196193
return self.reservation_matrix[position.x, position.y, t] == 0
@@ -274,12 +271,9 @@ def get_safe_intervals_at_cell(self, cell: Position) -> list[Interval]:
274271
# TODO - this is generating np.int instead of normal int, is that alright?
275272
intervals = [Interval(start, end) for start, end in zip(start_indices, end_indices)]
276273

277-
print(f"intervals at position {cell} : {intervals}")
278274

279-
# for i in range(len(intervals)):
280275
for interval in intervals:
281276
if interval.start_time == interval.end_time:
282-
print("AAAAAAAAAA matching! ", interval.start_time)
283277
# TODO: hate this modification in the loop
284278
intervals.remove(interval)
285279

PathPlanning/TimeBasedPathPlanning/SafeInterval.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

220225
show_animation = True
221-
verbose = True
226+
verbose = False
222227

223-
# TODO: viz shows obstacle finish 1 cell above the goal?
224228
def 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

Comments
 (0)