# MoveIt2获取状态报错timestamp为0，需修正节点初始化与Executor

> 原文链接：https://robotics.hellobike.com/pitfalls/2024-06-07-robotics-se-111134
> 频道：pitfalls | 更新日期：2024-06-07 | 标签：auto, stackexchange, moveit
> 核心摘要：MoveIt2无法获取关节状态且时间戳为0，系MoveGroupInterface初始化错误所致，通过继承rclcpp::Node并独立线程运行Executor解决。

# MoveIt2获取状态报错timestamp为0，需修正节点初始化与Executor

::: v-pre
> 本文由 AI 根据公开内容整理，可能有误，请以原文为准：[MoveIt2 Didn't receive robot state (joint angles) with recent timestamp within 1.000000 seconds](https://robotics.stackexchange.com/questions/111134/moveit2-didnt-receive-robot-state-joint-angles-with-recent-timestamp-within-1)（Robotics Stack Exchange #111134）

**状态**：已解决

## 问题

调用 `getCurrentState()` 或 `getCurrentPose()` 时报错 "Didn't receive robot state (joint angles) with recent timestamp within 1.000000 seconds"，提示请求时间为3533s但最新状态时间为0.000000。

## 环境

ROS2 MoveIt2, rclcpp, MoveGroupInterface, MultiThreadedExecutor/SingleThreadedExecutor

## 解决办法

1. 修改类定义使 `m2Iface` 直接继承 `rclcpp::Node`，避免在类内部额外创建子节点 `node_`，确保 MoveIt 接口绑定到主节点上下文。
2. 将执行器改为 `SingleThreadedExecutor` 并在独立 `std::thread` 中调用 `spin()`，或在主函数中使用 `rclcpp::spin(move_group_node)` 替代手动多线程管理。
3. 使用 `MoveGroupInterface::Options(groupName, "robot_description", moveNs)` 显式指定参数进行初始化，并紧接着调用 `startStateMonitor()` 启动状态监听。
4. 确保 `node_options` 开启 `automatically_declare_parameters_from_overrides(true)` 以正确加载配置参数。

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

## 原始参考来源 (Sources)

- [Robotics Stack Exchange #111134：MoveIt2 Didn't receive robot state (joint angles) with recent timestamp within 1.000000 seconds](https://robotics.stackexchange.com/questions/111134/moveit2-didnt-receive-robot-state-joint-angles-with-recent-timestamp-within-1)