0
$\begingroup$

Rosanswers logo

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!


Originally posted by KenYN on ROS Answers with karma: 541 on 2020-05-27

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Have you found Node::create_wall_timer?

Docs: http://docs.ros2.org/eloquent/api/rclcpp/classrclcpp_1_1Node.html#a72bcd0268e23fafda8766b01f1ce624f


Originally posted by Mbuijs with karma: 247 on 2020-06-10

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by KenYN on 2020-06-10:
I did eventually; I'd been looking at the beta3 documentation instead of eloquent...

Comment by Mbuijs on 2020-06-11:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.