Robotics StackExchange | Archived questions

How do I generate logging messages from inside a ros2_control hardware interface?

I'm working on a custom hardware interface plugin for ros2_control and I'm not sure how to generate log messages from inside the plugin. I'd like to log hardware issues in general and it would also help with debugging & development. How do I get a logger object from inside the hardware interface so I can generate log messages?

My system is ROS2 Humble running on Ubuntu 22.04 LTS

Asked by PierceNichols on 2023-05-26 09:56:49 UTC

Comments

Answers

Figured out the answer on my own... I need to call the function rclcpp::get_logger() rather than the get_logger() method of rclcpp::Node.

For a test I added the following lines to the on_init() method:

rclcpp::Logger loger = rclcpp::get_logger("test_logger");
RCLCPP_INFO(logger, "Logging test");

Which resulted in the output:

[ros2_control_node-1] [INFO] [1685153874.083490048] [test_logger]: Logging test

And that's what I needed. Hopefully this will help someone else who doesn't read the code quite closely enough.

Asked by PierceNichols on 2023-05-26 21:30:56 UTC

Comments