# C++节点中实现MoveIt 2碰撞检测时报错无法获取规划场景

> 原文链接：https://robotics.hellobike.com/pitfalls/2025-03-07-robotics-se-114898
> 频道：pitfalls | 更新日期：2025-03-07 | 标签：auto, stackexchange, moveit
> 核心摘要：用户在C++节点中实现MoveIt 2碰撞检测时出错，原因是构造函数中调用了shared_from_this()，需构造完成后单独调用初始化方法。

# C++节点中实现MoveIt 2碰撞检测时报错无法获取规划场景

::: v-pre
> 本文由 AI 根据公开内容整理，可能有误，请以原文为准：[Error with MoveIt 2 collision detection with C++ Node](https://robotics.stackexchange.com/questions/114898/error-with-moveit-2-collision-detection-with-c-node)（Robotics Stack Exchange #114898）

**状态**：有绕过办法

## 问题

用户尝试在C++节点中使用MoveIt 2实现简单碰撞检测，运行时出现无法获取规划场景的错误。

## 环境

MoveIt 2

## 解决办法

1. 不在节点构造函数中调用shared_from_this()初始化PlanningSceneMonitor。
2. 新增独立的初始化函数，在构造函数执行完成后调用，完成各类数据结构的初始化操作。

原问题作者：Icon45；采纳答案作者：Mike Ferguson。原内容依 CC BY-SA 4.0 授权，本页摘要同样依 CC BY-SA 4.0 授权。
:::

## 原始参考来源 (Sources)

- [Robotics Stack Exchange #114898：Error with MoveIt 2 collision detection with C++ Node](https://robotics.stackexchange.com/questions/114898/error-with-moveit-2-collision-detection-with-c-node)