# tf2: Transform cache timed out while waiting for transform from 'base_link' to 'odom'

- **ID:** `ros2/tf2-timeout-on-startup`
- **Domain:** ros2
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

The transform broadcaster (e.g., robot_state_publisher or a custom node) is not publishing the required transform frequently enough, or there is a startup delay where the transform is not yet available, causing tf2's cache lookup to timeout after the default duration (e.g., 1 second).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| ROS2 Humble | active | — | — |
| ROS2 Iron | active | — | — |
| ROS2 Rolling | active | — | — |

## Workarounds

1. **Ensure the transform broadcaster is publishing at a high enough rate (e.g., 50 Hz) and that the node's timer for publishing is set correctly. For robot_state_publisher, check that the URDF is loaded and the joint states are being published.** (90% success)
   ```
   Ensure the transform broadcaster is publishing at a high enough rate (e.g., 50 Hz) and that the node's timer for publishing is set correctly. For robot_state_publisher, check that the URDF is loaded and the joint states are being published.
   ```
2. **Add a retry loop with exponential backoff in the subscriber node: 'while not tf_buffer.can_transform('odom', 'base_link', rclpy.time.Time(), timeout=rclpy.duration.Duration(seconds=0.1)): rclpy.spin_once(node)'** (85% success)
   ```
   Add a retry loop with exponential backoff in the subscriber node: 'while not tf_buffer.can_transform('odom', 'base_link', rclpy.time.Time(), timeout=rclpy.duration.Duration(seconds=0.1)): rclpy.spin_once(node)'
   ```
3. **If using a static transform, publish it with a static_transform_publisher in the launch file to ensure it's always available.** (95% success)
   ```
   If using a static transform, publish it with a static_transform_publisher in the launch file to ensure it's always available.
   ```

## Dead Ends

- **Increasing the tf2 buffer timeout to a very large value (e.g., 10 seconds) in the node's code** — This masks the problem but does not fix the underlying publishing issue; the transform may never arrive if the broadcaster is not running. (70% fail)
- **Adding a sleep(5) at the beginning of the node's main function to wait for transforms** — Sleeping does not guarantee the transform will be available; it only delays the error, and the transform may still timeout. (80% fail)
