Skip to content

Commit 486c434

Browse files
committed
feat: plot path in search
1 parent 3f3008c commit 486c434

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/components/plan/elastic_bands/elastic_bands_path_planner.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ def __init__(self, start, goal, map_file, *,
233233
self.y_range = np.arange(y_min, y_max, self.resolution)
234234
self.rows, self.cols = self.grid.shape
235235

236-
# SDF: distance (in cells) to nearest obstacle for every free cell
237-
obstacle_mask = (self.grid >= 0.99)
238-
self.sdf = distance_transform_edt(~obstacle_mask)
236+
# SDF: distance (in cells) to nearest impassable cell
237+
# (obstacles at >= 0.99 AND clearance zones at ~0.75)
238+
impassable_mask = (self.grid > 0)
239+
self.sdf = distance_transform_edt(~impassable_mask)
239240

240241
# A* initial path
241242
self.path = []
@@ -308,7 +309,7 @@ def _astar_search(self):
308309
nb = (current[0] + dx, current[1] + dy)
309310
if not (0 <= nb[0] < self.cols and 0 <= nb[1] < self.rows):
310311
continue
311-
if self.grid[nb[1], nb[0]] >= 0.99:
312+
if self.grid[nb[1], nb[0]] > 0:
312313
continue
313314
step = 1.414 if (dx != 0 and dy != 0) else 1.0
314315
nc = cost[current] + step
@@ -456,17 +457,27 @@ def update(i, ax):
456457
ax.plot(self.start[0], self.start[1], 'go', markersize=8, label="Start")
457458
ax.plot(self.goal[0], self.goal[1], 'ro', markersize=8, label="Goal")
458459

459-
# Draw bubbles during optimisation phase
460+
# Draw bubbles + path trace during optimisation phases
460461
if phase >= 3:
461462
snap = (history[opt_indices[min(local, len(opt_indices) - 1)]]
462463
if phase == 3 else self._optimiser.bubbles)
464+
# Bubble circles
463465
for bub in snap:
464466
wx = self.x_range[0] + bub.pos[0] * self.resolution
465467
wy = self.y_range[0] + bub.pos[1] * self.resolution
466468
r_world = bub.radius * self.resolution
467469
circ = Circle((wx, wy), r_world, fill=False,
468470
color='green', alpha=0.25, linewidth=0.5)
469471
ax.add_patch(circ)
472+
# Path line connecting bubble centers
473+
bx = [self.x_range[0] + b.pos[0] * self.resolution
474+
for b in snap]
475+
by = [self.y_range[0] + b.pos[1] * self.resolution
476+
for b in snap]
477+
ax.plot(bx, by, '-', color='#1565C0', linewidth=2.0,
478+
label="EB Path", zorder=5)
479+
ax.plot(bx, by, 'o', color='#1565C0', markersize=4,
480+
zorder=6)
470481

471482
ax.set_title(titles[phase](local), fontsize=14)
472483
ax.legend(loc='upper left')
-21.3 KB
Loading
288 KB
Loading
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[[0.0, 0.0], [9.0, -2.5], [20.0, -6.0], [29.0, -9.0], [34.0, -11.0], [37.0, -12.0], [38.0, -12.0], [40.0, -12.0], [41.0, -12.0], [43.5, -11.5], [50.0, -10.0]]
1+
[[0.0, 0.0], [4.0, -1.5], [13.5, -4.5], [18.5, -6.0], [27.5, -9.5], [32.0, -11.5], [35.0, -13.0], [36.5, -13.5], [38.5, -13.5], [40.5, -14.0], [41.5, -13.5], [44.0, -13.0], [45.0, -12.5], [50.0, -10.0]]

0 commit comments

Comments
 (0)