Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/components/plan/astar/astar_path_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def save_path(self, path, filename):


def visualize_search(self, gif_name=None):
if gif_name is None:
return

print(f"Exploring {len(self.explored_nodes)} nodes.")
if not self.explored_nodes:
print("Error: No explored nodes. Ensure search() is executed before visualize_search().")
Expand All @@ -225,15 +228,12 @@ def visualize_search(self, gif_name=None):
repeat=False,
)

if gif_name is not None:
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")
else:
plt.show()
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")

# clear existing plot and close existing figure
plt.clf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ def save_path(self, path, filename):
json.dump(path, f)

def visualize_search(self, gif_name=None):
if gif_name is None:
return

print(f"Exploring {len(self.explored_nodes)} nodes.")
if not self.explored_nodes:
print("Error: No explored nodes. Ensure search() is executed before visualize_search().")
Expand All @@ -377,15 +380,12 @@ def visualize_search(self, gif_name=None):
repeat=False,
)

if gif_name is not None:
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")
else:
plt.show()
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")

# clear existing plot and close existing figure
plt.clf()
Expand Down
42 changes: 21 additions & 21 deletions src/components/plan/dijkstra/dijkstra_path_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ def save_path(self, path, filename):


def visualize_search(self, gif_name=None):
if gif_name is None:
return

print(f"Exploring {len(self.explored_nodes)} nodes.")
if not self.explored_nodes:
print("Error: No explored nodes. Ensure search() is executed before visualize_search().")
Expand Down Expand Up @@ -226,28 +229,25 @@ def visualize_search(self, gif_name=None):
repeat=False,
)

if gif_name is not None:
try:
print("Saving animation...")
# Use FFmpeg writer if available for better memory efficiency
try:
print("Saving animation...")
# Use FFmpeg writer if available for better memory efficiency
try:
self.anime.save(gif_name, writer="pillow", fps=20,
savefig_kwargs={'bbox_inches': 'tight', 'dpi': 100})
except Exception:
# Fallback to pillow with reduced quality
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")
# Try saving as MP4 instead if GIF fails
try:
mp4_name = gif_name.replace('.gif', '.mp4')
self.anime.save(mp4_name, writer="ffmpeg", fps=20)
print(f"Saved as MP4 instead: {mp4_name}")
except Exception as e2:
print(f"Both GIF and MP4 saving failed: {e2}")
else:
plt.show()
self.anime.save(gif_name, writer="pillow", fps=20,
savefig_kwargs={'bbox_inches': 'tight', 'dpi': 100})
except Exception:
# Fallback to pillow with reduced quality
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")
# Try saving as MP4 instead if GIF fails
try:
mp4_name = gif_name.replace('.gif', '.mp4')
self.anime.save(mp4_name, writer="ffmpeg", fps=20)
print(f"Saved as MP4 instead: {mp4_name}")
except Exception as e2:
print(f"Both GIF and MP4 saving failed: {e2}")

# clear existing plot and close existing figure
plt.clf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def save_path(self, path):
json.dump(path, f)

def visualize_search(self, gif_name, frame_skip=3):
if not self.tree_edges:
if gif_name is None or not self.tree_edges:
return

Path(gif_name).parent.mkdir(parents=True, exist_ok=True)
Expand Down
18 changes: 9 additions & 9 deletions src/components/plan/rrt/rrt_path_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ def save_path(self, path, filename):


def visualize_search(self, gif_name=None):
if gif_name is None:
return

print(f"Exploring {len(self.explored_nodes)} nodes.")
if not self.explored_nodes:
print("Error: No explored nodes. Ensure search() is executed before visualize_search().")
Expand All @@ -308,15 +311,12 @@ def visualize_search(self, gif_name=None):
repeat=False,
)

if gif_name is not None:
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")
else:
plt.show()
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")

# clear existing plot and close existing figure
plt.clf()
Expand Down
18 changes: 9 additions & 9 deletions src/components/plan/rrt_star/rrt_star_path_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ def save_path(self, path, filename):
json.dump(path, f)

def visualize_search(self, gif_name=None):
if gif_name is None:
return

print(f"Exploring {len(self.explored_nodes)} nodes.")
if not self.explored_nodes:
print("Error: No explored nodes. Ensure search() is executed before visualize_search().")
Expand All @@ -417,15 +420,12 @@ def visualize_search(self, gif_name=None):
repeat=False,
)

if gif_name is not None:
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")
else:
plt.show()
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")

plt.clf()
plt.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ def save_path(self, path, filename):
json.dump(path, f)

def visualize_search(self, gif_name=None):
if gif_name is None:
return

print(f"Exploring {len(self.explored_nodes)} nodes.")
if not self.explored_nodes:
print("Error: No explored nodes. Ensure search() is executed before visualize_search().")
Expand All @@ -399,15 +402,12 @@ def visualize_search(self, gif_name=None):
repeat=False,
)

if gif_name is not None:
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")
else:
plt.show()
try:
print("Saving animation...")
self.anime.save(gif_name, writer="pillow")
print("Animation saved successfully.")
except Exception as e:
print(f"Error saving animation: {e}")

plt.clf()
plt.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def main():
x_lim=x_lim,
y_lim=y_lim,
path_filename=path_filename,
gif_name=search_gif_path,
gif_name=search_gif_path if show_plot else None,
)

# Load sparse path from json file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main():
occ_grid.save_map()
# Easy Goal = (50,22)
# Hard Goal = (50,-10)
planner = AStarPathPlanner((0, 0), (50, -10), map_path, weight=5.0, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path)
planner = AStarPathPlanner((0, 0), (50, -10), map_path, weight=5.0, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path if show_plot else None)

# Load sparse path from json file
with open(path_filename, 'r') as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main():
occ_grid.save_map()
# Easy Goal = (50,22)
# Hard Goal = (50,-10)
planner = DijkstraPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path)
planner = DijkstraPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path if show_plot else None)

# Load sparse path from json file
with open(path_filename, 'r') as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def main():
occ_grid.add_object(obst_list)
occ_grid.save_map()

planner = InformedRrtStarPathPlanner((10, 0), (30, 0), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path,
planner = InformedRrtStarPathPlanner((10, 0), (30, 0), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path if show_plot else None,
max_iterations=1200,step_size=1.5,goal_sample_rate=0.05, visualize_live=False)

# Load sparse path from json file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main():
occ_grid.save_map()
# Easy Goal = (50,22)
# Hard Goal = (50,-10)
planner = RrtPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path,
planner = RrtPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path if show_plot else None,
max_iterations=5000,step_size=0.5,goal_sample_rate=0.05)

# Load sparse path from json file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main():
occ_grid.save_map()
# Easy Goal = (50,22)
# Hard Goal = (50,-10)
planner = RrtStarBidirectionalPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path,
planner = RrtStarBidirectionalPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path if show_plot else None,
max_iterations=5000, step_size=0.5, goal_sample_rate=0.05)

# Load sparse path from json file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main():
occ_grid.save_map()
# Easy Goal = (50,22)
# Hard Goal = (50,-10)
planner = RrtStarPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path,
planner = RrtStarPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path if show_plot else None,
max_iterations=5000, step_size=0.5, goal_sample_rate=0.05)

# Load sparse path from json file
Expand Down
Loading