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

How should I create a timer in ros2?

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

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

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
2

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

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

Comments

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 -0600 )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 https://github.com/ros2/rclcpp/issues...

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

Question Tools

1 follower

Stats

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

Seen: 16,390 times

Last updated: Sep 30 '20