參考資料:https://www.youtube.com/watch?v=j6bBxfD_bYs
1. 下載ROS-Industrial universal robot meta-package
cd ~/catkin_ws/src
git clone https://github.com/ros-industrial/universal_robot.git
cd ~/catkin_ws
catkin_make
2. 啓動Gazebo
cd ~/catkin_ws/src/universal_robot/ur_gazebo/launch
roslaunch ur10.launch
此時Gazebo將啓動,並且能夠看到ur10機械臂
3. 配置MoveIt!
roslaunch moveit_setup_assistant setup_assistant.launch
第一個標籤下面需要選擇機械臂的urdf文件,注意/catkin_ws/src/universal_robot/ur_description/urdf/文件夾中只有xacro文件,因此先使用xacro命令將ur10.urdf.xacro轉換爲靜態urdf文件。
cd ~/catkin_ws/src/universal_robot/ur_description/urdf/
rosrun xacro xacro.py ur10.urdf.xacro > ur10.urdf
然後逐步完成配置,具體可參考上面的Youtube視頻或者ROS by Example的11.10節,最後一步選擇存放生成的package的位置,這裏將其命名爲demo_moveit_config。
4. 連接到Gazebo
在demo_moveit_config/config/文件夾中創建兩個文件,controllers.yaml和joint_names.yaml。
controllers.yaml的內容如下:
controller_list:
- name: arm_controller
action_ns: "follow_joint_trajectory"
type: FollowJointTrajectory
joints: [shoulder_pan_joint, shoulder_lift_joint, elbow_joint, wrist_1_joint, wrist_2_joint, wrist_3_joint]
其中,arm_controller是action server,可以通過rostopic list看到,joints的名字是在urdf文件裏定義的,可以在ur10.urdf裏找到。
joint_names.yaml內容如下:
controller_joint_names: [shoulder_pan_joint, shoulder_lift_joint, elbow_joint, wrist_1_joint, wrist_2_joint, wrist_3_joint]
然後在launch文件夾中找到ur10_moveit_controller_manager.launch.xml,是個空文件,將其改爲:
<launch>
<rosparam file="$(find demo_moveit_config)/config/controllers.yaml"/>
<param name="use_controller_manager" value="false"/>
<param name="trajectory_execution/execution_duration_monitoring" value="false"/>
<param name="moveit_controller_manager" value="moveit_simple_controller_manager/MoveItSimpleControllerManager"/>
</launch>
在launch文件夾下新建文件,demo_planning_execution.launch,其內容如下:
<launch>
<rosparam command="load" file="$(find demo_moveit_config)/config/joint_names.yaml"/>
<include file="$(find demo_moveit_config)/launch/planning_context.launch" >
<arg name="load_robot_description" value="true" />
</include>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
<param name="/use_gui" value="false"/>
<rosparam param="/source_list">[/joint_states]</rosparam>
</node>
<include file="$(find demo_moveit_config)/launch/move_group.launch" >
<arg name="publish_monitored_planning_scene" value="true" />
</include>
<include file="$(find demo_moveit_config)/launch/moveit_rviz.launch" >
<arg name="config" value="true" />
</include>
</launch>
5. 使用MoveIt!控制仿真的機械臂
roslaunch demo_moveit_config demo_planning_execution.launch
會看到rviz界面出現,現在就可以在planning標籤測試一下了。