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
29 #include <mrpt/utils/COutputLogger.h>
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 
115 inline mrpt::math::TPose3D p2t(const mrpt::poses::CPose3D& p)
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
console.h
mrpt_bridge::rosLoggerLvlToMRPTLoggerLvl
VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(log4cxx::LevelPtr lvl)
function that converts ROS verbosity level log4cxx::Level to MRPT equivalent MRPT's VerbosityLevel
Definition: utils.h:39
ROS_DEBUG
#define ROS_DEBUG(...)
ROS_WARN
#define ROS_WARN(...)
mrpt_bridge::p2t
mrpt::math::TPose3D p2t(const mrpt::poses::CPose3D &p)
Definition: utils.h:115
mrpt_bridge::mrptToROSLoggerCallback_mrpt_15
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
ROS_ERROR
#define ROS_ERROR(...)
mrpt::utils
Definition: map.h:52
mrpt_bridge
File includes methods for converting CNetworkOfPoses*DInf <=> NetworkOfPoses message types.
Definition: include/mrpt_bridge/beacon.h:52
ROS_INFO
#define ROS_INFO(...)
mrpt_bridge::mrptToROSLoggerCallback
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


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Sun Mar 6 2022 03:48:10