ANYbotics / grid_map

Universal grid map library for mobile robotic mapping
BSD 3-Clause "New" or "Revised" License
2.58k stars 800 forks source link

How to convert grid map from Elevation Mapping to CostMap2D? #399

Open Aishkrish18 opened 11 months ago

Aishkrish18 commented 11 months ago

Hello, I am new to this repository and I see that we can convert any kind of grid map to occupancy grids/costmap2D . I also see these convertors in many of the issues on how to do it. But I dont understand how exactly do I execute this? Do i write my own separate launch files to do this?

deweykai commented 10 months ago

You can use the grid_map_visualization node to convert a grid map topic into several others including an occupancy grid. Most of the grid_map demos do this in their launch file.

Also, you can include grid_map_ros/GridMapRosConvertor.hpp to convert a grid_map to other ros representations including a costmap2d.

Aishkrish18 commented 9 months ago

Thank you for your reply. Honestly, I am quite versatile with python and ros and not with c ++ and im quite unsure how to use this node from the repo, could you please explain a bit elaborately so that I can try it out? I am currently working on my thesis and it would be really helpful for me to implement this.

Thanks!

deweykai commented 9 months ago

Looking at it again, the toCostmap function is only available in the ros2 branch. You can use the grid_map_visualization node to output a occupancy grid like shown here (launch) for traversability. Then use a costmap_2d_node with a static layer listening to the occupancy grid topic.

Or if you want to directly output a costmap2d. I think you can use Costmap2DConverter. Pseudo code:

// variables
grid_map::GridMap map;
costmap_2d::Costmap2D outputMap;
grid_map::Costmap2DConverter<grid_map::GridMap> converter;

// initialize
converter.initializeFromGridMap(grid, costmap);

// create costmap
converter.setCostmap2DFromGridMap(grid, "layer name", costmap);