moveitcpp 没办法执行的问题

moveit_cpp::PlanningComponent 默认只做规划,不执行轨迹 ------ 因为它没有对接控制器 。要让机械臂真的动起来 ,必须使用 TrajectoryExecutionComponent 轨迹执行组件。

我会给你最简可运行修复版代码 + 原理一句话说明


🔥 核心问题(一句话)

planning_components->execute() 不是执行到真实机械臂 / 控制器,它只是在内部模拟播放,不会发指令给硬件。

真正执行必须用:

cpp

运行

复制代码
moveit_cpp::TrajectoryExecutionComponent execution_component(PLANNING_GROUP, moveit_cpp_ptr);
execution_component.execute(plan_solution.trajectory);

✅ 修复后完整可执行代码(关键部分)

我只改执行部分,其他不变,你直接替换即可。

1. 增加头文件

cpp

运行

复制代码
#include <moveit/moveit_cpp/trajectory_execution_component.h>  // <-- 加这个

2. 声明执行器(在 planning_components 下面加)

cpp

运行

复制代码
auto planning_components = std::make_shared<moveit_cpp::PlanningComponent>(PLANNING_GROUP, moveit_cpp_ptr);
auto execution_components = std::make_shared<moveit_cpp::TrajectoryExecutionComponent>(PLANNING_GROUP, moveit_cpp_ptr); // <-- 加这行

3. 把所有

cpp

运行

复制代码
planning_components->execute();

替换成:

cpp

运行

复制代码
if (!execution_components->execute(plan_solution1.trajectory))
{
  RCLCPP_ERROR(LOGGER, "Execution failed!");
}

✔ 示例(Plan #1 修复后)

cpp

运行

复制代码
if (plan_solution1)
{
  visual_tools.publishAxisLabeled(robot_start_state->getGlobalLinkTransform("panda_link8"), "start_pose");
  visual_tools.publishAxisLabeled(target_pose1.pose, "target_pose");
  visual_tools.publishText(text_pose, "setStartStateToCurrentState", rvt::WHITE, rvt::XLARGE);
  visual_tools.publishTrajectoryLine(plan_solution1.trajectory, joint_model_group_ptr);
  visual_tools.trigger();

  // ---------------- 真正执行 ----------------
  execution_components->execute(plan_solution1.trajectory);
}

所有 5 个 plan 都这样改,机械臂就会真的动了。


🧠 为什么 moveit_cpp 要分两个组件?

  • PlanningComponent :只负责算路径
  • TrajectoryExecutionComponent :负责把路径发给控制器

MoveItCpp 架构就是这样设计的:规划 / 执行分离


🚀 最快可运行修复总结

  1. 加头文件: cpp

    运行

    复制代码
    #include <moveit/moveit_cpp/trajectory_execution_component.h>
  2. 创建执行器: cpp

    运行

    复制代码
    auto execution_components = std::make_shared<moveit_cpp::TrajectoryExecutionComponent>(PLANNING_GROUP, moveit_cpp_ptr);
  3. 执行轨迹: cpp

    运行

    复制代码
    execution_components->execute(plan_solution1.trajectory);

相关推荐
智者知已应修善业2 小时前
【C++非递归剪枝问题凑钱方案数】2024-7-18
c语言·c++·经验分享·笔记·算法·剪枝
郝学胜-神的一滴2 小时前
Pytorch张量核心运算精讲:从类型转换到数值操作全解析
开发语言·人工智能·pytorch·python·深度学习·程序人生·机器学习
Yolo_TvT2 小时前
C++:缺省参数
开发语言·c++·算法
云烟成雨TD2 小时前
Spring AI 1.x 系列【18】深入了解更多的工具规范底层组件
java·人工智能·spring
AAA小肥杨2 小时前
OpenClaw 数据、设置和内存备份指南
人工智能·大模型·openclaw
进击的小头2 小时前
第19篇:多个PI控制器串联控制系统设计与参数整定调试实战
python·算法
承渊政道2 小时前
【优选算法】(实战领略前缀和的真谛)
开发语言·数据结构·c++·笔记·学习·算法
阿泽·黑核2 小时前
Easy Vibe Coding 学习心得(六):RAG 入门——让 AI 拥有企业级知识库
人工智能·vibe coding·easy vibe
Jul1en_2 小时前
Java 集合判空方法对比
java·spring boot·算法·spring