ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

RCUTILS logging macro vs ROS_INFO

asked 2021-04-11 05:29:13 -0500

Kappa95 gravatar image

Hi Community, I am starting to studying ROS2 in order to start to work with Realtime and Lifecycle nodes. I would like to ask which are the differences between the rcutils and the classical debugging/printout methods provided by ROS2 like ROS_INFO. The usage of these tools like rcutils have better performances for realtime and are suitable for these applications?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-04-20 12:02:17 -0500

sgvandijk gravatar image

It should not matter too much, because the RCLCPP logging macros (which replace the ROS_INFO calls from ROS 1) are implemented by using rcutils. See for instance RCLCPP_DEBUG:

  do { \
    static_assert( \
      ::std::is_same<typename std::remove_cv<typename std::remove_reference<decltype(logger)>::type>::type, \
      typename ::rclcpp::Logger>::value, \
      "First argument to logging macros must be an rclcpp::Logger"); \
 \
    RCUTILS_LOG_DEBUG_NAMED( \
      logger.get_name(), \
      rclcpp::get_c_string(RCLCPP_FIRST_ARG(__VA_ARGS__, "")), \
        RCLCPP_ALL_BUT_FIRST_ARGS(__VA_ARGS__,"")); \
  } while (0)

So decoding this, it basically just calls RCUTILS_LOG_DEBUG_NAMED, with a little bit of extra overhead to get the name of the logger you are using, which is negligible, and some magic to ensure the first argument is a C string that also should be very cheap, and some static type checks at the beginning that only affect compilation time.

So I'd just continue using the RCLCPP macros if you're working in C++, unless your profiling shows you have a bottleneck here :)

NB the snippet above is from Foxy, but for Dashing it is not different in a way that affects your question.

edit flag offensive delete link more

Comments

Thank you so much!

Kappa95 gravatar image Kappa95  ( 2021-04-22 01:52:06 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-04-11 05:29:13 -0500

Seen: 136 times

Last updated: Apr 20 '21