# tf2.BufferCore::lookupTransform：找不到从 'base_link' 到 'map' 的变换，错误：'map' 作为 lookupTransform 参数 target_frame 传递，但不存在

- **ID:** `ros2/tf2-buffer-core-transform-timeout`
- **领域:** ros2
- **类别:** runtime_error
- **错误码:** `TF2_LOOKUP_001`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

tf2 缓冲区没有请求的变换，原因是缺少广播器、帧名称错误或变换尚未发布（例如 robot_state_publisher 未运行或 static_transform_publisher 配置错误）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Humble | active | — | — |
| Iron | active | — | — |
| Jazzy | active | — | — |
| Rolling | active | — | — |

## 解决方案

1. ```
   Ensure the static_transform_publisher for the 'map' to 'odom' frame is running in the launch file: <node pkg="tf2_ros" exec="static_transform_publisher" args="0 0 0 0 0 0 map odom"/>
   ```
2. ```
   Check the frame names in the URDF and ensure robot_state_publisher publishes the correct transforms: ros2 run robot_state_publisher robot_state_publisher --ros-args -p robot_description:="$(xacro my_robot.urdf.xacro)"
   ```
3. ```
   Add a transform listener with a retry loop and a timeout of 2 seconds, logging the available frames for debugging: try: transform = tf_buffer.lookup_transform('map', 'base_link', rclpy.time.Time(), timeout=rclpy.duration.Duration(seconds=2.0)); except tf2.LookupException: self.get_logger().info('Available frames: ' + str(tf_buffer.all_frames_as_string()))
   ```

## 无效尝试

- **Set the lookup timeout to a very high value (e.g., 10 seconds)** — Timeout doesn't create the missing transform; it only delays the error. (95% 失败率)
- **Change the target_frame to 'odom' in all lookup calls** — This may work temporarily but breaks applications that need the 'map' frame for global planning. (80% 失败率)
- **Hardcode the transform as a static transform in the code** — Static transforms don't update with robot movement; the robot will get stuck or collide. (90% 失败率)
