utils.h
Go to the documentation of this file.
1 /*
2  * File: utils.h
3  * Author: Vladislav Tananaev
4  *
5  */
6 
7 #ifndef MRPT_BRIDGE_UTILS_H
8 #define MRPT_BRIDGE_UTILS_H
9 
10 #include <ros/console.h>
11 #include <mrpt/system/datetime.h>
12 #include <mrpt/poses/CPose3D.h>
13 #include <mrpt/version.h>
14 #include <log4cxx/logger.h>
15 
16 #if MRPT_VERSION>=0x199
17 #include <mrpt/system/COutputLogger.h>
18 using namespace mrpt::system;
19 #else
20 #include <mrpt/utils/COutputLogger.h>
21 using namespace mrpt::utils;
22 #endif
23 
24 namespace mrpt_bridge
25 {
30 inline VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(log4cxx::LevelPtr lvl)
31 {
32  using namespace log4cxx;
33 
34  // determine on the corresponding VerbosityLevel
35  VerbosityLevel mrpt_lvl;
36 
37  if (lvl == Level::getFatal() || lvl == Level::getError())
38  {
39  mrpt_lvl = LVL_ERROR;
40  }
41  else if (lvl == Level::getWarn())
42  {
43  mrpt_lvl = LVL_WARN;
44  }
45  else if (lvl == Level::getInfo())
46  {
47  mrpt_lvl = LVL_INFO;
48  }
49  else if (lvl == Level::getDebug())
50  {
51  mrpt_lvl = LVL_DEBUG;
52  }
53  else
54  {
55  THROW_EXCEPTION("Unknown log4cxx::Level is given.");
56  }
57 
58  return mrpt_lvl;
59 
60 } // end of rosLoggerLvlToMRPTLoggerLvl
61 
70  const std::string& msg, const VerbosityLevel level,
71  const std::string& loggerName, const mrpt::system::TTimeStamp timestamp)
72 {
73  // Remove trailing \n if present
74  std::string tmsg = msg;
75  if (!tmsg.empty() &&
76  tmsg.compare(tmsg.length() - 1, tmsg.length(), "\n") == 0)
77  {
78  tmsg.erase(tmsg.end() - 1);
79  }
80 
81  if (level == LVL_DEBUG)
82  {
83  ROS_DEBUG("%s", tmsg.c_str());
84  }
85  else if (level == LVL_INFO)
86  {
87  ROS_INFO("%s", tmsg.c_str());
88  }
89  else if (level == LVL_WARN)
90  {
91  ROS_WARN("%s", tmsg.c_str());
92  }
93  else if (level == LVL_ERROR)
94  {
95  ROS_ERROR("%s", tmsg.c_str());
96  }
97 }
99  const std::string& msg, const VerbosityLevel level,
100  const std::string& loggerName, const mrpt::system::TTimeStamp timestamp,
101  void* userParam)
102 {
103  mrptToROSLoggerCallback(msg,level,loggerName,timestamp);
104 }
105 
106 inline mrpt::math::TPose3D p2t(const mrpt::poses::CPose3D &p)
107 {
108 #if MRPT_VERSION>=0x199
109  return p.asTPose();
110 #else
111  return TPose3D(p);
112 #endif
113 }
114 
115 } // namespace mrpt_bridge
116 
117 #endif // MRPT_BRIDGE_UTILS_H
#define ROS_WARN(...)
File includes methods for converting CNetworkOfPoses*DInf <=> NetworkOfPoses message types...
mrpt::math::TPose3D p2t(const mrpt::poses::CPose3D &p)
Definition: utils.h:106
#define ROS_INFO(...)
VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(log4cxx::LevelPtr lvl)
function that converts ROS verbosity level log4cxx::Level to MRPT equivalent MRPT&#39;s VerbosityLevel ...
Definition: utils.h:30
void mrptToROSLoggerCallback(const std::string &msg, const VerbosityLevel level, const std::string &loggerName, const mrpt::system::TTimeStamp timestamp)
callback that is called by MRPT mrpt::utils::COuputLogger to redirect log messages to ROS logger...
Definition: utils.h:69
void mrptToROSLoggerCallback_mrpt_15(const std::string &msg, const VerbosityLevel level, const std::string &loggerName, const mrpt::system::TTimeStamp timestamp, void *userParam)
Definition: utils.h:98
#define ROS_ERROR(...)
#define ROS_DEBUG(...)


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Sat Apr 28 2018 02:49:17