map_loader_node.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
22 #include "stdr_server/map_loader.h"
23 #include <stdr_msgs/LoadExternalMap.h>
24 
25 #define USAGE "USAGE: load_map <map_file.yaml>"
26 
33 int main(int argc, char** argv) {
34 
35  ros::init(argc, argv, "map_loader", ros::init_options::AnonymousName);
36 
37  ros::NodeHandle nh;
38 
39  if (argc == 2) {
40 
41  nav_msgs::OccupancyGrid map;
42 
43  map = stdr_server::map_loader::loadMap(std::string(argv[1]));
44 
45  ros::ServiceClient client;
46 
48  "/stdr_server/load_static_map_external", ros::Duration(.1)) && ros::ok())
49  {
50  ROS_WARN(
51  "Trying to register to /stdr_server/load_static_map_external...");
52  }
53  client = nh.serviceClient<stdr_msgs::LoadExternalMap>
54  ("/stdr_server/load_static_map_external", true);
55 
56  stdr_msgs::LoadExternalMap srv;
57 
58  srv.request.map = map;
59 
60  if (client.call(srv)) {
61  ROS_INFO("Map successfully loaded");
62  return 0;
63  }
64  else {
65  ROS_ERROR("Could not load map, maybe already loaded...");
66  return -1;
67  }
68 
69  }
70  else {
71  ROS_ERROR("%s", USAGE);
72  return -1;
73  }
74 
75 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
#define USAGE
#define ROS_WARN(...)
nav_msgs::OccupancyGrid loadMap(const std::string &fname)
Loads a map from an image file.
Definition: map_loader.cpp:33
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
int main(int argc, char **argv)
Main function of the server node.
#define ROS_ERROR(...)
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)


stdr_server
Author(s): Chris Zalidis
autogenerated on Mon Jun 10 2019 15:15:07