map_saver.cpp
Go to the documentation of this file.
1 /*
2  * map_saver
3  * Copyright (c) 2019, Samsung Research America
4  *
5  * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
6  * COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
7  * COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
8  * AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
9  *
10  * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO
11  * BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS
12  * CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
13  * CONDITIONS.
14  *
15  */
16 
17 /* Author: Steven Macenski */
18 
20 
21 namespace map_saver
22 {
23 
24 /*****************************************************************************/
25 MapSaver::MapSaver(ros::NodeHandle & nh, const std::string& map_name)
26 : nh_(nh), map_name_(map_name), received_map_(false)
27 /*****************************************************************************/
28 {
31 }
32 
33 /*****************************************************************************/
34 void MapSaver::mapCallback(const nav_msgs::OccupancyGrid& msg)
35 /*****************************************************************************/
36 {
37  received_map_ = true;
38 }
39 
40 /*****************************************************************************/
42  slam_toolbox_msgs::SaveMap::Request& req,
43  slam_toolbox_msgs::SaveMap::Response& resp)
44 /*****************************************************************************/
45 {
46  if (!received_map_)
47  {
48  ROS_WARN("Map Saver: Cannot save map, no map yet received on topic %s.",
49  map_name_.c_str());
50  return false;
51  }
52 
53  const std::string name = req.name.data;
54  if (name != "")
55  {
56  ROS_INFO("SlamToolbox: Saving map as %s.", name.c_str());
57  int rc = system(("rosrun map_server map_saver -f " + name).c_str());
58  }
59  else
60  {
61  ROS_INFO("SlamToolbox: Saving map in current directory.");
62  int rc = system("rosrun map_server map_saver");
63  }
64  ros::Duration(1.0).sleep();
65  return true;
66 }
67 
68 } // end namespace
ros::Subscriber sub_
Definition: map_saver.hpp:43
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
#define ROS_WARN(...)
MapSaver(ros::NodeHandle &nh, const std::string &service_name)
Definition: map_saver.cpp:25
std::string map_name_
Definition: map_saver.hpp:44
void mapCallback(const nav_msgs::OccupancyGrid &msg)
Definition: map_saver.cpp:34
ros::ServiceServer server_
Definition: map_saver.hpp:42
#define ROS_INFO(...)
bool saveMapCallback(slam_toolbox_msgs::SaveMap::Request &req, slam_toolbox_msgs::SaveMap::Response &resp)
Definition: map_saver.cpp:41
ros::NodeHandle nh_
Definition: map_saver.hpp:41
bool sleep() const


slam_toolbox
Author(s): Steve Macenski
autogenerated on Wed Mar 3 2021 03:49:20