Ask Your Question


asked 2021-02-10 13:41:09 -0500

lexi gravatar image

I'm getting this error:

error: cannot capture ‘rclcpp::Clock(RCL_SYSTEM_TIME)’ by reference

from this line:

RCLCPP_DEBUG_THROTTLE(node_->get_logger(), rclcpp::Clock(), 1, "EIPInterface::receiveLoop - Average Loop Time: %f (FPS: %.2f)", avg_period, 1 / avg_period);
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2021-02-10 13:40:44 -0500

lexi gravatar image

The trick I needed was to instantiate the clock outside of the macro call like this:

rclcpp::Clock clock;
RCLCPP_DEBUG_THROTTLE(node_->get_logger(), clock, 1, "EIPInterface::receiveLoop - Average Loop Time: %f (FPS: %.2f)", avg_period, 1 / avg_period);

The reason is that the macro just replaces [&clock] with the string you place in for the clock. So in my case after the preprocessor processes the logging macro it was generating code like this:


Which is invalid C++ syntax.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2021-02-10 13:34:42 -0500

Seen: 201 times

Last updated: Feb 10 '21