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

Get valid frames from `tf2_ros.Buffer` based on `cache_time`

asked 2021-02-15 01:36:29 -0600

kunaltyagi gravatar image

tf2_ros.Buffer offers a cache_time argument in both C++ and Python implementations.

However, on calling the buffer.all_frames_as_yaml(), the frames including those outside the cache time are included. Is there a way to clear the cache periodically or to filter the "stale" frames without having to read the YAML/string for the field: most_recent_transform and then convert it into a number (which also results in a loss of precision)?

PS: My understanding of cache_time might be wrong, so I'll rephrase my question for clarity: How do I

  • Get only frames with a TF within the cache_time provided to the tf2_ros.Buffer OR
  • Clear the expired cache of tf2_ros.Buffer in Python (there's a clear function, but like in C++, it clears the entire cache)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-02-16 04:10:56 -0600

tfoote gravatar image

There is not a method to clear the "expired" data. Due to there not being a clear definition of "now" at the library level the data is not evaluated compared to "now" but is compared to the lastest information heard on that topic. The cache expiration is only evaluated on insertion into that specific transform's history. This means that you'll have cache_time amount of history for each frame.

If you want to get the list of only frameids that have an updated data within the last X seconds I think that parsing the yaml as you're saying is likely going to be your best approach. Worrying about the precision for this seems to be a distraction compared to any useful cache duration.

A new clear method could be added to the core, however you're getting into more of the internal buffer and cache implementation and away from the specifically simple public interface for running queries.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-02-15 01:36:29 -0600

Seen: 564 times

Last updated: Feb 16 '21