Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
h-sh-h opened this issue Jun 14, 2024 · 0 comments
Open

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

h-sh-h opened this issue Jun 14, 2024 · 0 comments

Comments

@h-sh-h
Copy link

h-sh-h commented Jun 14, 2024

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;
  1. 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__)
  1. Since RCLCPP needs node to get logger from, the node should be defined as extern variable in ros_compat.h
extern std::string __node_name_;
extern rclcpp::Node::SharedPtr node; // This line is added
  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant