Ask Your Question

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

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

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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 28 times

Last updated: Feb 16