ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How should I create a timer in ros2?

asked 2020-09-28 12:50:31 -0500

updated 2020-09-30 11:56:24 -0500

I am looking for the create_timer function in ros2 but I only find the rclcpp::Node::create_wall_timer.

From my understanding there should be some abstract create_timer function (instead of wall timer) to work optionally with the simulated time. Where is this function?

If that function is not there in ros2, what would be the solution to have some abstract timer that adapts to the wall or to the simulated time?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-09-29 13:41:50 -0500

sloretz gravatar image

There is an rclcpp::create_timer() free function

The trick to a timer that uses simulated time is to pass a clock that uses simulated time to the rclcpp::create_timer() function. The default clock on a node is a ROS clock - meaning it will use simulated time if simulated time is active.

You might also be interested in

edit flag offensive delete link more


Correct. Thank you. Does anyone know why create_timer is a free function? and Node::create_wall_timer is a member function?

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2020-09-30 13:02:54 -0500 )edit

The free function has an advantage in that the same code can be used with both LifecycleNode and Node. There's some talk of making all functions free functions in

sloretz gravatar image sloretz  ( 2020-09-30 13:16:43 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2020-09-28 12:50:31 -0500

Seen: 7,524 times

Last updated: Sep 30 '20