Skip to content

Commit e6a4bf7

Browse files
committed
in_collision fix
1 parent 72d3fa0 commit e6a4bf7

4 files changed

Lines changed: 22 additions & 18 deletions

File tree

src/python_motion_planning/common/env/map/grid.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def is_expandable(self, point: tuple, src_point: tuple = None) -> bool:
309309
if not self.within_bounds(point):
310310
return False
311311
if src_point is not None:
312-
if self._esdf[point] < self._esdf[src_point]:
312+
if self._esdf[point] >= self._esdf[src_point]:
313313
return True
314314
return not self.type_map[point] == TYPES.OBSTACLE and not self.type_map[point] == TYPES.INFLATION
315315

@@ -369,9 +369,6 @@ def line_of_sight(self, p1: tuple, p2: tuple) -> list:
369369
Returns:
370370
points: List of point on the line of sight.
371371
"""
372-
if not self.is_expandable(p1, p2) or not self.is_expandable(p2, p1):
373-
return []
374-
375372
p1 = np.array(p1)
376373
p2 = np.array(p2)
377374

@@ -423,7 +420,7 @@ def in_collision(self, p1: tuple, p2: tuple) -> bool:
423420
Returns:
424421
in_collision: True if the line of sight is in collision, False otherwise.
425422
"""
426-
if not self.is_expandable(p1, p2) or not self.is_expandable(p2, p1):
423+
if not self.is_expandable(p1) or not self.is_expandable(p2, p1):
427424
return True
428425

429426
# Corner Case: Start and end points are the same
@@ -449,11 +446,12 @@ def in_collision(self, p1: tuple, p2: tuple) -> bool:
449446
steps = abs_delta[primary_axis]
450447
current = p1
451448

452-
# Check the start point
453-
if not self.is_expandable(tuple(current), tuple(current)):
454-
return True
449+
# # Check the start point
450+
# if not self.is_expandable(tuple(current)):
451+
# return True
455452

456453
for _ in range(steps):
454+
last_point = current.copy()
457455
current[primary_axis] += primary_step
458456

459457
# Update the error for the primary dimension
@@ -467,7 +465,7 @@ def in_collision(self, p1: tuple, p2: tuple) -> bool:
467465
error[d] -= delta2[primary_axis]
468466

469467
# Check the current point
470-
if not self.is_expandable(tuple(current), tuple(current)):
468+
if not self.is_expandable(tuple(current), tuple(last_point)):
471469
return True
472470

473471
return False
@@ -488,15 +486,19 @@ def inflate_obstacles(self, radius: float = 1.0) -> None:
488486
Args:
489487
radius: Radius of the inflation.
490488
"""
489+
self.update_esdf()
491490
for i in range(self.shape[0]):
492491
for j in range(self.shape[1]):
493-
if self.type_map[i, j] == TYPES.OBSTACLE:
494-
for k in range(round(i-radius), round(i+radius+1)):
495-
for l in range(round(j-radius), round(j+radius+1)):
496-
if k < 0 or k >= self.shape[0] or l < 0 or l >= self.shape[1]:
497-
continue
498-
if self.type_map[k, l] == TYPES.FREE and (k - i)**2 + (l - j)**2 <= radius**2:
499-
self.type_map[k, l] = TYPES.INFLATION
492+
if self.esdf[i, j] <= radius and self.type_map[i, j] == TYPES.FREE:
493+
self.type_map[i, j] = TYPES.INFLATION
494+
495+
# if self.type_map[i, j] == TYPES.OBSTACLE:
496+
# for k in range(round(i-radius), round(i+radius+1)):
497+
# for l in range(round(j-radius), round(j+radius+1)):
498+
# if k < 0 or k >= self.shape[0] or l < 0 or l >= self.shape[1]:
499+
# continue
500+
# if self.type_map[k, l] == TYPES.FREE and (k - i)**2 + (l - j)**2 <= radius**2:
501+
# self.type_map[k, l] = TYPES.INFLATION
500502

501503
def fill_expands(self, expands: List[Node]) -> None:
502504
"""

src/python_motion_planning/common/visualizer/visualizer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def plot_path(self, path: list, style: str = "-", color: str = "#13ae00", label:
130130
marker: marker of path
131131
'''
132132
path = np.array(path)
133+
if len(path.shape) < 2:
134+
return
133135
if path.shape[1] == 2:
134136
plt.plot(path[:, 0], path[:, 1], style, lw=linewidth, color=color, label=label, marker=marker)
135137
elif path.shape[1] == 3:

src/python_motion_planning/path_planner/graph_search/a_star.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def plan(self) -> Union[list, dict]:
8484
node = heapq.heappop(OPEN)
8585

8686
# obstacle found
87-
if not self.map_.is_expandable(node.current):
87+
if not self.map_.is_expandable(node.current, node.parent):
8888
continue
8989

9090
# exists in CLOSED list

src/python_motion_planning/path_planner/graph_search/theta_star.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def plan(self) -> tuple:
4747
node = heapq.heappop(OPEN)
4848

4949
# obstacle found
50-
if not self.map_.is_expandable(node.current):
50+
if not self.map_.is_expandable(node.current, node.parent):
5151
continue
5252

5353
# exists in CLOSED list

0 commit comments

Comments
 (0)