AutonomousVehicleControlBeginnersGuide
AutonomousVehicleControlBeginnersGuide copied to clipboard
Binary Occupancy Grid Implementation
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
-
Map Configuration:
- Provide
x_limandy_limto specify map boundaries. - Set the grid resolution to control cell size.
- Specify a clearance value for obstacle and vehicle safety.
- Provide
-
Obstacles:
- Define obstacles with attributes like
position,length,width, andyaw. - Add obstacles using an
ObstacleListobject.
- Define obstacles with attributes like
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.