当前位置:   article > 正文

ros gazebo机械臂仿真,手动控制与MoveIt自动控制_ros 工业机器人 ros机械臂moveit!

ros 工业机器人 ros机械臂moveit!

本文总结归纳古月居胡春旭ros机械臂教程,给出了一些error的解决方法,补充了通过python运行moveit。十分建议去看github huchunxu源代码的repository。

创建机械臂的xacro模型

首先创建一个工作空间,在工作空间中创建arm_description功能包。功能包中创建一个urdf文件夹,放入机械臂模型文件arm.xacro

  1. <?xml version="1.0"?>
  2. <robot name="arm" xmlns:xacro="http://ros.org/wiki/xacro">
  3. <!-- Defining the colors used in this robot -->
  4. <material name="Black">
  5. <color rgba="0 0 0 1"/>
  6. </material>
  7. <material name="White">
  8. <color rgba="1 1 1 1"/>
  9. </material>
  10. <material name="Blue">
  11. <color rgba="0 0 1 1"/>
  12. </material>
  13. <material name="Red">
  14. <color rgba="1 0 0 1"/>
  15. </material>
  16. <!-- Constants -->
  17. <xacro:property name="M_PI" value="3.14159"/>
  18. <!-- link1 properties -->
  19. <xacro:property name="link1_width" value="0.03" />
  20. <xacro:property name="link1_len" value="0.10" />
  21. <!-- link2 properties -->
  22. <xacro:property name="link2_width" value="0.03" />
  23. <xacro:property name="link2_len" value="0.14" />
  24. <!-- link3 properties -->
  25. <xacro:property name="link3_width" value="0.03" />
  26. <xacro:property name="link3_len" value="0.22" />
  27. <!-- link4 properties -->
  28. <xacro:property name="link4_width" value="0.025" />
  29. <xacro:property name="link4_len" value="0.06" />
  30. <!-- link5 properties -->
  31. <xacro:property name="link5_width" value="0.03" />
  32. <xacro:property name="link5_len" value="0.06" />
  33. <!-- link6 properties -->
  34. <xacro:property name="link6_width" value="0.04" />
  35. <xacro:property name="link6_len" value="0.02" />
  36. <!-- Left gripper -->
  37. <xacro:property name="left_gripper_len" value="0.08" />
  38. <xacro:property name="left_gripper_width" value="0.01" />
  39. <xacro:property name="left_gripper_height" value="0.01" />
  40. <!-- Right gripper -->
  41. <xacro:property name="right_gripper_len" value="0.08" />
  42. <xacro:property name="right_gripper_width" value="0.01" />
  43. <xacro:property name="right_gripper_height" value="0.01" />
  44. <!-- Gripper frame -->
  45. <xacro:property name="grasp_frame_radius" value="0.001" />
  46. <!-- Inertial matrix -->
  47. <xacro:macro name="inertial_matrix" params="mass">
  48. <inertial>
  49. <mass value="${mass}" />
  50. <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="0.5" iyz="0.0" izz="1.0" />
  51. </inertial>
  52. </xacro:macro>
  53. <!-- /// bottom_joint // -->
  54. <joint name="bottom_joint" type="fixed">
  55. <origin xyz="0 0 0" rpy="0 0 0" />
  56. <parent link="base_link"/>
  57. <child link="bottom_link"/>
  58. </joint>
  59. <link name="bottom_link">
  60. <visual>
  61. <origin xyz=" 0 0 -0.02" rpy="0 0 0"/>
  62. <geometry>
  63. <box size="1 1 0.02" />
  64. </geometry>
  65. <material name="Brown" />
  66. </visual>
  67. <collision>
  68. <origin xyz=" 0 0 -0.02" rpy="0 0 0"/>
  69. <geometry>
  70. <box size="1 1 0.02" />
  71. </geometry>
  72. </collision>
  73. <xacro:inertial_matrix mass="500"/>
  74. </link>
  75. <!-- / BASE LINK // -->
  76. <link name="base_link">
  77. <visual>
  78. <origin xyz="0 0 0" rpy="0 0 0" />
  79. <geometry>
  80. <box size="0.1 0.1 0.04" />
  81. </geometry>
  82. <material name="White" />
  83. </visual>
  84. <collision>
  85. <origin xyz="0 0 0" rpy="0 0 0" />
  86. <geometry>
  87. <box size="0.1 0.1 0.04" />
  88. </geometry>
  89. </collision>
  90. <xacro:inertial_matrix mass="1"/>
  91. </link>
  92. <joint name="joint1" type="revolute">
  93. <parent link="base_link"/>
  94. <child link="link1"/>
  95. <origin xyz="0 0 0.02" rpy="0 ${M_PI/2} 0" />
  96. <axis xyz="-1 0 0" />
  97. <limit effort="300" velocity="1" lower="-2.96" upper="2.96"/>
  98. <dynamics damping="50" friction="1"/>
  99. </joint>
  100. <!-- / LINK1 // -->
  101. <link name="link1" >
  102. <visual>
  103. <origin xyz="-${link1_len/2} 0 0" rpy="0 ${M_PI/2} 0" />
  104. <geometry>
  105. <cylinder radius="${link1_width}" length="${link1_len}"/>
  106. </geometry>
  107. <material name="Blue" />
  108. </visual>
  109. <collision>
  110. <origin xyz="-${link1_len/2} 0 0" rpy="0 ${M_PI/2} 0" />
  111. <geometry>
  112. <cylinder radius="${link1_width}" length="${link1_len}"/>
  113. </geometry>
  114. </collision>
  115. <xacro:inertial_matrix mass="1"/>
  116. </link>
  117. <joint name="joint2" type="revolute">
  118. <parent link="link1"/>
  119. <child link="link2"/>
  120. <origin xyz="-${link1_len} 0 0.0" rpy="-${M_PI/2} 0 ${M_PI/2}" />
  121. <axis xyz="1 0 0" />
  122. <limit effort="300" velocity="1" lower="-2.35" upper="2.35" />
  123. <dynamics damping="50" friction="1"/>
  124. </joint>
  125. <!-- /// LINK2 // -->
  126. <link name="link2" >
  127. <visual>
  128. <origin xyz="0 0 ${link2_len/2}" rpy="0 0 0" />
  129. <geometry>
  130. <cylinder radius="${link2_width}" length="${link2_len}"/>
  131. </geometry>
  132. <material name="White" />
  133. </visual>
  134. <collision>
  135. <origin xyz="0 0 ${link2_len/2}" rpy="0 0 0" />
  136. <geometry>
  137. <cylinder radius="${link2_width}" length="${link2_len}"/>
  138. </geometry>
  139. </collision>
  140. <xacro:inertial_matrix mass="1"/>
  141. </link>
  142. <joint name="joint3" type="revolute">
  143. <parent link="link2"/>
  144. <child link="link3"/>
  145. <origin xyz="0 0 ${link2_len}" rpy="0 ${M_PI} 0" />
  146. <axis xyz="-1 0 0" />
  147. <limit effort="300" velocity="1" lower="-2.62" upper="2.62" />
  148. <dynamics damping="50" friction="1"/>
  149. </joint>
  150. <!-- / LINK3 / -->
  151. <link name="link3" >
  152. <visual>
  153. <origin xyz="0 0 -${link3_len/2}" rpy="0 0 0" />
  154. <geometry>
  155. <cylinder radius="${link3_width}" length="${link3_len}"/>
  156. </geometry>
  157. <material name="Blue" />
  158. </visual>
  159. <collision>
  160. <origin xyz="0 0 -${link3_len/2}" rpy="0 0 0" />
  161. <geometry>
  162. <cylinder radius="${link3_width}" length="${link3_len}"/>
  163. </geometry>
  164. </collision>
  165. <xacro:inertial_matrix mass="1"/>
  166. </link>
  167. <joint name="joint4" type="revolute">
  168. <parent link="link3"/>
  169. <child link="link4"/>
  170. <origin xyz="0.0 0.0 -${link3_len}" rpy="0 ${M_PI/2} ${M_PI}" />
  171. <axis xyz="1 0 0" />
  172. <limit effort="300" velocity="1" lower="-2.62" upper="2.62" />
  173. <dynamics damping="50" friction="1"/>
  174. </joint>
  175. <!-- /// LINK4 -->
  176. <link name="link4" >
  177. <visual>
  178. <origin xyz="${link4_len/2} 0 0" rpy="0 ${M_PI/2} 0" />
  179. <geometry>
  180. <cylinder radius="${link4_width}" length="${link4_len}"/>
  181. </geometry>
  182. <material name="Black" />
  183. </visual>
  184. <collision>
  185. <origin xyz="${link4_len/2} 0 0" rpy="0 ${M_PI/2} 0" />
  186. <geometry>
  187. <cylinder radius="${link4_width}" length="${link4_len}"/>
  188. </geometry>
  189. </collision>
  190. <xacro:inertial_matrix mass="1"/>
  191. </link>
  192. <joint name="joint5" type="revolute">
  193. <parent link="link4"/>
  194. <child link="link5"/>
  195. <origin xyz="${link4_len} 0.0 0.0" rpy="0 ${M_PI/2} 0" />
  196. <axis xyz="1 0 0" />
  197. <limit effort="300" velocity="1" lower="-2.62" upper="2.62" />
  198. <dynamics damping="50" friction="1"/>
  199. </joint>
  200. <!-- // LINK5 / -->
  201. <link name="link5">
  202. <visual>
  203. <origin xyz="0 0 ${link4_len/2}" rpy="0 0 0" />
  204. <geometry>
  205. <cylinder radius="${link5_width}" length="${link5_len}"/>
  206. </geometry>
  207. <material name="White" />
  208. </visual>
  209. <collision>
  210. <origin xyz="0 0 ${link4_len/2} " rpy="0 0 0" />
  211. <geometry>
  212. <cylinder radius="${link5_width}" length="${link5_len}"/>
  213. </geometry>
  214. </collision>
  215. <xacro:inertial_matrix mass="1"/>
  216. </link>
  217. <joint name="joint6" type="revolute">
  218. <parent link="link5"/>
  219. <child link="link6"/>
  220. <origin xyz="0 0 ${link4_len}" rpy="${1.5*M_PI} -${M_PI/2} 0" />
  221. <axis xyz="1 0 0" />
  222. <limit effort="300" velocity="1" lower="-6.28" upper="6.28" />
  223. <dynamics damping="50" friction="1"/>
  224. </joint>
  225. <!-- LINK6 / -->
  226. <link name="link6">
  227. <visual>
  228. <origin xyz="${link6_len/2} 0 0 " rpy="0 ${M_PI/2} 0" />
  229. <geometry>
  230. <cylinder radius="${link6_width}" length="${link6_len}"/>
  231. </geometry>
  232. <material name="Blue" />
  233. </visual>
  234. <collision>
  235. <origin xyz="${link6_len/2} 0 0" rpy="0 ${M_PI/2} 0" />
  236. <geometry>
  237. <cylinder radius="${link6_width}" length="${link6_len}"/>
  238. </geometry>
  239. </collision>
  240. <xacro:inertial_matrix mass="1"/>
  241. </link>
  242. <joint name="finger_joint1" type="prismatic">
  243. <parent link="link6"/>
  244. <child link="gripper_finger_link1"/>
  245. <origin xyz="0.0 0 0" />
  246. <axis xyz="0 1 0" />
  247. <limit effort="100" lower="0" upper="0.06" velocity="1.0"/>
  248. <dynamics damping="50" friction="1"/>
  249. </joint>
  250. <!-- // gripper // -->
  251. <!-- LEFT GRIPPER AFT LINK -->
  252. <link name="gripper_finger_link1">
  253. <visual>
  254. <origin xyz="0.04 -0.03 0"/>
  255. <geometry>
  256. <box size="${left_gripper_len} ${left_gripper_width} ${left_gripper_height}" />
  257. </geometry>
  258. <material name="White" />
  259. </visual>
  260. <xacro:inertial_matrix mass="1"/>
  261. </link>
  262. <joint name="finger_joint2" type="fixed">
  263. <parent link="link6"/>
  264. <child link="gripper_finger_link2"/>
  265. <origin xyz="0.0 0 0" />
  266. </joint>
  267. <!-- RIGHT GRIPPER AFT LINK -->
  268. <link name="gripper_finger_link2">
  269. <visual>
  270. <origin xyz="0.04 0.03 0"/>
  271. <geometry>
  272. <box size="${right_gripper_len} ${right_gripper_width} ${right_gripper_height}" />
  273. </geometry>
  274. <material name="White" />
  275. </visual>
  276. <xacro:inertial_matrix mass="1"/>
  277. </link>
  278. <!-- Grasping frame -->
  279. <link name="grasping_frame"/>
  280. <joint name="grasping_frame_joint" type="fixed">
  281. <parent link="link6"/>
  282. <child link="grasping_frame"/>
  283. <origin xyz="0.08 0 0" rpy="0 0 0"/>
  284. </joint>
  285. <!-- / Gazebo // -->
  286. <gazebo reference="bottom_link">
  287. <material>Gazebo/White</material>
  288. </gazebo>
  289. <gazebo reference="base_link">
  290. <material>Gazebo/White</material>
  291. </gazebo>
  292. <gazebo reference="link1">
  293. <material>Gazebo/Blue</material>
  294. </gazebo>
  295. <gazebo reference="link2">
  296. <material>Gazebo/White</material>
  297. </gazebo>
  298. <gazebo reference="link3">
  299. <material>Gazebo/Blue</material>
  300. </gazebo>
  301. <gazebo reference="link4">
  302. <material>Gazebo/Black</material>
  303. </gazebo>
  304. <gazebo reference="link5">
  305. <material>Gazebo/White</material>
  306. </gazebo>
  307. <gazebo reference="link6">
  308. <material>Gazebo/Blue</material>
  309. </gazebo>
  310. <gazebo reference="gripper_finger_link1">
  311. <material>Gazebo/White</material>
  312. </gazebo>
  313. <gazebo reference="gripper_finger_link2">
  314. <material>Gazebo/White</material>
  315. </gazebo>
  316. <!-- Transmissions for ROS Control -->
  317. <xacro:macro name="transmission_block" params="joint_name">
  318. <transmission name="tran1">
  319. <type>transmission_interface/SimpleTransmission</type>
  320. <joint name="${joint_name}">
  321. <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
  322. </joint>
  323. <actuator name="motor1">
  324. <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
  325. <mechanicalReduction>1</mechanicalReduction>
  326. </actuator>
  327. </transmission>
  328. </xacro:macro>
  329. <xacro:transmission_block joint_name="joint1"/>
  330. <xacro:transmission_block joint_name="joint2"/>
  331. <xacro:transmission_block joint_name="joint3"/>
  332. <xacro:transmission_block joint_name="joint4"/>
  333. <xacro:transmission_block joint_name="joint5"/>
  334. <xacro:transmission_block joint_name="joint6"/>
  335. <xacro:transmission_block joint_name="finger_joint1"/>
  336. <!-- ros_control plugin -->
  337. <gazebo>
  338. <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
  339. <robotNamespace>/arm</robotNamespace>
  340. </plugin>
  341. </gazebo>
  342. </robot>

Transmission for ROS Control那一部分相当于是给关节绑定上电机,通过控制电机控制关节运动。

再创建一个launch文件夹,创建view_arm.launch文件

  1. <launch>
  2. <arg name="model" />
  3. <!-- 加载机器人模型参数 -->
  4. <param name="robot_description" command="$(find xacro)/xacro --inorder $(find arm_description)/urdf/arm.xacro" />
  5. <!-- 设置GUI参数,显示关节控制插件 -->
  6. <!-- <param name="use_gui" value="true"/> -->
  7. <!-- 运行joint_state_publisher节点,发布机器人的关节状态 -->
  8. <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  9. <!-- 运行robot_state_publisher节点,发布tf -->
  10. <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
  11. <!-- 运行rviz可视化界面 -->
  12. <node name="rviz" pkg="rviz" type="rviz"/>
  13. </launch>

运行这个launch文件,在rviz中选择fixed frame,再加载Robot Model,就可以看见机械臂了。

在Gazebo中手动控制机械臂

在工作空间中再创建一个arm_gazebo功能包,添加launch文件夹,创建arm_world.launch

  1. <launch>
  2. <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  3. <arg name="paused" default="false"/>
  4. <arg name="use_sim_time" default="true"/>
  5. <arg name="gui" default="true"/>
  6. <arg name="headless" default="false"/>
  7. <arg name="debug" default="false"/>
  8. <!-- We resume the logic in empty_world.launch -->
  9. <include file="$(find gazebo_ros)/launch/empty_world.launch">
  10. <arg name="debug" value="$(arg debug)" />
  11. <arg name="gui" value="$(arg gui)" />
  12. <arg name="paused" value="$(arg paused)"/>
  13. <arg name="use_sim_time" value="$(arg use_sim_time)"/>
  14. <arg name="headless" value="$(arg headless)"/>
  15. </include>
  16. <!-- Load the URDF into the ROS Parameter Server -->
  17. <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find arm_description)/urdf/arm.xacro'" />
  18. <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  19. <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
  20. args="-urdf -model arm -param robot_description"/>
  21. </launch>

功能是:创建一个环境,并且将机器人模型放进去。

下面要做的是加载控制器,首先要设定pid控制器的参数。在arm_gazebo功能包中创建config文件夹,创建arm_gazebo_control.yaml,给6个关节设定pid控制器参数。

  1. arm:
  2. # Publish all joint states -----------------------------------
  3. joint_state_controller:
  4. type: joint_state_controller/JointStateController
  5. publish_rate: 50
  6. # Position Controllers ---------------------------------------
  7. joint1_position_controller:
  8. type: position_controllers/JointPositionController
  9. joint: joint1
  10. pid: {p: 100.0, i: 0.01, d: 10.0}
  11. joint2_position_controller:
  12. type: position_controllers/JointPositionController
  13. joint: joint2
  14. pid: {p: 100.0, i: 0.01, d: 10.0}
  15. joint3_position_controller:
  16. type: position_controllers/JointPositionController
  17. joint: joint3
  18. pid: {p: 100.0, i: 0.01, d: 10.0}
  19. joint4_position_controller:
  20. type: position_controllers/JointPositionController
  21. joint: joint4
  22. pid: {p: 100.0, i: 0.01, d: 10.0}
  23. joint5_position_controller:
  24. type: position_controllers/JointPositionController
  25. joint: joint5
  26. pid: {p: 100.0, i: 0.01, d: 10.0}
  27. joint6_position_controller:
  28. type: position_controllers/JointPositionController
  29. joint: joint6
  30. pid: {p: 100.0, i: 0.01, d: 10.0}

在launch文件夹中创建arm_gazebo_controller.launch,实现的作用是加载刚才创建的pid参数yaml文件,创建控制器。

  1. <launch>
  2. <!-- 将关节控制器的配置参数加载到参数服务器中 -->
  3. <rosparam file="$(find arm_gazebo)/config/arm_gazebo_control.yaml" command="load"/>
  4. <!-- 加载controllers -->
  5. <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
  6. output="screen" ns="/arm" args="joint_state_controller
  7. joint1_position_controller
  8. joint2_position_controller
  9. joint3_position_controller
  10. joint4_position_controller
  11. joint5_position_controller
  12. joint6_position_controller"/>
  13. <!-- 运行robot_state_publisher节点,发布tf -->
  14. <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
  15. respawn="false" output="screen">
  16. <remap from="/joint_states" to="/arm/joint_states" />
  17. </node>
  18. </launch>

最后再创建一个arm_gazebo_control.launch文件,其作用是,运行world launch和controller launch两个launch文件。

  1. <launch>
  2. <!-- 启动Gazebo -->
  3. <include file="$(find arm_gazebo)/launch/arm_world.launch" />
  4. <!-- 启动Gazebo controllers -->
  5. <include file="$(find arm_gazebo)/launch/arm_gazebo_controller.launch" />
  6. </launch>

运行arm_gazebo_control.launch文件,再另外打开两个terminal,分别运行

rqt
rosrun rviz rviz

通过rqt发送指令,可以在gazebo和rviz中同时看到机械臂的动作。

配置MoveIt

rosrun moveit_setup_assistant moveit_setup_assistant

依次加载模型,生成碰撞矩阵,生成规划组,如下图所示,一个arm规划组和一个gripper规划组,注意“3”那里,新版本的moveit那里不一样,空着就好。

 添加一个初始位姿,命名为home

 配置终端夹爪

最后再添加作者信息,生成配置文件就可以了。命名为arm_moveit_config,和前面创建的两个功能包arm_description, arm_gazebo并列放在一起。

用moveIt控制gazebo中的机械臂

arm_gazebo功能包中创建关节轨迹控制器,一个控制器包含两个部分:yaml配置文件和launch运行文件,yaml配置文件放在功能包的config文件夹中,里面写着控制器的参数,运行文件放在launch文件夹中,用于运行控制器。

arm_moveit_config功能包中创建一个gazebo控制器,同样是一组.yaml和.launch文件(注意这个launch文件的后缀是.launch.xml,这个文件自动存在,不需要创建,我们要改内容),launch文件加载yaml文件,分别放在config文件夹和launch文件夹。以及另外一个单独的.launch(moveit_planning_execution.launch)。

moveit功能包中的控制器和gazebo功能包中的控制器的关系是:通过ros的Action机制,moveit功能包中的控制器发布关节轨迹点指令,gazebo功能包中的控制器控制关节电机是关节到达轨迹点。

还要在arm_gazebo功能包中创建一个关节状态控制器,用于发布关节状态和tf变换。这个是为了在rviz中可视化用。

总结:一共三个控制器7个文件(3个.yaml和4个.launch)

arm_gazebo功能包中的命名为:trajectory_control.yaml    arm_trajectory_controller.launch

arm_gazebo_joint_states.yaml      arm_gazebo_states.launch

arm_moveit_config功能包中的命名为:controllers_gazebo.yaml    arm_moveit_controller_manager.launch.xml

moveit_planning_execution.launch

以上文件的内容整理在后文。最后再创建一个.launch,其作用是一次性运行上面的所有.launch。命名为arm_bringup_moveit.launch,放在arm_gazebo功能包的launch文件夹。

运行最后写的那个.launch,就可以通过rviz中的moveit插件来控制gazebo中的机械臂了。

roslaunch marm_gazebo arm_bringup_moveit.launch

 trajectory_control.yaml 内容:

  1. arm:
  2. arm_joint_controller:
  3. type: "position_controllers/JointTrajectoryController"
  4. joints:
  5. - joint1
  6. - joint2
  7. - joint3
  8. - joint4
  9. - joint5
  10. - joint6
  11. gains:
  12. joint1: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  13. joint2: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  14. joint3: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  15. joint4: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  16. joint5: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  17. joint6: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  18. gripper_controller:
  19. type: "position_controllers/JointTrajectoryController"
  20. joints:
  21. - finger_joint1
  22. gains:
  23. finger_joint1: {p: 50.0, d: 1.0, i: 0.01, i_clamp: 1.0}

 arm_trajectory_controller.launch 内容:

  1. <launch>
  2. <rosparam file="$(find arm_gazebo)/config/trajectory_control.yaml" command="load"/>
  3. <node name="arm_controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
  4. output="screen" ns="/arm" args="arm_joint_controller gripper_controller"/>
  5. </launch>

arm_gazebo_joint_states.yaml 内容:

  1. arm:
  2. # Publish all joint states -----------------------------------
  3. joint_state_controller:
  4. type: joint_state_controller/JointStateController
  5. publish_rate: 50

arm_gazebo_states.launch 内容:

  1. <launch>
  2. <!-- 将关节控制器的配置参数加载到参数服务器中 -->
  3. <rosparam file="$(find arm_gazebo)/config/arm_gazebo_joint_states.yaml" command="load"/>
  4. <node name="joint_controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
  5. output="screen" ns="/arm" args="joint_state_controller" />
  6. <!-- 运行robot_state_publisher节点,发布tf -->
  7. <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
  8. respawn="false" output="screen">
  9. <remap from="/joint_states" to="/arm/joint_states" />
  10. </node>
  11. </launch>

controllers_gazebo.yaml内容:

  1. controller_manager_ns: controller_manager
  2. controller_list:
  3. - name: arm/arm_joint_controller
  4. action_ns: follow_joint_trajectory
  5. type: FollowJointTrajectory
  6. default: true
  7. joints:
  8. - joint1
  9. - joint2
  10. - joint3
  11. - joint4
  12. - joint5
  13. - joint6
  14. - name: arm/gripper_controller
  15. action_ns: follow_joint_trajectory
  16. type: FollowJointTrajectory
  17. default: true
  18. joints:
  19. - finger_joint1
  20. - finger_joint2

arm_moveit_controller_manager.launch.xml内容:

  1. <launch>
  2. <!-- Set the param that trajectory_execution_manager needs to find the controller plugin -->
  3. <arg name="moveit_controller_manager" default="moveit_simple_controller_manager/MoveItSimpleControllerManager" />
  4. <param name="moveit_controller_manager" value="$(arg moveit_controller_manager)"/>
  5. <!-- load controller_list -->
  6. <!-- Arbotix -->
  7. <!-- <rosparam file="$(find marm_moveit_config)/config/controllers.yaml"/> -->
  8. <!-- Gazebo -->
  9. <rosparam file="$(find arm_moveit_config)/config/controllers_gazebo.yaml"/>
  10. </launch>

moveit_planning_execution.launch内容:

  1. <launch>
  2. # The planning and execution components of MoveIt! configured to
  3. # publish the current configuration of the robot (simulated or real)
  4. # and the current state of the world as seen by the planner
  5. <include file="$(find arm_moveit_config)/launch/move_group.launch">
  6. <arg name="publish_monitored_planning_scene" value="true" />
  7. </include>
  8. # The visualization component of MoveIt!
  9. <include file="$(find arm_moveit_config)/launch/moveit_rviz.launch"/>
  10. <!-- We do not have a robot connected, so publish fake joint states -->
  11. <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
  12. <param name="/use_gui" value="false"/>
  13. <rosparam param="/source_list">[/arm/joint_states]</rosparam>
  14. </node>
  15. </launch>

arm_bringup_moveit.launch内容:

  1. <launch>
  2. <!-- Launch Gazebo -->
  3. <include file="$(find arm_gazebo)/launch/arm_world.launch" />
  4. <!-- ros_control arm launch file -->
  5. <include file="$(find arm_gazebo)/launch/arm_gazebo_states.launch" />
  6. <!-- ros_control trajectory control dof arm launch file -->
  7. <include file="$(find arm_gazebo)/launch/arm_trajectory_controller.launch" />
  8. <!-- moveit launch file -->
  9. <include file="$(find arm_moveit_config)/launch/moveit_planning_execution.launch" />
  10. </launch>

一些可能出现的报错:

Tried to advertise on topic but the topic is already advertised

解决办法:

arm_moveit_config功能包中,sensors_3d.yaml文件中,出现了重名topic,修改第二个topic的名称

 Unable to identify any set of controllers that can actuate the specified joints:

解决办法:修改

工作空间/src/marm_moveit_config/launch/trajectory_execution.launch.xml

删掉 pass_all_args="true"

通过python的接口运行moveit

上面是通过rviz中的插件来控制moveit,下面通过py文件来运行moveit,不需要在rviz中操作moveit插件。

还是先运行arm_bringup_moveit.launch

再运行这个py文件,group_name是在moveit_setup_assistant中配置的group,在joint_goal那里设定关节目标角度 弧度制。

  1. import sys
  2. import rospy
  3. import moveit_commander
  4. from moveit_commander import PlanningSceneInterface
  5. moveit_commander.roscpp_initialize(sys.argv)
  6. rospy.init_node('move_group_python_interface_tutorial', anonymous=True)
  7. ## Instantiate a `RobotCommander`_ object. Provides information such as the robot's
  8. ## kinematic model and the robot's current joint states
  9. robot = moveit_commander.RobotCommander()
  10. ## Instantiate a `PlanningSceneInterface`_ object. This provides a remote interface
  11. ## for getting, setting, and updating the robot's internal understanding of the
  12. ## surrounding world:
  13. scene = moveit_commander.PlanningSceneInterface()
  14. ## Instantiate a `MoveGroupCommander`_ object. This object is an interface
  15. ## to a planning group (group of joints). In this tutorial the group is the primary
  16. ## arm joints in the Panda robot, so we set the group's name to "panda_arm".
  17. ## If you are using a different robot, change this value to the name of your robot
  18. ## arm planning group.
  19. ## This interface can be used to plan and execute motions:
  20. group_name = "arm"
  21. move_group = moveit_commander.MoveGroupCommander(group_name)
  22. joint_goal = move_group.get_current_joint_values()
  23. print(joint_goal)
  24. joint_goal[0] = 0
  25. joint_goal[1] = 0.9
  26. joint_goal[2] = 0
  27. joint_goal[3] = 0
  28. # The go command can be called with joint values, poses, or without any
  29. # parameters if you have already set the pose or joint target for the group
  30. move_group.go(joint_goal, wait=True)
  31. # Calling ``stop()`` ensures that there is no residual movement
  32. move_group.stop()
  33. ## END_SUB_TUTORIAL
  34. # For testing:
  35. current_joints = move_group.get_current_joint_values()
  36. print(current_joints)

如果是pycharm运行py文件,注意interpreter选择,我的虚拟机安装的是ubuntu18 和ros melodic,需要python2.7的interpreter,另外还要把melodic的python包放进pycharm的project structure。另外,在pycharm中添加两个环境变量。以上。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/703758
推荐阅读
相关标签
  

闽ICP备14008679号