ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I was struggling with exactly this also this morning and I found the following to work (assuming this is a rclcpp::Node):

auto& clk = *this->get_clock();
RCLCPP_INFO_THROTTLE(this->get_logger(),
                     clk,
                     5000,
                     "Hello world");

I was struggling with exactly this also this morning and I found the following to work (assuming this is a rclcpp::Node):

auto& clk = *this->get_clock();
RCLCPP_INFO_THROTTLE(this->get_logger(),
                     clk,
                     5000,
                     "Hello world");

clock argument

The source of RCLCPP_INFO_THROTTLE: http://docs.ros2.org/eloquent/api/rclcpp/logging_8hpp.html#a53cee4093804b13f31cb1516087400eb

You can see here that the clock argument is used in a lambda capture and then inside the lambda. Due to this, the macro evaluation will result in this->get_clock(), which is not valid. As a workaround, I store the actual Clock (not the Clock::SharedPtr) in the clk variable and pass that along.

duration argument

2 levels deeper you can find the usage of duration: http://docs.ros2.org/eloquent/api/rcutils/logging__macros_8h.html#ae33a3cea9859fb46168396b09a7514b5

Here you can see that the duration is converted to the standard rcutils_duration_value_t using the macro RCUTILS_MS_TO_NS, which is a multiplication by 1000LL * 1000LL. So 5000 means 5000 milliseconds.