# [nav2_planner] 初始化代价地图层失败：'obstacle_layer' - 未找到插件或加载失败

- **ID:** `ros2/nav2-planner-failed-to-initialize-costmap-layer`
- **领域:** ros2
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 84%

## 根因

nav2代价地图层插件（如obstacle_layer）未在pluginlib系统中注册，原因可能是包未构建、缺少插件描述XML，或代价地图配置中插件名称拼写错误。

## 版本兼容性

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

## 解决方案

1. ```
   Verify the plugin is registered: run 'ros2 pkg list | grep nav2_costmap_2d' and check the plugin description file in the package share directory: cat $(ros2 pkg prefix nav2_costmap_2d)/share/nav2_costmap_2d/plugins.xml. Ensure the plugin name matches your config.
   ```
2. ```
   If the plugin is from a custom package, ensure the plugin description XML is correctly set up. In the package's CMakeLists.txt: pluginlib_export_plugin_description_file(nav2_costmap_2d plugins.xml). Then rebuild: colcon build --packages-select my_costmap_plugins
   ```
3. ```
   In the costmap configuration YAML, use the exact plugin name from the plugins.xml. For example: plugins: [obstacle_layer] and obstacle_layer: {plugin: 'nav2_costmap_2d::ObstacleLayer', ...}. Restart the planner node.
   ```

## 无效尝试

- **** — The plugin name must match exactly what is registered in the plugin description XML. A typo or missing package will cause the same error. (90% 失败率)
- **** — If the plugin is from a custom package, apt-get won't help. You need to build your custom package with colcon and source the workspace. (85% 失败率)
