dusty-nv / ros_deep_learning

Deep learning inference nodes for ROS / ROS2 with support for NVIDIA Jetson and TensorRT
862 stars 258 forks source link

Migrating from RCUTILS to RCLCPP for Enhanced /rosout Log Publishing #138

Open h-sh-h opened 3 weeks ago

h-sh-h commented 3 weeks ago

Hi The current logging procedure uses RCUTILS, which only logs to the console and not to the /rosout topic. Similar related issue Here.

The following changes are required to migrate the logging to RCLCPP.

  1. Add following line to ros_compat.cpp
    clcpp::Node::SharedPtr node;
  2. Remove RCUTILS macros from ros_compat.h and replace RCLCPP macros
    
    // #define ROS_INFO(...)    RCUTILS_LOG_INFO_NAMED(__node_name_.c_str(), __VA_ARGS__)
    // #define ROS_DEBUG(...)   RCUTILS_LOG_DEBUG_NAMED(__node_name_.c_str(), __VA_ARGS__)
    // #define ROS_ERROR(...)   RCUTILS_LOG_ERROR_NAMED(__node_name_.c_str(), __VA_ARGS__)

define ROS_INFO(...) RCLCPP_INFO(node->get_logger(), __VA_ARGS__)

define ROS_DEBUG(...) RCLCPP_DEBUG(node->get_logger(), __VA_ARGS__)

define ROS_ERROR(...) RCLCPP_ERROR(node->get_logger(), __VA_ARGS__)

3. Since RCLCPP needs node to get logger from, the node should be defined as extern variable in ros_compat.h

extern std::string __nodename; extern rclcpp::Node::SharedPtr node; // This line is added

4. Modify ROS_CREATE_NODE macro in ros_compat.h (remove auto keyword)

define ROS_CREATE_NODE(name) \

    rclcpp::init(argc, argv);                   \
    node = rclcpp::Node::make_shared(name, "/" name); \
    __node_name_ = name; \
    __global_clock_ = std::make_shared<rclcpp::Clock>(RCL_ROS_TIME);


After these changes, the logs are now forwarded to both console and /rosout.

Unfortunately, I don't have enough time to test the entire package after this modification to check for potential issues. Therefore, I am leaving this note here to inform others.

Thanks