anybotics/grid_map

repository·master·Indexed 25 days ago

https://github.com/anybotics/grid_map

A C++ library with a ROS interface for managing two-dimensional grid maps with multiple data layers, such as elevation, friction, and traversability. Optimized for mobile robotic mapping and rough terrain navigation, it includes packages for core algorithms, ROS integration, RViz visualization, and conversions from PCL point clouds, meshes, OctoMap, and OpenCV images.

Tokens
5.3K
Snippets
13
Records
26
Agent score
85%

What's inside grid_map

  1. Overview of Grid Map packages

    master

    The grid_map repository is a meta-package containing several specialized packages:

    • grid_map_core: Implements core algorithms and the GridMap class. It has no ROS dependencies and relies on Eigen.
    • grid_map_ros: Main package for ROS-dependent projects; provides interfaces to convert grid maps to/from ROS message types.
    • grid_map_msgs: Contains ROS message and service definitions for the grid_map_msg/GridMap type.
    • grid_map_filters: Processes grid maps as a sequence of filters (built on ROS Filters).
    • grid_map_rviz_plugin: RViz plugin for 3D surface plot (height map) visualization.
    • grid_map_visualization: Converts GridMap messages to other ROS message types for visualization.
    • grid_map_sdf: Converts elevation maps into 3D signed distance fields.
    • grid_map_demos: Demonstration nodes.

    Conversion Packages:

    • grid_map_costmap_2d: Conversions for costmap_2d types.
    • grid_map_cv: Conversions for OpenCV image types.
    • grid_map_octomap: Conversions for OctoMap maps.
    • grid_map_pcl: Conversions for PCL polygon meshes and point clouds.
  2. Convert Point Clouds or Meshes to Grid Maps using grid_map_pcl

    master

    The grid_map_pcl package is a C++ ROS-integrated tool for computing 2.5D elevation maps from PCL types (point clouds and meshes).

    Conversion Methods

    • Meshes: Elevation is computed via raytracing from grid map cells to find intersections with the mesh.
    • Point Clouds: The point cloud is sliced into columns corresponding to grid map cells. Points within each column are clustered, and the elevation is determined by the mean Z-coordinate of either the lowest or highest cluster (depending on configuration). All calculations occur in the point cloud frame.
  3. Apply grid_map_filters to grid maps

    master

    The grid_map_filters package provides several filters that can be chained using a YAML configuration file (similar to ROS Filters).

    Available Filters:

    • gridMapFilters/ThresholdFilter: Sets values in an output layer to a specific value if a condition layer exceeds a threshold.
    • gridMapFilters/MeanInRadiusFilter: Computes the mean value of a layer within a specified radius.
    • gridMapFilters/MedianFillFilter: Fills NaN cells using the median of finite values within a radius.
    • gridMapFilters/NormalVectorsFilter: Computes normal vectors for a layer.
    • gridMapFilters/NormalColorMapFilter: Generates a color layer based on normal vector layers.
    • gridMapFilters/MathExpressionFilter: Evaluates mathematical matrix expressions (using EigenLab syntax) on layers.
    • gridMapFilters/SlidingWindowMathExpressionFilter: Evaluates mathematical expressions within a sliding window (e.g., for box blurs).
    • gridMapFilters/DuplicationFilter: Duplicates a layer.
    • gridMapFilters/DeletionFilter: Deletes specified layers.
  4. Run the grid_map_pcl conversion algorithm

    master

    To convert a .pcd file into a grid map saved as a ROS bag, follow these steps:

    1. Prepare Files: Place your .pcd file in the package folder or a known system path.
    2. Configure Launch File: Edit the launch file to set the following variables:
      • pcd_filename: Path to your input .pcd file.
      • output_grid_map: Path where the resulting .bag file will be saved.
      • configFilePath_: Path to your .yaml configuration file.
    3. Execute: Run the following command:
      roslaunch grid_map_pcl grid_map_pcl_loader_node.launch
    4. Visualize: Once finished, the output should appear in RViz. If not, run rviz in a separate terminal (after sourcing your workspace) to visualize the grid map. Do not close the terminal running the grid_map_pcl_loader_node until processing is complete.

    Performance Note:

    • ~10M points: ~1-2 minutes.
    • 40M-60M points: 5-15 minutes.
    • 100M-140M points: 30-60 minutes (using 6 threads).
    roslaunch grid_map_pcl grid_map_pcl_loader_node.launch
  5. Convert elevation maps to 3D SDF with grid_map_sdf

    master
    The grid_map_sdf package provides an algorithm to convert an elevation map into a dense 3D signed distance field (SDF). Each point in the resulting 3D grid contains the distance to the closest point in the map and its gradient.
  6. Configure grid_map_visualization for RViz

    master

    The grid_map_visualization node subscribes to grid_map_msgs/GridMap topics and publishes various visualization formats to RViz. The node is fully configurable via a YAML parameter file.

    Subscribed Topic:

    • grid_map_topic (string, default: /grid_map): The name of the grid map topic to be visualized.

    Available Visualization Types (Published via YAML config):

    TypeMessage TypeDescription
    point_cloudsensor_msgs/PointCloud2Shows the grid map as a point cloud using a specified layer
    flat_point_cloudsensor_msgs/PointCloud2Shows the map as a flat point cloud at a specific height (z-position)
    vectorsvisualization_msgs/MarkerVisualizes vector data (e.g., normals) using layer_prefix for x, y, z components
    occupancy_gridnav_msgs/OccupancyGridVisualizes a layer as an occupancy grid with data_min and data_max bounds
    grid_cellsnav_msgs/GridCellsVisualizes a layer as grid cells with lower_threshold and upper_threshold
    regionvisualization_msgs/MarkerShows the boundary of the grid map

    Note on Colors: Color values are RGB concatenated integers. Example for green: 3289650 (calculated as BitOr[BitShiftLeft[r,16], BitShiftLeft[g,8], b] where r=0, g=255, b=0).

  7. Visualize Grid Maps with grid_map_rviz_plugin

    master
    The grid_map_rviz_plugin allows you to visualize a grid map layer as a 3D surface plot (height map) directly in RViz. You can select a separate layer to provide color information for the visualization.
  8. Run Grid Map demonstrations

    master

    The grid_map_demos package provides several nodes to verify your installation and explore library functionalities. Use these roslaunch or rosrun commands to start specific demonstrations:

    • Simple usage: roslaunch grid_map_demos simple_demo.launch (creates and publishes a grid map).
    • Extended functionalities: roslaunch grid_map_demos tutorial_demo.launch.
    • Iterators: roslaunch grid_map_demos iterators_demo.launch.
    • Image to Grid Map: roslaunch grid_map_demos image_to_gridmap_demo.launch.
    • Grid Map to Image: rosrun grid_map_demos grid_map_to_image_demo _grid_map_topic:=/grid_map _file:=/home/$USER/Desktop/grid_map_image.png (saves a layer to a file).
    • OpenCV manipulations: roslaunch grid_map_demos opencv_demo.launch.
    • Resolution change: roslaunch grid_map_demos resolution_change_demo.launch.
    • ROS Filters chain: roslaunch grid_map_demos filters_demo.launch (uses filters_demo_filter_chain.yaml to process terrain maps).
    • Interpolation methods: roslaunch grid_map_demos interpolation_demo.launch.
  9. Build Grid Map from source

    master

    To build the library from source, clone the repository into your catkin workspace and compile it. It is recommended to build in Release mode to maximize performance.

    cd catkin_ws/src
    git clone https://github.com/anybotics/grid_map.ncd ../
    catkin_make
    
    # To maximize performance, use Release mode:
    catkin_make -DCMAKE_BUILD_TYPE=Release