utils.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, 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  * File: utils.h
12  * Author: Vladislav Tananaev
13  *
14  */
15 
16 #pragma once
17 
18 #include <ros/console.h>
19 #include <mrpt/system/datetime.h>
20 #include <mrpt/poses/CPose3D.h>
21 #include <mrpt/version.h>
22 #include <log4cxx/logger.h>
23 
24 #if MRPT_VERSION >= 0x199
25 #include <mrpt/system/COutputLogger.h>
26 #include <mrpt/math/TPose3D.h>
27 using namespace mrpt::system;
28 #else
30 using namespace mrpt::utils;
31 #endif
32 
33 namespace mrpt_bridge
34 {
39 inline VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(log4cxx::LevelPtr lvl)
40 {
41  using namespace log4cxx;
42 
43  // determine on the corresponding VerbosityLevel
44  VerbosityLevel mrpt_lvl;
45 
46  if (lvl == Level::getFatal() || lvl == Level::getError())
47  {
48  mrpt_lvl = LVL_ERROR;
49  }
50  else if (lvl == Level::getWarn())
51  {
52  mrpt_lvl = LVL_WARN;
53  }
54  else if (lvl == Level::getInfo())
55  {
56  mrpt_lvl = LVL_INFO;
57  }
58  else if (lvl == Level::getDebug())
59  {
60  mrpt_lvl = LVL_DEBUG;
61  }
62  else
63  {
64  THROW_EXCEPTION("Unknown log4cxx::Level is given.");
65  }
66 
67  return mrpt_lvl;
68 
69 } // end of rosLoggerLvlToMRPTLoggerLvl
70 
79  const std::string& msg, const VerbosityLevel level,
80  const std::string& loggerName, const mrpt::system::TTimeStamp timestamp)
81 {
82  // Remove trailing \n if present
83  std::string tmsg = msg;
84  if (!tmsg.empty() &&
85  tmsg.compare(tmsg.length() - 1, tmsg.length(), "\n") == 0)
86  {
87  tmsg.erase(tmsg.end() - 1);
88  }
89 
90  if (level == LVL_DEBUG)
91  {
92  ROS_DEBUG("%s", tmsg.c_str());
93  }
94  else if (level == LVL_INFO)
95  {
96  ROS_INFO("%s", tmsg.c_str());
97  }
98  else if (level == LVL_WARN)
99  {
100  ROS_WARN("%s", tmsg.c_str());
101  }
102  else if (level == LVL_ERROR)
103  {
104  ROS_ERROR("%s", tmsg.c_str());
105  }
106 }
108  const std::string& msg, const VerbosityLevel level,
109  const std::string& loggerName, const mrpt::system::TTimeStamp timestamp,
110  void* userParam)
111 {
112  mrptToROSLoggerCallback(msg, level, loggerName, timestamp);
113 }
114 
116 {
117 #if MRPT_VERSION >= 0x199
118  return p.asTPose();
119 #else
120  return mrpt::math::TPose3D(p);
121 #endif
122 }
123 
124 } // namespace mrpt_bridge
uint64_t TTimeStamp
#define THROW_EXCEPTION(msg)
#define ROS_WARN(...)
static XMLCSTR getError(XMLError error)
File includes methods for converting CNetworkOfPoses*DInf <=> NetworkOfPoses message types...
mrpt::math::TPose3D p2t(const mrpt::poses::CPose3D &p)
Definition: utils.h:115
#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:39
GLfloat GLfloat p
GLint level
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:78
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:107
#define ROS_ERROR(...)
#define ROS_DEBUG(...)


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Fri Feb 28 2020 03:22:14