# [nav2_costmap_2d] 初始化图层 'obstacle_layer' 失败：找不到话题 '/scan'

- **ID:** `ros2/costmap-layer-initialization-failure-no-topic`
- **领域:** ros2
- **类别:** runtime_error
- **错误码:** `NAV2-5001`
- **验证级别:** ai_generated
- **修复率:** 91%

## 根因

Nav2 代价地图中的障碍物图层无法订阅其输入话题（例如 '/scan'），因为该话题的发布者未运行，或者在代价地图参数中话题名称配置错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| ROS2 Humble Hawksbill | active | — | — |
| ROS2 Iron Irwini | active | — | — |
| ROS2 Jazzy Jalisco | active | — | — |

## 解决方案

1. ```
   Ensure the LiDAR or sensor node is running and publishing to the correct topic. Use `ros2 topic list` and `ros2 topic echo /scan` to verify. If the topic name differs (e.g., '/scan_raw'), update the costmap YAML config to match.
   ```
2. ```
   If the sensor publishes on a different topic (e.g., '/lidar/points'), set the `topic` parameter in the obstacle layer configuration to that topic, and ensure the message type matches (e.g., LaserScan or PointCloud2).
   ```

## 无效尝试

- **** — Setting the topic to an empty string or a random topic name may avoid the error but will cause the costmap to have no obstacle data, making the robot blind to obstacles. (80% 失败率)
- **** — Disabling the obstacle layer entirely in the costmap configuration removes the error but also removes obstacle avoidance, which is critical for navigation. (90% 失败率)
