跳转到主要内容博客列表
KOLIKO / 20262026年06月16日 / 4 min read

Moveit \&\& 真实机械臂

本文介绍如何配置MoveIt以连接真实机械臂。通过配置controller list、新建yaml文件、启动控制器管理器,实现了MoveIt对机械臂的轨迹控制。重点解析了follow_joint_trajectory的action消息结构,并提供了命令行验证方法。

2026年06月16日4 min read
ROSMoveIt机械臂机器人

Moveit && 真实机械臂

https://blog.csdn.net/qq_27865227/article/details/119650972

参考教程

前期知识

follow_joint_trajectory的格式

我们可以在命令行输入这个订阅这个话题,然后在rviz里面运行之后可以看到他的一个格式

1rostopic echo /arm_7dof/arm_controller/follow_joint_trajectory/goal
1header: 2 seq: 1 3 stamp: 4 secs: 177 5 nsecs: 281000000 6 frame_id: '' 7goal_id: 8 stamp: 9 secs: 177 10 nsecs: 281000000 11 id: "/move_group-2-177.281000000" 12goal: 13 trajectory: 14 header: 15 seq: 0 16 stamp: 17 secs: 0 18 nsecs: 0 19 frame_id: "world" 20 joint_names: 21 - joint1 22 - joint2 23 - joint3 24 - joint4 25 - joint5 26 - joint6 27 - joint7 28 points: 29 - 30 positions: [0.015166845039457755, -0.27425455778553953, -3.082853418324648, 0.8833036868286568, 3.048520446767654, 0.877150518378369, -0.21636067809133408] 31 velocities: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 32 accelerations: [-0.09891003377306339, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 33 effort: [] 34 time_from_start: 35 secs: 0 36 nsecs: 0 37 - 38 positions: [0.005273659482528944, -0.2689186290136684, -3.0799010620287497, 0.7860407613195349, 3.0540116465554057, 0.7898463768061345, -0.22007649079977906] 39 velocities: [-0.03804472517268003, 0.020519573043351676, 0.011353429412897673, -0.37402930018772496, 0.021116675270179592, -0.3357323132614436, -0.014289338097669973] 40 accelerations: [-0.10102152820530179, 0.0544863609225982, 0.030147169797029708, -0.9931734643113422, 0.05607186795872897, -0.8914820963913125, -0.037942993808389024] 41 effort: [] 42 time_from_start: 43 secs: 0 44 nsecs: 447262926 45 - 46 positions: [-0.004619526074399867, -0.2635827002417973, -3.076948705732851, 0.6887778358104131, 3.0595028463431575, 0.7025422352338999, -0.22379230350822404] 47 velocities: [-0.053764776444935575, 0.028998244892397485, 0.01604465774157217, -0.5285779202550125, 0.02984206930154785, -0.47445664769329754, -0.020193681643914742] 48 accelerations: [0.0022311488119770057, -0.0012033789391324974, -0.0006658266141095222, 0.02193510466879971, -0.0012383962488522686, 0.019689161860829918, 0.0008380042062550468] 49 effort: [] 50 time_from_start: 51 secs: 0 52 nsecs: 630571718 53 - 54 positions: [-0.014512711631328678, -0.25824677146992614, -3.0739963494369524, 0.5915149103012912, 3.064994046130909, 0.6152380936616655, -0.22750811621666905] 55 velocities: [-0.03783944680602874, 0.02040885534412802, 0.01129216958160195, -0.37201114593706947, 0.021002735779515936, -0.33392079850912065, -0.014212236949694765] 56 accelerations: [0.09949763857662218, -0.053664445022201177, -0.02969240574619919, 0.9781916404503127, -0.055226035000529056, 0.8780342665576202, 0.037370631305338166] 57 effort: [] 58 time_from_start: 59 secs: 0 60 nsecs: 815285651 61 - 62 positions: [-0.024405897188257492, -0.252910842698055, -3.0710439931410543, 0.49425198479216936, 3.0704852459186607, 0.527933952089431, -0.23122392892511404] 63 velocities: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 64 accelerations: [0.09891003377306341, -0.05334751804658081, -0.02951705082827317, 0.9724147183549502, -0.05489988571787972, 0.8728488454752797, 0.037149930967307745] 65 effort: [] 66 time_from_start: 67 secs: 1 68 nsecs: 262548576 69 path_tolerance: [] 70 goal_tolerance: [] 71 goal_time_tolerance: 72 secs: 0 73 nsecs: 0 74--- 75

知道他的格式对后面使用有很大的帮助

可以看到他是有几个路径点组成的轨迹,并不是很多的路径点,只有几个关键节点

使用

1rosmsg show control_msgs/FollowJointTrajectoryActionResult

也可以看到他的action消息结构

Move_group结构

Image

Image

MoveIt!控制接口配置

controller_list配置

先在moveit_7dof/config里面新建一个 **arm_7dof_controller.yaml **文件,内容可以和simple_controller一样,用来配置moveit的控制器。

1controller_list: 2 - name: arm_7dof/arm_controller 3 action_ns: follow_joint_trajectory 4 type: FollowJointTrajectory 5 default: True 6 joints: 7 - joint1 8 - joint2 9 - joint3 10 - joint4 11 - joint5 12 - joint6 13 - joint7

启动控制器

在moveit包的/launch文件里面新建 arm_7dof_moveit_controller_manager.launch.xml

1<launch> 2 <!-- Define the MoveIt controller manager plugin to use for trajectory execution --> 3 <arg name="moveit_controller_manager" default="moveit_simple_controller_manager/MoveItSimpleControllerManager" /> 4 <param name="moveit_controller_manager" value="$(arg moveit_controller_manager)" /> 5 6 <!-- load controller list --> 7 <arg name="use_controller_manager" default="true" /> 8 <param name="use_controller_manager" value="$(arg use_controller_manager)" /> 9 10 <!-- Load controller list to the parameter server --> 11 <rosparam file="$(find moveit_7dof)/config/arm_7dof_moveit_controllers.yaml" /> 12</launch>

启动控制器管理者

这里(argmoveit_controller_manager)_moveit_controller_manager.launch.xml,需要和上面启动控制器的文件名做匹配,可以直接修改,也可以通过传参方式实现(见下)

1<include file="$(dirname)/$(argmoveit_controller_manager)_moveit_controller_manager.launch.xml" pass_all_args="true" />

moveit启动 fake_execution_type 启动参数修改

可以通过传参的方式实现

1<!-- Launch MoveIt --> 2 <include file="$(dirname)/demo.launch" pass_all_args="true"> 3 <arg name="moveit_controller_manager" value="arm_7dof"/> 4 <arg name="fake_execution_type" value="false"/> 5 </include>

订阅话题名配置

这个可以加在demo里面,去做一个分类

1<group if="$(eval arg('moveit_controller_manager') == 'arm_7dof')"> 2 <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher"> 3 <param name="/use_gui" value="false"/> 4 <rosparam param="/source_list">[/arm_7dof/joint_states]</rosparam> 5 </node> 6 </group>

[IMG_0846.MOV]