tf2.BufferCore::lookupTransform: 找不到从 frame_a 到 frame_b 的变换,错误:传递给 lookupTransform 参数 target_frame 的 'frame_b' 不存在。缓冲区大小已超出。
tf2.BufferCore::lookupTransform: Can't find transform from frame_a to frame_b, error: 'frame_b' passed to lookupTransform argument target_frame does not exist. Buffer size exceeded.
ID: ros2/tf2-buffer-size-exceeded
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ROS2 Foxy | active | — | — | — |
| ROS2 Galactic | active | — | — | — |
| ROS2 Humble | active | — | — | — |
| tf2 2.5.x | active | — | — | — |
根因分析
tf2 缓冲区大小有限(默认 10 秒),较旧的变换会被移除;如果变换查找需要早于缓冲区窗口的数据,则会失败。
English
The tf2 buffer has a limited size (default 10 seconds) and older transforms are removed; if a transform lookup requires data older than the buffer window, it fails.
官方文档
https://docs.ros.org/en/humble/Tutorials/Intermediate/Tf2/Tf2-Main.html解决方案
-
在节点中增加 tf2 缓冲区大小:'tf_buffer = tf2_ros.Buffer(cache_time=rclpy.duration.Duration(seconds=30.0))'
-
确保变换发布者以足够高的速率(例如 50 Hz)连续运行,并检查是否有丢弃的消息:'ros2 topic hz /tf'
无效尝试
常见但无效的做法:
-
60% 失败
This may cause memory issues and does not address the root cause of missing transforms; it only delays the problem.
-
90% 失败
The transform may never become available if the publisher has stopped or the frame is no longer being broadcast.
-
85% 失败
If sim_time is enabled but no /clock is published, timestamps may be zero, causing all lookups to fail.