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);

相关推荐
洛水水5 小时前
【力扣100题】18.随机链表的复制
算法·leetcode·链表
Raink老师5 小时前
【AI面试临阵磨枪-48】GraphRAG、多模态 RAG、自适应 RAG 原理
人工智能·ai 面试题
波动几何5 小时前
模式驱动的学术选题方法论——四种AI模式处理能力的系统建构与论证
人工智能
南宫萧幕6 小时前
规则基 EMS 仿真实战:SOC 区间划分与 Simulink 闭环建模全解
算法·matlab·控制
飞哥数智坊6 小时前
我为我的龙虾斩分身:OpenClaw 多智能体实操
人工智能·agent
七牛开发者6 小时前
HTML is the new Markdown:来自 Claude Code 团队的实践
前端·人工智能·语言模型·html
飞哥数智坊6 小时前
在二线城市做AI社群,我的五一节后到底有多疯狂?
人工智能
多加点辣也没关系6 小时前
数据结构与算法|第二十三章:高级数据结构
数据结构·算法
视***间6 小时前
智启边缘,魔盒藏锋——视程空间Pandora系列魔盒,解锁边缘计算普惠新范式
人工智能·区块链·边缘计算·ai算力·视程空间
蛐蛐蛐6 小时前
昇腾910B4上安装新版本CANN的正确流程
人工智能·python·昇腾