Ask Your Question
1

createTimer() replacement in eloquent

asked 2020-05-27 19:51:23 -0500

KenYN gravatar image

updated 2020-05-27 20:16:11 -0500

In ROS1 we can simply do:

ros::Timer timer = nh.createTimer(ros::Duration(0.1), timerCallback);

This gives us a tick approximately every 100 ms of ROS time. In ROS2, particularly in Eloquent, there is no similar API as far as I can determine, and the only references I find mention Ardent APIs that have been removed. However, for this code:

rclcpp::Clock ros_clock(RCL_ROS_TIME);

This returns a ROS time-based clock, but I cannot see an obvious way to go from there to a timer that ticks every simulated 100 milliseconds. rclcpp::create_wall_timer() exists, but not the more generic rclcpp::create_timer(rclccp::Clock, duration, callback). How can I replicate the ROS1 behaviour in ROS2?


EDIT: Studying the API, the best I can find is something like this:

rclcpp::Clock ros_clock(RCL_ROS_TIME);
rclcpp::timer::GenericTimer<??typeof my_callback??, ros_clock> ros_timer(10ms, std::bind(&my_callback, this));
n.get_node_timers_interface()->add_timer(ros_timer, n.get_callback_groups());

This seems a very long-winded way to do this, though!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-06-10 02:42:10 -0500

Mbuijs gravatar image

Have you found Node::create_wall_timer?

Docs: http://docs.ros2.org/eloquent/api/rcl...

edit flag offensive delete link more

Comments

I did eventually; I'd been looking at the beta3 documentation instead of eloquent...

KenYN gravatar image KenYN  ( 2020-06-10 07:20:04 -0500 )edit
1

It's quite annoying that in search results the old documentation typically appears higher than eloquent (and now foxy), so now I usually add eloquent in front of my searches in an attempt to find the right version straight away.

Mbuijs gravatar image Mbuijs  ( 2020-06-11 01:32:58 -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

2 followers

Stats

Asked: 2020-05-27 19:51:23 -0500

Seen: 188 times

Last updated: Jun 10 '20