The ROS package pgm_map_creator can generate the pgm map directly from the Gazebo world. Compilation errors occur in ROS melodic are fixed. See reference for the original version of the package.

Ubuntu 18.04, ROS Melodic.
sudo apt-get install libignition-math2-dev protobuf-compilercd catkin_ws/src/
git clone https://github.com/gene-su/pgm_map_creatorcd catkin_ws
catkin_makecd catkin_ws/src/pgm_map_creator
mkdir worlds
cp my_world.world ~/catkin_ws/src/pgm_map_creator/worlds/Add the following code to the my_world.world, just before the </world> tag.
<plugin filename="libcollision_map_creator.so" name="collision_map_creator"/>cd catkin_ws/src/pgm_map_creator/launch
touch my_world.launchmy_world.launch
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<!-- World File -->
<arg name="world_file" default="$(find pgm_map_creator)/worlds/my_world.world"/>
<!-- Launch Gazebo World -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="use_sim_time" value="true"/>
<arg name="debug" value="false"/>
<arg name="gui" value="true" />
<arg name="world_name" value="$(arg world_file)"/>
</include>
</launch>roslaunch pgm_map_creator my_world.launchroslaunch pgm_map_creator request_publisher.launchWait for the plugin th generate map. Track the progess in the terminal that spawns the world file. Once it is done, the pgm map would be in the map folder of the pgm_map_creator.
You may also need a yaml file which provides the metadata of the map.
cd catkin_ws/src/pgm_map_creator/maps
touch map.yaml
map.yaml
image: map.pgm
resolution: 0.01
origin: [-15.0, -15.0, 0.0]
occupied_thresh: 0.65
free_thresh: 0.196
negate: 0
The parameters resolution and origin are based on the arguments in request_publisher.launch.
Add the following code to the top of /usr/include/boost/gil/extension/io/png_io_private.hpp
#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL2. [libprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: vector2d.proto
Change CmakeLists in pgm_map_creator/msgs/CMakeLists.txt to the following
find_package(Protobuf REQUIRED)
set(PROTOBUF_IMPORT_DIRS)
foreach(ITR ${GAZEBO_INCLUDE_DIRS})
if(ITR MATCHES ".*gazebo-[0-9.]+$")
set(PROTOBUF_IMPORT_DIRS "${ITR}/gazebo/msgs/proto")
endif()
endforeach()
set (msgs
collision_map_request.proto
#${PROTOBUF_IMPORT_DIRS}/vector2d.proto
#${PROTOBUF_IMPORT_DIRS}/header.proto
#${PROTOBUF_IMPORT_DIRS}/time.proto
)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${msgs})
add_library(collision_map_creator_msgs SHARED ${PROTO_SRCS})
target_include_directories(collision_map_creator_msgs PUBLIC ${PROTOBUF_INCLUDE_DIRS})
target_link_libraries(collision_map_creator_msgs ${PROTOBUF_LIBRARY})Edit the arguments in the launch/request_publisher.launch for a larger map size.
<arg name="xmin" default="-15" />
<arg name="xmax" default="15" />
<arg name="ymin" default="-15" />
<arg name="ymax" default="15" />
<arg name="scan_height" default="5" />
<arg name="resolution" default="0.01" />- Udacity: Robotic Software Engineer Nanodegree Program
- https://github.com/udacity/pgm_map_creator
- https://github.com/hyfan1116/pgm_map_creator