当前位置: 首页 > article >正文

Ubuntu20.04+ROS 进行机械臂抓取仿真:环境搭建(一)

目录

一、从官网上下载UR机械臂

二、给UR机械臂添加夹爪

三、报错解决


本文详细介绍如何在Ubuntu20.04+ROS环境中为Universal Robots的UR机械臂添加夹爪。首先从官方和第三方源下载必要的软件包,包括UR机械臂驱动、夹爪插件和相关依赖。然后,针对gazebo版本不匹配的问题,替换夹爪文件中的旧版API,并修改夹爪和机械臂的urdf配置文件。接着,更新launch文件以包含夹爪控制器,并进行编译。然后解决依赖缺失的问题。最后,运行启动文件。

一、从官网上下载UR机械臂

 首先构建工程:

 mkdir -p catkin_ws/src 
 cd catkin_ws/src

在终端中进入src目录输入下面几串代码:

git clone https://github.com/UniversalRobots/Universal_Robots_ROS_Driver.git src/Universal_Robots_ROS_Driver
git clone -b calibration_devel https://github.com/fmauch/universal_robot.git src/fmauch_universal_robot
git clone https://github.com/ros-industrial/ur_msgs.git src/ur_msgs
catkin_make

二、给UR机械臂添加夹爪

(1)从官网上下载的UR机械臂是没有夹爪的,需要自己添加夹爪。

git clone https://github.com/DH-Robotics/dh_gripper_ros.git src/dh_gripper_ros

夹爪下载完之后再进行编译,这时候会报错,因为下载的夹爪文件中程序调用的时Gazebo7中的 API,而在gazebo9时函数已经被改写,有的函数已经不存在。因此需要将部分文件替换成gazebo11的版本:

https://github.com/roboticsgroup/roboticsgroup_gazebo_plugins.git

将这个下载下来的roboticsgroup_gazebo_plugins替换掉原有路径:dh_robotics_ag95_gripper/dh_robotics_ag95_simulation/roboticsgroup_gazebo_plugins 的这个包。

2)在刚刚下载好的dh_robotics_ag95_gripper文件中进行操作

dh_robotics_ag95_gripper/dh_robotics_ag95_description/urdf/dh_robotics_ag95_gripper.xacro,然后将下面几段代码注释掉并保存:

<gazebo>
        <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so"> 
            <robotNamespace>/</robotNamespace>
            <legacyModeNS>true</legacyModeNS>
        </plugin> 
    </gazebo>
 
 <link name="world"/>
    <joint name="world_fixed" type="fixed">
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <parent link="world"/>
        <child link="gripper_root_link"/>
    </joint>
 
    <link name="gripper_root_link">
        <visual>
            <origin xyz="0 0 0.5" rpy="0 0 0"/>
            <geometry>
                <box size="0.1 0.1 1.0"/>
            </geometry>
        </visual>
        <collision>
            <origin xyz="0 0 0.5" rpy="0 0 0"/>
            <geometry>
                <box size="0.1 0.1 1.0"/>
            </geometry>
        </collision>
        <inertial>
            <mass value="1e2" />
            <origin xyz="0.0 0.0 0.0" />
            <inertia ixx = "0.000001" ixy = "0.000000" ixz = "0.000000"
                     iyx = "0.000000" iyy = "0.000001" iyz = "0.000000"
                     izx = "0.000000" izy = "0.000000" izz = "0.000001" />
        </inertial>
    </link>
    
    <xacro:dh_robotics_ag95_gripper prefix="" parent="gripper_root_link" >
        <origin xyz="0.05 0 0.85" rpy="${pi/2}  0 ${pi/2}"/>
    </xacro:dh_robotics_ag95_gripper>

然后打开机械臂文件:打开fmauch_universal_robot/ur_description/urdf,复制ur5.xacro文件并重命名为ur5_dh.xacro;并且添加下面几行代码:

<xacro:include filename="$(find dh_robotics_ag95_description)/urdf/dh_robotics_ag95_gripper.xacro" />
 
  <!--dh_ag95_gripper-->
  <xacro:dh_robotics_ag95_gripper prefix="" parent="tool0" >
        <origin xyz="0 0 0" rpy="0 0 0"/>
    </xacro:dh_robotics_ag95_gripper>

打开fmauch_universal_robot/ur_description/launch,复制load_ur5.launch并且重命名为load_ur5.launch,将下面代码替代原来的代码:

<?xml version="1.0"?>
<launch>
  <!--ur5 parameters files -->
  <arg name="joint_limit_params" default="$(find ur_description)/config/ur5/joint_limits.yaml"/>
  <arg name="kinematics_params" default="$(find ur_description)/config/ur5/default_kinematics.yaml"/>
  <arg name="physical_params" default="$(find ur_description)/config/ur5/physical_parameters.yaml"/>
  <arg name="visual_params" default="$(find ur_description)/config/ur5/visual_parameters.yaml"/>
  <!--common parameters -->
  <arg name="transmission_hw_interface" default="hardware_interface/PositionJointInterface" />
  <arg name="safety_limits" default="false" doc="If True, enable the safety limits controller"/>
  <arg name="safety_pos_margin" default="0.15" doc="The lower/upper limits in the safety controller" />
  <arg name="safety_k_position" default="20" doc="Used to set k position in the safety controller" />
 
 
  <param name="robot_description" command="$(find xacro)/xacro $(find ur_description)/urdf/ur5_dh.xacro transmission_hw_interface:=$(arg transmission_hw_interface)" />
  
  
  <!-- use common launch file and pass all arguments to it -->
  <!-- <include file="$(find ur_description)/launch/load_ur.launch" pass_all_args="true"/> -->
</launch>

继续在这一个launch文件夹下复制view_ur5.launch,并且重命名为view_ur5_dh.launch,替换为以下内容:

<?xml version="1.0"?>
<launch>
  <include file="$(find ur_description)/launch/load_ur5_dh.launch"/>
 
  <node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" />
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(find ur_description)/cfg/view_robot.rviz" required="true" />
</launch>

找到ur_gazebo/launch,复制ur5_bringup.launch并且重命名为ur5_bringup_dh.launch,修改为以下内容:

<?xml version="1.0"?>
<launch>
<include file="$(find ur_description)/launch/load_ur5_dh.launch"/>
<rosparam file="$(find dh_robotics_ag95_gazebo)/controller/gripper_controller_dh_robotics.yaml" command="load"/>
<node name="arm_controller_spawner" pkg="controller_manager" type="controller_manager" args="spawn arm_controller gripper" respawn="false" output="screen"/>
<node name="gui_controller" pkg="rqt_joint_trajectory_controller" type="rqt_joint_trajectory_controller" />
 
  <!--Robot description and related parameter files -->
  <arg name="robot_description_file" default="$(dirname)/inc/load_ur5.launch.xml" doc="Launch file which populates the 'robot_description' parameter."/>
  <arg name="joint_limit_params" default="$(find ur_description)/config/ur5/joint_limits.yaml"/>
  <arg name="kinematics_params" default="$(find ur_description)/config/ur5/default_kinematics.yaml"/>
  <arg name="physical_params" default="$(find ur_description)/config/ur5/physical_parameters.yaml"/>
  <arg name="visual_params" default="$(find ur_description)/config/ur5/visual_parameters.yaml"/>
 
  <!-- Controller configuration -->
  <arg name="controller_config_file" default="$(find ur_gazebo)/config/ur5_controllers.yaml" doc="Config file used for defining the ROS-Control controllers."/>
  <arg name="controllers" default="joint_state_controller pos_joint_traj_controller" doc="Controllers that are activated by default."/>
  <arg name="stopped_controllers" default="joint_group_pos_controller" doc="Controllers that are initally loaded, but not started."/>
 
  <!-- robot_state_publisher configuration -->
  <arg name="tf_prefix" default="" doc="tf_prefix used for the robot."/>
  <arg name="tf_pub_rate" default="125" doc="Rate at which robot_state_publisher should publish transforms."/>
 
  <!-- Gazebo parameters -->
  <arg name="paused" default="false" doc="Starts Gazebo in paused mode" />
  <arg name="gui" default="true" doc="Starts Gazebo gui" />
 
  <!-- Load urdf on the parameter server -->
  <include file="$(arg robot_description_file)">
    <arg name="joint_limit_params" value="$(arg joint_limit_params)"/>
    <arg name="kinematics_params" value="$(arg kinematics_params)"/>
    <arg name="physical_params" value="$(arg physical_params)"/>
    <arg name="visual_params" value="$(arg visual_params)"/>
  </include>
 
  <!-- Robot state publisher -->
  <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher">
    <param name="publish_frequency" type="double" value="$(arg tf_pub_rate)" />
    <param name="tf_prefix" value="$(arg tf_prefix)" />
  </node>
 
  <!-- Start the 'driver' (ie: Gazebo in this case) -->
  <include file="$(dirname)/inc/ur_control.launch.xml">
    <arg name="controller_config_file" value="$(arg controller_config_file)"/>
    <arg name="controllers" value="$(arg controllers)"/>
    <arg name="gui" value="$(arg gui)"/>
    <arg name="paused" value="$(arg paused)"/>
    <arg name="stopped_controllers" value="$(arg stopped_controllers)"/>
  </include>
</launch>

最后进行编译一下,运行 roslaunch ur_description view_ur5_dh.launch 

三、报错解决

此时,如果顺利的话就结束了,但是,有的朋友会发现打开的rviz界面如下:

可以看到机械臂模型发生报错,找到终端查看错误,会发现报错如下:

这是因为joint_state_publisher_gui robot_state_publisher 也是 ROS 包的一部分,确保它们已正确安装,执行:

sudo apt install ros-noetic-joint-state-publisher ros-noetic-joint-state-publisher-gui ros-noetic-robot-state-publisher

然后重新编译,解决问题:

参考:

大佬


http://www.kler.cn/a/410851.html

相关文章:

  • 代码美学:MATLAB制作渐变色
  • 103.【C语言】数据结构之TopK问题详细分析
  • 现代密码学
  • uniapp vue2项目迁移vue3项目
  • Python人工智能项目报告
  • Spring Boot 应用开发:构建高效、可扩展的 Java 微服务
  • Amazon商品详情API接口:电商创新与用户体验的驱动力
  • 电子消费品生产线:科技的时尚,玛哈特矫平机为生产线打造平整面板
  • 【SpringBoot】MapStruct生成映射代码
  • 【论文笔记】Number it: Temporal Grounding Videos like Flipping Manga
  • Qt之QMainWidget相关
  • nohup java -jar supporterSys.jar --spring.profiles.active=prod
  • 5.算法移植第六篇YOLOV5 /onnx模型转换成rknn
  • Oracle 深入学习 Part 8: Managing Tablespaces and Data Files(管理表空间和数据文件)
  • Linux中的权限管理
  • 数据结构 ——— 快速排序算法的实现(hoare版本)
  • 贵州茅台[600519]行情数据接口
  • FFmpegFrameRecorder 切分视频文件时结束条件设置不当导致切分后的文件过短问题
  • 深度解析 Docker:重塑软件部署格局
  • Element UI 打包探索【1】
  • bridge-multicast-igmpsnooping
  • 第二十八章 TCP 客户端 服务器通信 - JOB命令示例
  • Python和R荧光分光光度法
  • 基于YOLOv8深度学习的农作物番茄成熟度检测系统研究与实现(PyQt5界面+数据集+训练代码)
  • jmeter基础06_(练习)常见的http请求
  • Reactor 模式的理论与实践