mrpt_graphslam_2d_mr_node.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+
9  */
10 
11 // MRPT headers
12 #include <mrpt/system/COutputLogger.h>
13 #include <mrpt/graphslam/CGraphSlamEngine.h>
14 #include <mrpt/system/string_utils.h>
15 
16 #include <cstdlib>
17 #include <cstring>
18 
19 // ROS headers
21 
22 using namespace mrpt;
23 using namespace mrpt::poses;
24 using namespace mrpt::obs;
25 using namespace mrpt::system;
26 using namespace mrpt::graphs;
27 using namespace mrpt::math;
28 using namespace mrpt::opengl;
29 using namespace mrpt::graphslam;
30 using namespace mrpt::graphslam::deciders;
31 using namespace mrpt::graphslam::optimizers;
32 using namespace mrpt::graphslam::apps;
33 
34 using namespace std;
35 
37 int main(int argc, char** argv)
38 {
39  COutputLogger logger;
40 
41  try
42  {
43  std::string node_name = "mrpt_graphslam_2d_mr";
44 
45  ros::init(argc, argv, node_name);
46  ros::NodeHandle nh;
47 
48  node_name = node_name + nh.getNamespace();
49  logger.setLoggerName(node_name);
50  logger.logFmt(LVL_WARN, "Initialized %s node...\n", node_name.c_str());
51 
52  ros::Rate loop_rate(10);
53 
54  // Initialization
57  &logger, &options_checker, &nh);
58  graphslam_handler.readParams();
59  graphslam_handler.initEngine_MR();
60  graphslam_handler.setupComm();
61 
62  std::string ns = nh.getNamespace();
63  // overwite default results directory due to the multi-robot nature
64  graphslam_handler.setResultsDirName(
65  std::string(ns.begin() + 2, ns.end()));
66 
67  // print the parameters just for verification
68  graphslam_handler.printParams();
69 
70  bool cont_exec = true;
71  while (ros::ok() && cont_exec)
72  {
73  cont_exec = graphslam_handler.usePublishersBroadcasters();
74 
75  ros::spinOnce();
76  loop_rate.sleep();
77  }
78  }
79  catch (exception& e)
80  {
81  cout << "Known error!" << endl;
82  logger.logFmt(LVL_ERROR, "Caught exception: %s", e.what());
83  mrpt::system::pause();
84  return -1;
85  }
86  catch (...)
87  {
88  cout << "Unknown error!" << endl;
89  logger.logFmt(LVL_ERROR, "Finished with unknown exception. Exiting\n.");
90  mrpt::system::pause();
91  return -1;
92  }
93 }
void readParams()
Read the problem configuration parameters.
bool usePublishersBroadcasters()
Provide feedback about the SLAM operation using ROS publilshers, update the registered frames using t...
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL bool ok()
int main(int argc, char **argv)
void setupComm()
Wrapper method around the protected setup* class methods.
bool sleep()
void printParams()
Print in a compact manner the overall problem configuration parameters.
const std::string & getNamespace() const
Manage variables, ROS parameters and everything else related to the graphslam-engine ROS wrapper...
ROSCPP_DECL void spinOnce()


mrpt_graphslam_2d
Author(s): Nikos Koukis
autogenerated on Sun Jun 26 2022 02:12:26