ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

You first have to create a service client somewhere:

    map_service_client_ = n_.serviceClient<nav_msgs::GetMap>("map");

Then, you can use it like this:

nav_msgs::GetMap srv_map;

if (map_service_client_.call(srv_map))
{
  ROS_INFO("Map service called successfully");
  const nav_msgs::OccupancyGrid& map (srv_map.response.map);
  //do something with the map
}
else
{
  ROS_ERROR("Failed to call map service");
  return;
}

This is the easy part. More difficult is initializing gmapping with an existing map. It keeps multiple map/pose hypotheses in memory, so initializing it would mean you have to initialize all those. This hasn't been done before AFAIK and will require that you change code inside the gmapping core, which internally uses a different map representation than ROS does. I'm sure it's doable, but it will require some work.