【前言】本篇文章旨在实现,在gazebo中对ur5e机械臂进行仿真,并通过moveit实现机械臂的控制。
一、仿真前准备
1.1 Gazebo安装
Ubuntu18.04 + ROS melodic,安装gazebo9:自用参考链接
1.2 UR机械臂软件包安装
步骤:
1)创建工作空间
2)安装UR臂软件包 universal_robot
cd catkin_ws/src
git clone -b melodic-devel https://github.com/ros-industrial/universal_robot.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro melodic // 安装插件
catkin build
source devel/setup.bash
1.3 本文工作空间catkin_ws文件结构
|--catkin_ws
|----src
|------universal_robot
|------robot_gazebo
|----------robot_description
|----------ur5e_moveit_config
git地址:GitHub - Aya-nuomi/marker_track
二、在gazebo中显示ur5e机械臂
参考链接:UR5 Gazebo仿真配置(不使用MoveIt)
步骤:
1)创建一个工作空间(使用上一步创建的catkin_ws工作空间)
2)创建一个ROS包,并创建urdf、meshes、launch文件夹
·创建ROS包 -> robot_description
cd catkin_ws/src
mkdir -p robot_gazebo
cd robot_gazebo
catkin_create_pkg robot_description rospy roscpp
·创建urdf、meshes、launch文件夹
cd robot_description
mkdir urdf
mkdir meshes
mkdir launch
3)把ur5e的urdf、mesh文件(ur5e_moveit_config中)拷贝进来,并修改文件中的模型地址
·修改ur5e_robot.urdf.xacro文件,把xacro文件地址中包名 ur_e_description 修改为自己的包名,这里是 robot_description
<?xml version="1.0"?>
<robot name="ur5e" xmlns:xacro="http://ros.org/wiki/xacro" >
<!-- common stuff -->
<xacro:include filename="$(find robot_description)/urdf/common.gazebo.xacro" />
<!-- ur5e -->
<xacro:include filename="$(find robot_description)/urdf/ur5e.urdf.xacro" />
<!-- my_arm -->
<xacro:ur5e_robot prefix="" joint_limited="false"/>
<link name="world" />
<joint name="world_joint" type="fixed">
<parent link="world" />
<child link = "base_link" />
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
</joint>
</robot>
·修改ur5e.urdf.xacro文件,操作类似上一步
4)创建ur_gazebo.launch文件,在gazebo中显示机械臂模型
·这里运行"spawn_model"节点时,参数z取0.1,使机械臂初始状态下与地面有一定的间隙,防止机械臂与地面产生干涉
<?xml version="1.0"?>
<!-- ur_gazebo.launch load Gazebo world and ur5e model -->
<launch>
<!-- Gazebo world -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" default="worlds/empty.world"/>
</include>
<!-- parse xacro file into urdf and upload urdf to parameter server -->
<param name="robot_description" command="$(find xacro)/xacro --inorder '$(find robot_description)/urdf/ur5e_robot.urdf.xacro'" />
<!-- spawn robot in gazebo -->
<node name="spawn_gazebo_model" pkg="gazebo_ros" type="spawn_model" args="-urdf -param robot_description -model robot -z 0.1" respawn="false" output="screen" />
</launch>
5)修改urdf.xacro文件, 调整机械臂初始位姿
·把第二个关节shoulder_lift_joint的初始关节角旋转−π/2,修改ur5.urdf.xacro文件,调整对应<joint>的<origin>值,改完后机械臂初始状态变成竖直的姿态
<joint name="${prefix}shoulder_lift_joint" type="revolute">
<parent link="${prefix}shoulder_link" />
<child link = "${prefix}upper_arm_link" />
<origin xyz="0.0 ${shoulder_offset} 0.0" rpy="0.0 0.0 0.0" /> <!--<origin xyz="0.0 ${shoulder_offset} 0.0" rpy="0.0 ${pi / 2.0} 0.0" />-->>
<axis xyz="0 1 0" />
......
</joint>
6)测试
roslaunch robot_description ur_gazebo.launch
三、使用moveit控制ur5e机械臂
3.1 生成moveit配置文件 -> moveit_setup_assistant
步骤:
1)安装moveit_setup_assistant
sudo apt install ros-melodic-moveit
2)启动moveit_setup_assistant
cd catkin_ws // 进到工作空间内启动配置助手,才能找到机器人模型xacro文件
source devel/setup.bash
roslaunch moveit_setup_assistant setup_assistant.launch
3)导入模型文件,配置,生成配置文件夹
详细操作:MoveIt入门之——使用MoveIt配置助手生成MoveIt配置文件, MoveIt Setup Assistant
tips:ROS control那一步很重要,需要点一下
本人生成的配置文件夹为:ur5e_moveit_config,放在catkin_ws/src/robot_gazebo中。
3.2 修改moveit包(刚才生成的配置文件夹)
第一次实现moveit控制gazebo仿真ur5机械臂
1)修改moveit配置文件中.../config/ros_controllers.yaml,在末尾添加
arm_controller:
type: position_controllers/JointTrajectoryController
joints:
- shoulder_pan_joint
- shoulder_lift_joint
- elbow_joint
- wrist_1_joint
- wrist_2_joint
- wrist_3_joint
constraints:
goal_time: 0.6
stopped_velocity_tolerance: 0.05
shoulder_pan_joint: {trajectory: 0.1, goal: 0.1}
shoulder_lift_joint : {trajectory: 0.1, goal: 0.1}
elbow_joint: {trajectory: 0.1, goal: 0.1}
wrist_1_joint: {trajectory: 0.1, goal: 0.1}
wrist_2_joint: {trajectory: 0.1, goal: 0.1}
wrist_3_joint: {trajectory: 0.1, goal: 0.1}
stop_trajectory_duration: 0.5
state_publish_rate: 25
action_monitor_rate: 1
2)修改.../launch/ros_controllers.launch
<!-- Load the controllers -->
<!-- 注释的为原来的,需要改成下面那一行 -->
<!-- <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
output="screen" args=""/> -->
<node name="controller_spawner" pkg="controller_manager" type="controller_manager" respawn="false"
output="screen" args="spawn joint_state_controller arm_controller"/>
3.3 运行launch文件
catkin build
source devel/setup.bash
roslaunch ur5e_moveit_config demo_gazebo.launch
注意:开始运行launch文件时,gazebo中一直不显示ur模型,后来发现有一个bug...
需要修改.../ur5e_moveit_config/launch/gazebo.launch,因为加载模型文件时,加载的是xacro文件,不是urdf文件。
<!-- send robot urdf to param server -->
<!-- <param name="robot_description" textfile="$(arg urdf_path)" /> -->
<param name="robot_description" command="$(find xacro)/xacro $(arg urdf_path)" />
Next: 在gazebo中进行二维码识别与跟随仿真
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)