Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astar planner #24

Closed

Conversation

shantanuparabumd
Copy link

PR Description: A* Path Planning Implementation with File-Based Grid Input

Overview

This PR introduces an enhanced A* path planning implementation that supports loading the occupancy grid map from a file and generates paths for autonomous navigation. This modular and efficient design enables users to integrate pre-existing map files, visualize the planning process, and save the resulting path for future use.


Key Features

1. File-Based Grid Input

  • The planner supports multiple file formats for loading the map grid:
    • JSON: Load a 2D grid saved as a JSON array.
    • PNG: Interpret an image as a binary occupancy grid.
    • NumPy Binary (.npy): Load the grid efficiently from a NumPy file.
  • Automatically binarizes maps loaded from .png files to handle grayscale or colored images.

2. Grid and Resolution Handling

  • The planner automatically calculates the grid resolution based on the file input and provided map boundaries (x_lim and y_lim).
  • Works seamlessly with pre-generated binary occupancy grids, ensuring compatibility with existing mapping tools.

3. A Path Planning*

  • Implements grid-based A* path planning with:
    • 8-action set: Supports diagonal and cardinal movements for efficient exploration.
    • Min-Heap: Optimizes performance by prioritizing nodes with lower cost.
    • Heuristic Weighting: Adjustable parameter (weight) to balance exploration and heuristic-driven search.

4. Sparse Path Generation

  • Generates a sparse path from the full path to reduce the number of points while maintaining the trajectory.
  • Designed for integration with cubic spline interpolation for smooth trajectory planning.

5. Visualization and Animation

  • Animates the planning process, including:
    • Exploration phase: Marks visited nodes.
    • Path reconstruction phase: Displays the computed path after goal discovery.
  • Supports saving the visualization as a GIF (gif_name).
  • Utilizes a custom colormap to differentiate:
    • Free space: White.
    • Explored nodes: Light blue.
    • Path: Green.
    • Clearance zones: Gray.
    • Obstacles: Black.

6. Path Saving

  • Saves the computed path in JSON format for future use or further processing.

Usage Instructions

Input

  1. Grid Map:
    • Provide a pre-generated grid map in one of the supported formats (.npy, .png, .json).
    • Specify the map boundaries (x_lim and y_lim).
  2. Start and Goal Positions:
    • Provide the start and goal coordinates in world space.
  3. Parameters:
    • Adjust heuristic weight (weight) for exploration efficiency.
    • Specify file paths for saving the path and animation (optional).

Example

map_file = "map.json"
path_file = "path.json"
gif_path = "astar_search.gif"

x_lim, y_lim = MinMax(-5, 55), MinMax(-20, 25)

# Define start and goal positions
start = (0, 0)
goal = (50, -10)

# Create the A* planner
planner = AStarPathPlanner(start, goal, map_file, weight=5.0, x_lim=x_lim, y_lim=y_lim, path_filename=path_file, gif_name=gif_path)

Output

  • Visualization: Displays the grid, exploration process, and reconstructed path. Optionally saves as a GIF.
  • Path File: Saves the reconstructed path in JSON format.
  • Sparse Path: A sparse version of the path for smooth trajectory generation.

@ShisatoYano ShisatoYano added the enhancement New feature or request label Jan 27, 2025
@ShisatoYano ShisatoYano linked an issue Jan 27, 2025 that may be closed by this pull request
@ShisatoYano
Copy link
Owner

This PR can not be accepted because the previous commits for A star path planning implementation are also included.
Firstly, you should create a working branch only for Occupancy Grid Map implementation. It should not include any changes for any other algorithm’s implementations. Secondly, you need to complete the implementation and the test at the branch. And then, you can send me the PR.
If you want to create the second working branch for A star path planning implementation, you can create it after the first PR was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementation of A-Star Algorithm
2 participants