Robotics StackExchange | Archived questions

What is setCreateTimerInterface in the TF2 library for?

I'm currently working on setting up a TransformListener in ROS2, using the TF2 API. I notice that when creating the TF buffer object, existing ROS2 libraries that use this library also call the setCreateTimerInterface function.

This is the typical code used:

tf_buffer_ = std::make_shared<tf2_ros::Buffer>(rclcpp_node_->get_clock());
auto timer_interface = std::make_shared<tf2_ros::CreateTimerROS>(
    rclcpp_node_->get_node_base_interface(),
    rclcpp_node_->get_node_timers_interface());
tf_buffer_->setCreateTimerInterface(timer_interface);

And here are two examples of this in use:

However the ROS2 Foxy API doesn't describe this function at all (see bottom of this page), if it is necessary, or why the TF2 buffer needs this in ROS2 when it wasn't present in ROS1. It's also not explained on the ROS2 TF2 tutorial page.

Is someone with better knowledge of this source code able to explain what the timer interface is for and how it works?

Asked by M@t on 2021-02-23 22:13:39 UTC

Comments

Answers

You can see where it's useful slightly above:

https://github.com/ros2/geometry2/blob/7fb77c597e22344f90f5661f0871beedb666b73a/tf2_ros/include/tf2_ros/buffer.h#L217

or https://docs.ros2.org/foxy/api/tf2_ros/classtf2__ros_1_1Buffer.html#ad14c12577a86a981cb8853b571809551

This timer interface allows the buffer to register for regular callbacks from the node to test for the availability of the transform. This allows the buffer to fulfill it's asynchronous query without requiring starting its own thread(s).

Asked by tfoote on 2021-02-23 22:37:41 UTC

Comments

Ah I see. The Rviz node also shows an option for setting the buffer to use it's own dedicated thread. Does setting this to true simply make the transform lookup faster?

Asked by M@t on 2021-02-24 22:23:46 UTC

No that's independently spinning a thread to subscribe to incoming topics which does not cross over to the timer interface.

Asked by tfoote on 2021-02-25 17:05:29 UTC