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

Binary Occupancy Grid Implementation #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shantanuparabumd
Copy link

PR Description: Binary Occupancy Grid Implementation

Overview

This PR introduces a BinaryOccupancyGrid class that provides a grid-based representation of the environment for autonomous vehicle path planning and simulation. The implementation supports obstacle modeling, clearance handling, and visualization, making it a robust foundational tool for tasks like path planning, collision avoidance, and trajectory generation.

Key Features

1. Grid-Based Representation
  • The grid is created based on user-defined limits (x_lim, y_lim) and resolution.
  • Each cell in the grid represents a specific region of the map, allowing for spatial discretization.
  • Resolution determines the granularity of the grid: higher resolution captures finer details but requires more memory.
2. Obstacle Handling
  • Supports adding obstacles with attributes such as position (x, y), dimensions (length, width), and rotation (yaw).
  • Obstacles are represented in the grid with values corresponding to their presence.
3. Clearance Space
  • Clearance is calculated as a combination of obstacle clearance and an additional buffer to ensure safe navigation.
  • Clearance is marked distinctly on the grid for visualization purposes, providing a clear separation between free space, clearance zones, and obstacles.
4. Visualization
  • Utilizes a custom colormap to visually distinguish:
    • Free space: White.
    • Explored nodes: Light blue.
    • Path: Green (if integrated with a path planner).
    • Clearance zones: Gray.
    • Obstacles: Black.
  • Users can save the grid as an image (.png), JSON (.json), or binary NumPy file (.npy).
5. Obstacle Modeling
  • Obstacles are defined using corner-based calculations and transformations to account for rotation (yaw).
  • Efficient marking of grid cells within obstacle and clearance boundaries using polygon-based collision checks.
6. Map Saving
  • The grid map can be saved in multiple formats:
    • PNG: For visualization.
    • Numpy Binary (.npy): For programmatic reloading.
    • JSON: For sharing or debugging.

Usage Instructions

Input
  1. Map Configuration:

    • Provide x_lim and y_lim to specify map boundaries.
    • Set the grid resolution to control cell size.
    • Specify a clearance value for obstacle and vehicle safety.
  2. Obstacles:

    • Define obstacles with attributes like position, length, width, and yaw.
    • Add obstacles using an ObstacleList object.
Example
obst_list = ObstacleList()
obst_list.add_obstacle(Obstacle(State(x_m=10.0, y_m=15.0), length_m=10, width_m=8))
obst_list.add_obstacle(Obstacle(State(x_m=40.0, y_m=0.0), length_m=2, width_m=10))

bin_occ_grid = BinaryOccupancyGrid(MinMax(-5, 55), MinMax(-20, 25), resolution=0.5, clearance=1.5)
bin_occ_grid.add_object(obst_list)
bin_occ_grid.save_map("map.json")
Output
  • A saved grid map in the specified format (e.g., JSON, PNG).
  • Visualized grid showing free space, obstacles, and clearance zones.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the binary occupancy grid map class was implemented, the mapper module class need to be implemented by referring to the following ndt global mapper class.
https://github.com/ShisatoYano/AutonomousVehicleControlBeginnersGuide/blob/main/src/components/mapping/ndt/ndt_global_mapper.py
This global mapper class is given to the vehicle object as a global mapper module and provides the interfaces for mapping.


# Define RGB colors for each grid value
# Colors in the format [R, G, B], where values are in the range [0, 1]
colors = [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant value should be defined as a constant member value of the class and be named as COLORS if it is not changed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a simulation of binary occupancy grid map construction by referring to the following ndt map construction simulation.
https://github.com/ShisatoYano/AutonomousVehicleControlBeginnersGuide/blob/main/src/simulations/mapping/ndt_map_construction/ndt_map_construction.py
And then, please add a unit test code for the simulation by referring to this test code.
https://github.com/ShisatoYano/AutonomousVehicleControlBeginnersGuide/blob/main/test/test_ndt_map_construction.py

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