# [nav2_costmap_2d] 滚动窗口代价地图原点偏移不匹配：预期 (x, y) 但得到 (x', y')

- **ID:** `ros2/nav2-costmap-rolling-window-offset`
- **领域:** ros2
- **类别:** config_error
- **错误码:** `NAV2_COSTMAP_ROLLING_001`
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

滚动窗口代价地图的原点在机器人移动时未正确更新，通常是由于 'rolling_window' 参数设置错误或代价地图帧与机器人里程计帧不匹配。

## 版本兼容性

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

## 解决方案

1. ```
   Ensure the 'global_frame' parameter in the costmap config matches the frame used by the robot's odometry (e.g., 'odom' or 'map'). Example: global_frame: odom; rolling_window: true; width: 10.0; height: 10.0;
   ```
2. ```
   Add a static transform publisher in the launch file to publish the transform from 'odom' to 'map' if they differ: <node pkg="tf2_ros" exec="static_transform_publisher" args="0 0 0 0 0 0 map odom"/>
   ```
3. ```
   Update the costmap parameters to set 'always_send_full_costmap: true' in the nav2_params.yaml to force full costmap updates, reducing drift.
   ```

## 无效尝试

- **Set the costmap size to a very large value (e.g., 100x100 meters)** — Large costmaps consume excessive memory and slow down planning; the origin offset still drifts. (80% 失败率)
- **Disable the rolling window and use a static costmap** — This changes the navigation behavior (no map following), which may not be acceptable for dynamic environments. (70% 失败率)
- **Manually set the costmap origin in the parameter file to a fixed value** — The origin is dynamically updated by the robot's pose; a fixed value will cause the costmap to become misaligned. (95% 失败率)
