octomap_server_node.cpp
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2009-2012, A. Hornung, University of Freiburg
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are met:
15  *
16  * * Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  * * Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  * * Neither the name of the University of Freiburg nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 
39 #include <ros/ros.h>
41 
42 #define USAGE "\nUSAGE: octomap_server <map.[bt|ot]>\n" \
43  " map.bt: inital octomap 3D map file to read\n"
44 
45 using namespace octomap_server;
46 
47 int main(int argc, char** argv){
48  ros::init(argc, argv, "octomap_server");
49  const ros::NodeHandle nh;
50  const ros::NodeHandle private_nh("~");
51  std::string mapFilename(""), mapFilenameParam("");
52 
53  if (argc > 2 || (argc == 2 && std::string(argv[1]) == "-h")){
54  ROS_ERROR("%s", USAGE);
55  exit(-1);
56  }
57 
58  OctomapServer server(private_nh, nh);
59  ros::spinOnce();
60 
61  if (argc == 2){
62  mapFilename = std::string(argv[1]);
63  }
64 
65  if (private_nh.getParam("map_file", mapFilenameParam)) {
66  if (mapFilename != "") {
67  ROS_WARN("map_file is specified by the argument '%s' and rosparam '%s'. now loads '%s'", mapFilename.c_str(), mapFilenameParam.c_str(), mapFilename.c_str());
68  } else {
69  mapFilename = mapFilenameParam;
70  }
71  }
72 
73  if (mapFilename != "") {
74  if (!server.openFile(mapFilename)){
75  ROS_ERROR("Could not open file %s", mapFilename.c_str());
76  exit(1);
77  }
78  }
79 
80  try{
81  ros::spin();
82  }catch(std::runtime_error& e){
83  ROS_ERROR("octomap_server exception: %s", e.what());
84  return -1;
85  }
86 
87  return 0;
88 }
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define USAGE
#define ROS_WARN(...)
ROSCPP_DECL void spin(Spinner &spinner)
int main(int argc, char **argv)
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)
virtual bool openFile(const std::string &filename)


octomap_server
Author(s): Armin Hornung
autogenerated on Tue Jan 26 2021 03:27:07