Robotics StackExchange | Archived questions

How can I create a timer in ros2?

Hi, I want to publish ROS messages with a non-periodic frequency. I see that rclcpp::createwalltimer() uses a constant period for calling the callback function, which is not what I want. Is there a way to do this? Thanks in advance!

Asked by Ima on 2022-11-10 09:06:38 UTC

Comments

Why would you do that? Can you please explain your use case in the question?

Asked by ravijoshi on 2022-11-11 04:27:37 UTC

Answers

Every time when you call

publisher_->publish(message);

A message is published.

You could write a while true loop with thead sleep to get you a periodic behavior.

Asked by duck-development on 2022-11-11 15:10:54 UTC

Comments

Thanks for the reply!

Asked by Ima on 2022-11-18 04:42:51 UTC