gazebo+rviz中配置UR+robotiq_gripper夹爪,最详细操作过程


最原始的ros-industrial提供的robotiq夹爪的功能包,是不能用在gazebo中仿真的,只能在rviz中可视化,原因就是其urdf文件,或者说xacro文件中缺少在gazebo中需要的东西。下面就具体说一下应该修改哪些文件:

1.下载功能包

现在UR官方把机器人的仿真包更新了,和原来我用的不一样,这里还有我之前的版本,需要的可以去下载https://github.com/Luchuanzhao/UR5-robotiq85_gripper-gazebo

1.UR机器人功能包下载

github地址:https://github.com/ros-industrial/universal_robot/tree/melodic-devel
这个是Ubuntu18.04+ROS melodic版本的,如果需要其他版本请在分支中选择。
下载完成后记得编译工作空间。

2.Robotiq功能包下载

这里有两种版本的功能包
建议使用下面经过修改后的功能包。
这个是经过修改的:https://github.com/MetaMemoryT/robotiq_85_gripper-1
这个是ros-industrial的:https://github.com/ros-industrial/robotiq
我用的是修改过的,也就是第一个仓库中的,因为ros-industrial那个在使用robotiq_2f_85_gripper_visualization功能包时,其中的夹爪基座的dae文件是不正确的,在仓库的issue中也有人修改过,但是我还是没有修改成功,就用了另外一个仓库的功能包。而且这个包的好处就是支持在gazebo中仿真,因为作者已经修改好了xacro文件,添加了gazebo仿真必需的部分。

插件修改

由于在robotiq夹爪中有几个关节是被动关节(mimic joint),标准Gazebo不支持Mimic 关节仿真, 所以需要安装一个插件。第一个功能包中用到了这个插件,如果出问题就用下面这个仓库中的代码代替:https://github.com/roboticsgroup/roboticsgroup_gazebo_plugins
这个仓库含有的插件很全:https://github.com/JenniferBuehler/gazebo-pkgs
下载好之后记得编译。

2.gazebo仿真所需代码

下面来说一下如果下载的是最原始版本的代码,如何修改。(如果使用的是第一个经过修改的代码,这部分请略过)

1.修改urdf文件

找到robotiq_2f_140_gripper_visualization/urdf/robotiq_arg2f_transmission.xacro这个文件,修改为:

<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro">
  <xacro:macro name="robotiq_arg2f_transmission" params="prefix">
    <transmission name="${prefix}finger_joint_trans">
      <type>transmission_interface/SimpleTransmission</type>
      <joint name="${prefix}finger_joint">
        <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
      </joint>
      <actuator name="${prefix}finger_joint_motor">
        <mechanicalReduction>1</mechanicalReduction>
      </actuator>
    </transmission>
	    <gazebo>
             <!-- loading plugin: mimic joints works in gazebo now-->
             <plugin filename="libroboticsgroup_gazebo_mimic_joint_plugin.so" name="${prefix}mimic_robotiq_85_4">
                <joint>${prefix}finger_joint</joint>
                <mimicJoint>${prefix}right_outer_knuckle_joint</mimicJoint>
                <multiplier>1.0</multiplier>
            </plugin>
            <plugin filename="libroboticsgroup_gazebo_mimic_joint_plugin.so" name="${prefix}mimic_robotiq_85_2">
                <joint>${prefix}finger_joint</joint>
                <mimicJoint>${prefix}left_inner_finger_joint</mimicJoint>
                <multiplier>-1.0</multiplier>
                <!--<offset>0.0</offset>-->
            </plugin>
            <plugin filename="libroboticsgroup_gazebo_mimic_joint_plugin.so" name="${prefix}mimic_robotiq_85_1">
                <joint>${prefix}finger_joint</joint>
                <mimicJoint>${prefix}right_inner_finger_joint</mimicJoint>
                <multiplier>-1.0</multiplier>
            </plugin>
            <plugin filename="libroboticsgroup_gazebo_mimic_joint_plugin.so" name="${prefix}mimic_robotiq_85_3">
                <joint>${prefix}finger_joint</joint>
                <mimicJoint>${prefix}left_inner_knuckle_joint</mimicJoint>
                <multiplier>1.0</multiplier>
            </plugin>
            <plugin filename="libroboticsgroup_gazebo_mimic_joint_plugin.so" name="${prefix}mimic_robotiq_85_5">
                <joint>${prefix}finger_joint</joint>
                <mimicJoint>${prefix}right_inner_knuckle_joint</mimicJoint>
                <multiplier>1.0</multiplier>
            </plugin>
        </gazebo>
  </xacro:macro>

</robot>

如果运行时有报错Deprecated syntax, please prepend ‘hardware_interface/’ to ‘PositionJointInterface’ within the tag in joint ‘finger_joint’
就把上面文件中的

<hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>

改成

<hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>

单独仿真夹爪时,需要用到ros-control,在此文件中添加:

<gazebo> 
		<plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so"> 
				<robotNamespace>/</robotNamespace> 
				<legacyModeNS>true</legacyModeNS> 
		</plugin>
 </gazebo>

和ur机器人连接到一块时,一定要删掉这段!

2.创建yaml文件

在gazebo中仿真夹爪,要给它控制参数,即PID参数,在robotiq_2f_85_gripper_visualization下创建config文件夹,在config下创建gazebo_controller.yaml文件,把下面代码复制进去:

# Note: You MUST load these PID parameters for all joints that are using the
# PositionJointInterface, otherwise the arm + gripper will act like a giant
# parachute, counteracting gravity, and causing some of the wheels to lose
# contact with the ground, so the robot won't be able to properly navigate. See
# https://github.com/ros-simulation/gazebo_ros_pkgs/issues/612
gazebo_ros_control:
  pid_gains:
    # these gains are used by the gazebo_ros_control plugin
    finger_joint:
      p: 20.0
      i: 0.1
      d: 0.0
      i_clamp: 0.2
      antiwindup: false
      publish_state: true
    # the following gains are used by the gazebo_mimic_joint plugin
    left_inner_knuckle_joint:
      p: 20.0
      i: 0.1
      d: 0.0
      i_clamp: 0.2
      antiwindup: false
      publish_state: true

    left_inner_finger_joint:
      p: 20.0
      i: 0.1
      d: 0.0
      i_clamp: 0.2
      antiwindup: false
      publish_state: true

    right_outer_knuckle_joint:
      p: 20.0
      i: 0.1
      d: 0.0
      i_clamp: 0.2
      antiwindup: false
      publish_state: true

    right_inner_knuckle_joint:
      p: 20.0
      i: 0.1
      d: 0.0
      i_clamp: 0.2
      antiwindup: false
      publish_state: true

    right_inner_finger_joint:
      p: 20.0
      i: 0.1
      d: 0.0
      i_clamp: 0.2
      antiwindup: false
      publish_state: true

继续在config下创建gripper_controller_robotiq.yaml文件:

gripper_controller:
  type: position_controllers/JointTrajectoryController
  joints:
     - finger_joint
  constraints:
      goal_time: 0.6
      stopped_velocity_tolerance: 0.05
      finger_joint: {trajectory: 0.01, goal: 0.01}
  stop_trajectory_duration: 0.5
  state_publish_rate:  25
  action_monitor_rate: 10

继续在config下创建joint_state_controller.yaml文件:

joint_state_controller:
  type: joint_state_controller/JointStateController
  publish_rate: 50

3.创建launch文件

robotiq_2f_85_gripper_visualization/launch文件夹下创建gripper_gazebo.launch文件:

<?xml version="1.0" ?>

<launch>
  <param name="robot_description" command="$(find xacro)/xacro --inorder $(find robotiq_2f_85_gripper_visualization)/urdf/robotiq_arg2f_85_model.xacro" />

  <!-- Load gazebo controller configurations -->
  <!-- Note: You MUST load these PID parameters for all joints that are using
       the PositionJointInterface, otherwise the arm + gripper will act like a
       giant parachute, counteracting gravity, and causing some of the wheels
       to lose contact with the ground, so the robot won't be able to properly
       navigate. See
       https://github.com/ros-simulation/gazebo_ros_pkgs/issues/612 -->
  <rosparam file="$(find robotiq_2f_85_gripper_visualization)/config/gazebo_controller.yaml" command="load" />

  <!-- Gazebo -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="paused" value="false" />
  </include>

  <!-- Spawn the robot into Gazebo -->
  <node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-urdf -param robot_description -model robot -x 0 -y 0 -z 0.1" />

  <!-- Load ros_control controller configurations -->
  <rosparam file="$(find robotiq_2f_85_gripper_visualization)/config/joint_state_controller.yaml" command="load" />
  <rosparam file="$(find robotiq_2f_85_gripper_visualization)/config/gripper_controller_robotiq.yaml" command="load" />

  <!-- Start the controllers -->
  <node name="controller_spawner" pkg="controller_manager" type="spawner" output="screen" ns="/" args="joint_state_controller gripper_controller"/>

  <!-- Robot state publisher -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" output="screen" />
<node name="gui_controller" pkg="rqt_joint_trajectory_controller" type="rqt_joint_trajectory_controller" />
</launch>

 其中最后调用的rqt_joint_trajectory_controller是一个工具,可以实时发布并控制机器人各关节的角度,如果没安装可以使用sudo apt-get install ros-melodic-joint-trajectory-controller来安装。
 编译之后, 用roslaunch robotiq_2f_85_gripper_visualization gripper_gazebo.launch命令就可以在gazebo中看到夹爪了(后面再放截图)。

3.UR5和robotiq85结合

这里需要修改ur5的描述文件

1.修改ur5的urdf文件

找到universial_robot/ur_description/urdf/文件夹,新建一个ur5_robot_robotiq85_gripper.urdf.xacro文件或直接复制ur5_robot.urdf.xacro,然后把名字改成这个也可以。这个文件中包含如下代码:
可以对比下和原来的文件相比增加了哪些代码。

<?xml version="1.0"?>
<robot xmlns:xacro="http://wiki.ros.org/xacro" name="ur5" >

  <xacro:arg name="transmission_hw_interface" default="hardware_interface/PositionJointInterface"/>

  <!-- common stuff -->
  <xacro:include filename="$(find ur_description)/urdf/common.gazebo.xacro" />

  <!-- ur5_robotiq85_gripper -->
  <xacro:include filename="$(find ur_description)/urdf/ur5.urdf.xacro" />
  <xacro:include filename="$(find robotiq_85_description)/urdf/robotiq_85_gripper.urdf.xacro" />

  <!-- arm -->
  <xacro:ur5_robot prefix="" joint_limited="false"
    transmission_hw_interface="$(arg transmission_hw_interface)"
  />
  

  <!--robotiq_85_gripper-->
  <xacro:robotiq_85_gripper prefix="" parent="ee_link"/>


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

2.修改launch文件

找到universial_robot/ur_description/launch/文件夹,下面有view_ur5.launchur5_upload.launch两个文件,可以分别复制一份,然后进行修改。新复制的view_ur5.launch可以命名为view_ur5_gripper.launch,其中的

<include file="$(find ur_description)/launch/ur5_upload.launch"/>

修改为

<include file="$(find ur_description)/launch/ur5_upload_gripper.launch"/>

新复制的ur5_upload.launch可以命名为ur5_upload_gripper.launch,其中的

<param unless="$(arg limited)" name="robot_description" command="$(find xacro)/xacro --inorder $(find ur_description)/urdf/ur5_robot.urdf.xacro transmission_hw_interface:=$(arg transmission_hw_interface)" />

改为

<param unless="$(arg limited)" name="robot_description" command="$(find xacro)/xacro --inorder $(find ur_description)/urdf/ur5_robot_robotiq85_gripper.urdf.xacro transmission_hw_interface:=$(arg transmission_hw_interface)" />

上边这些是在rviz中查看的launch文件,下面,说一下gazebo中如何修改:
找到universial_robot/ur_gazebo/launch/文件夹,下面的ur5.launch修改如下:
将其中的

<include file="$(find ur_description)/launch/ur5_upload.launch">

修改为

<include file="$(find ur_description)/launch/ur5_upload_robotiq85_gripper.launch">

添加下面这两行代码:

<rosparam file="$(find robotiq_85_gazebo)/controller/gripper_controller_robotiq.yaml" command="load"/>
<node name="gui_controller" pkg="rqt_joint_trajectory_controller" type="rqt_joint_trajectory_controller" />

这一行:

<node name="arm_controller_spawner" pkg="controller_manager" type="controller_manager" args="spawn arm_controller" respawn="false" output="screen"/>

修改为

<node name="arm_controller_spawner" pkg="controller_manager" type="controller_manager" args="spawn arm_controller gripper" respawn="false" output="screen"/>

这样做可以对夹爪进行控制。
至此,所有文件修改完毕。

3.运行launch文件查看效果

首先测试rviz中,运行roslaunch ur5_description view_ur5_gripper.launch,不出意外应该可以看到以下效果,在joint_state_publisher_gui中调整可以控制机械臂和夹爪。
在这里插入图片描述
测试gazebo中效果:
运行roslaunch ur_gazebo ur5.launch,可以看到以下效果:
通过滑动右边划块可以控制机械臂运动,controller选择gripper可以控制夹爪。
在这里插入图片描述
到上面应该就UR+robotiq85的配置全部完成了,所有涉及的代码我放到github上:UR5+robotiq85
我的仿真会出现夹爪一直在抖的问题,机械臂移动几下或者过一段时间,夹爪就散架了,没能找到解决方案,修改关节的effort也不行,希望有大佬如果可以解决这个问题,能够不吝赐教!
由于这个夹爪我没法使用,所以又换了dh_gripper,参考我的另一篇文章UR5+dh_ag95_gripper夹爪配置
在这里插入图片描述
在这里插入图片描述
现在问题解决啦,下一些插件就行了,参考另一篇博客:https://blog.csdn.net/qq_44642372/article/details/124462220
参考以下文章:
https://blog.csdn.net/Tepmoe/article/details/119455411
https://blog.csdn.net/weixin_42268975/article/details/106268506

  • 11
    点赞
  • 116
    收藏
    觉得还不错? 一键收藏
  • 25
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 25
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值