Ask Your Question

How can I get the Data from costmap_2d in a file?

asked 2021-11-19 07:36:28 -0500

brokenglass gravatar image

I have implemented costmap_2d in my robot and now I want to get the information about obstacles, inflation and footprint inside a file and local planner. can you please help me?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2021-11-19 10:24:10 -0500

osilva gravatar image

updated 2021-11-19 11:37:03 -0500

Hi @brokenglass

When you save the map to disk from the map server by: rosrun map_server map_saver -f <map_name> two files will be generated.


A .pgm file that is a visual picture of the map and .yaml file that will contain information you are looking for. However you need to know how to interpret this information: Reference:

The image describes the occupancy state of each cell of the world in the color of the corresponding pixel. In the standard configuration, whiter pixels are free, blacker pixels are occupied, and pixels in between are unknown. Color images are accepted, but the color values are averaged to a gray value.

You can take a look how map_saver.cpp does it. Some people use OpenCV to read image and interpret the occupancy map.

If you want to do something more advanced, take a look at this package: Grid Map by Anybotics

And the information on local planner and global planner parameters are stored as .yaml files.

edit flag offensive delete link more


Thank you but I want to introduce obstacles in my local planner. the map related work is done. I am using NMPC local planner.

brokenglass gravatar image brokenglass  ( 2021-11-22 03:24:24 -0500 )edit

NMPC is a plug-in to the base_local_planner. The principles are the same as stated in my answer. You don’t introduce obstacles to the local planner. The local planner reads the costmap including obstacles to determine potential trajectories.

osilva gravatar image osilva  ( 2021-11-22 05:28:50 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2021-11-19 07:36:28 -0500

Seen: 372 times

Last updated: Nov 19 '21