机器人3D抓取避坑指南(一)——安装ur_robot_driver,驱动真实的ur5e机器人

1.安装ur_robot_driver

环境配置:Ubuntu16.04+ROS Kinetic

根据最新通告链接: Announcement: Universal Robots launches ROS driver.,ros发布了受UR官方支持的驱动程序ur_robot_driver,并宣布弃用ur_driver和ur_modern_driver。不过ur_robot_driver仅适用于控制器版本CB3 (with software version >= 3.7) 和e-Series (software >= 5.1)。

本文参考官方github文档Universal_Robots_ROS_Driver,采用源码编译的方式进行安装。

源文件编译

# source global ros
$ source /opt/ros/<your_ros_version>/setup.zsh

# create a catkin workspace
$ mkdir -p catkin_ws/src && cd catkin_ws

# clone the driver
$ git clone https://github.com/UniversalRobots/Universal_Robots_ROS_Driver.git src/Universal_Robots_ROS_Driver

# clone fork of the description. This is currently necessary, until the changes are merged upstream.
$ git clone -b calibration_devel https://github.com/fmauch/universal_robot.git src/fmauch_universal_robot

# install dependencies
$ sudo apt update -qq
$ rosdep update
$ rosdep install --from-paths src --ignore-src -y

# build the workspace
$ catkin_make

# activate the workspace (ie: source it)
$ source devel/setup.zsh

注意:
source devel/setup.bash只在当前终端生效,每次打开其他终端时都要重新source,这样比较麻烦。 解决方法:gedit ~/.zshrc,打开.zshrc文件,在文件底部添加source ~/path/to/ur5/devel/setup.bash,保存退出即可。

2. 仿真测试

首先安装一些包

sudo apt-get install \
  ros-kinetic-ur-gazebo \
  ros-kinetic-ur5-moveit-config \
  ros-kinetic-ur-kinematics
#打开终端,启动
roslaunch ur_e_gazebo ur5e.launch
#打开新终端
roslaunch ur5_e_moveit_config ur5_e_moveit_planning_execution.launch sim:=true
#再打开一个新终端
roslaunch ur5_moveit_config moveit_rviz.launch config:=true

注意:

若需要进行将关节角从[-2pi,2pi]约束到[-pi,pi],可以使用如下命令行,要确保Gazebo能正常运行

#打开终端,启动
roslaunch ur_e_gazebo ur5e.launch limited:=true
#打开新终端
roslaunch ur5_e_moveit_config ur5_e_moveit_planning_execution.launch sim:=true limited:=true
#再打开一个新终端
roslaunch ur5_moveit_config moveit_rviz.launch config:=true

拖动ur5的末端,按plan可以规划路径,按execute可以使UR5运动,在gazebo上也可以看到相同的运动效果。
在这里插入图片描述

3. 连接真实的ur机器人

3.1 安装externalcontrol

要在真正的机器人上使用ur_robot_driver,需要在ur机器人上安装externalcontrol-1.0.urcap,该文件位于Universal_Robots_ROS_Driver的resources文件夹内。注意:要安装此URCap,要求PolyScope的版本不得低于3.7。

安装步骤:

  1. 用U盘将此文件拷贝至机器人示教器的programs文件夹。
  2. 在欢迎屏幕上,选择Setup Robot,然后选择URCaps进入URCaps安装屏幕。
    在这里插入图片描述
    注意:
    UR5e界面和上述有所不同
  3. 单击底部的小加号以打开文件选择器。 在此处,可以看到存储在机器人程序文件夹或插入的USB驱动器中的所有urcap文件。 选择并打开externalcontrol-1.0.urcap文件,然后单击打开。 现在,您的URCaps视图应在活动的URCaps列表中显示External Control,点击右下角重启机器人。在这里插入图片描述
  4. 重新启动后,选择为机器人编程,在安装设置部分中找到External Control 。 然后设置外部PC的IP地址,本文设置为192.168.56.1 。请注意,机器人和外部PC必须位于同一网络中,理想情况下,彼此之间应直接连接,以最大程度地减少网络干扰。 自定义端口现在应该保持不变。
    在这里插入图片描述
  5. 要使用新的URCap,请创建一个新程序并将External Control程序节点插入到程序树中。
    在这里插入图片描述
    注意:
    UR5e在设置那里可以加载External Control程序!
    UR5e的机器人系统没有Structure这个选项,直接如下所示
    在这里插入图片描述
  6. 重新点击命令按钮,则会看到在安装中输入的设置。 检查它们是否正确,然后将程序保存,可以将程序命名为external_control.urp。 现在机器人可以与此驱动程序一起使用了。
    参考: Universal_Robots_ROS_Driver/ur_robot_driver/doc/install_urcap_cb3.md

3.2 网络配置

设置电脑主机静态IP.
IP地址: 192.168.56.1(必须和示教器的一样,不然运行External control还是有问题!!!

设置机器人静态IP. 设置机器人 ——> 设置网络菜单:
IP地址: 192.168.56.2
子网掩码:255.255.255.0
如果机器人似乎没有正确获取网络配置,请尝试重启控制器。
在这里插入图片描述
测试网络连接:

ping 192.168.56.2  #IP_OF_THE_ROBOT

会看到如下输出:
64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=0.518 ms
64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=0.259 ms
64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=0.282 ms
如果没有发生任何事情或引发错误,则无法从计算机访问机器人。

3.3 用ros驱动真实的ur5e机器人

警告:请将手放在急停按钮旁边,以防发生意外。

  1. 网线连接机器人和电脑,启动机器人。 打开电脑终端,启动机器人驱动程序。
  2. 打开电脑终端,启动机器人驱动程序。
roslaunch ur_robot_driver ur5_e_bringup.launch limited:=true robot_ip:=192.168.56.2 [reverse_port=REVERSE_PORT]
# "reverse_port" default="50001" 
#  limited:=true限制机器人关节运动范围 [-pi,pi],否则为 [-2pi, 2pi]
  1. 示教器,运行程序 —> 文件 —> 加载程序 —> 选择3.1 节保存的external_control.urp程序,打开—>运行。
    可以看到终端显示:
    [ INFO] : Robot mode is now POWER_ON
    [ INFO] : Robot mode is now IDLE
    [ INFO] : Robot mode is now RUNNING
    [ INFO]: Robot requested program
    [ INFO]: Sent program to robot
    [ INFO]: Robot ready to receive control commands.
    在这里插入图片描述
    注意:
    UR5e机器人不要设置成远程连接模式,需要设置成本地连接,这个和UR5配置ur_modern_driver不一样!
  2. 启动moveit和rviz,注意启动顺序不能变
# 新终端启动moveit  
roslaunch ur5_e_moveit_config ur5e_moveit_planning_execution.launch limited:=true
# 新终端启动rviz
roslaunch ur5_e_moveit_config moveit_rviz.launch config:=true

然后就可以拖动rviz中的ur5e的末端,plan然后execute控制真实的UR5e运动。注意在Rviz和Gazebo观察plan的运行轨迹,慎防撞击。

曾经踩过的坑
报错: [ERROR] : Action client not connected: /follow_joint_trajectory
解决:找到/ur5_moveit_config/config/controllers.yaml 文件,name: 后添加 scaled_pos_traj_controller

坑中之坑:上述修改方法会导致用gazebo仿真时报错
roslaunch ur_gazebo ur5.launch
roslaunch ur5_moveit_config ur5_moveit_planning_execution.launch limited:=true sim:=true
此时会报错: [ERROR] :Action client not connected: scaled_pos_traj_controller/follow_joint_trajectory
导致gazebo无法执行excuse
解决:保留源文件中的 - name:""
在文件后面添加:

- name: scaled_pos_traj_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

也即是保留原来的如下代码,只是在文件末尾进行添加

- name: ""
    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

4.抓取点位验证测试

4.1 获取机器人末端6D位姿

在使用moveit的逆解来对机械臂进行运动规划时候,是给机械臂输入末端的位置和姿态,其中位置是用x,y,z坐标来表示,姿态是使用四元数来表示。但是有时候想要根据机械臂目前的状态得到当前位姿,可以使用moveit的命令行工具或者直接在Rviz中查看。
命令行工具
首先启动MoveIt! 仿真环境接口,即自己使用的机械臂模型,例如:

roslaunch ur5_e_moveit_config demo.launch

启动moveit_commander命令行接口:

rosrun moveit_commander moveit_commander_cmdline.py

与机械臂的move_group节点建立连接:

use <group name>

为自己程序中设置的,例如我的是manipulator

现在就可以在此节点上执行命令了,current命令将会返回运动组的当前状态。包括关节的状态(关节1, 2, 3, ……)和末端的状态(px, py, pz, ox, oy, oz, ow)

可以看出当前状态信息:
在这里插入图片描述
Rviz中查看
你也可以在Rviz中查看末端执行器的位置姿态。打开连接树:【MotionPlanning】->【Scene Robot】->【Links】,可以查看每个连杆的位置姿态。
在这里插入图片描述

4.2 C++调用moveit控制UR5机器人运动

  1. 首先,创建一个新的功能包,来放置我们的代码:
$catkin_create_pkg puncture_demo catkin cmake_modules interactive_markers moveit_core moveit_ros_perception moveit_ros_planning_interface pluginlib roscpp std_msgs
  1. 在创建的功能包下创建puncture_demo.cpp文件;代码如下:
//punture_demo.cpp
#include <moveit/move_group_interface/move_group.h>
#include <moveit/planning_scene_interface/planning_scene_interface.h>
 
#include <moveit_msgs/DisplayRobotState.h> 
#include <moveit_msgs/DisplayTrajectory.h> 
#include <moveit_msgs/AttachedCollisionObject.h> 
#include <moveit_msgs/CollisionObject.h> 

int main(int argc, char **argv)
{
  ros::init(argc, argv, "movo_moveit");
  ros::NodeHandle node_handle; 
  ros::AsyncSpinner spinner(1);
  spinner.start();
 
  moveit::planning_interface::MoveGroup group("manipulator");//ur5对应moveit中选择的规划部分
 
  // 设置发送的数据,对应于moveit中的拖拽
  geometry_msgs::Pose target_pose1;
  
  target_pose1.orientation.x= -0.1993;
  target_pose1.orientation.y = 0.3054;
  target_pose1.orientation.z = -0.2284;
  target_pose1.orientation.w = 0.902;
 
  target_pose1.position.x = -0.2004;
  target_pose1.position.y = -1.0177;
  target_pose1.position.z = 1.56930;
 
  group.setPoseTarget(target_pose1);
  group.setMaxVelocityScalingFactor(0.02);
 
 
  // 进行运动规划,计算机器人移动到目标的运动轨迹,对应moveit中的plan按钮
  moveit::planning_interface::MoveGroup::Plan my_plan;
//bool success = (ptr_group->plan(my_plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS;
  bool success = group.plan(my_plan)== moveit::planning_interface::MoveItErrorCode::SUCCESS;;
 
  ROS_INFO("Visualizing plan 1 (pose goal) %s",success?"":"FAILED");   
 
  //让机械臂按照规划的轨迹开始运动,对应moveit中的execute。
  if(success)
      group.execute(my_plan);
 
///第二个位置
geometry_msgs::Pose target_pose2;

  target_pose2.orientation.x= -0.1993;
  target_pose2.orientation.y = 0.3054;
  target_pose2.orientation.z = -0.2284;
  target_pose2.orientation.w = 0.902;
 
  target_pose2.position.x = 0.096;
  target_pose2.position.y = -0.9618;
  target_pose2.position.z = 1.934;
 
  group.setPoseTarget(target_pose2);
  group.setMaxVelocityScalingFactor(0.02);
 
  // moveit::planning_interface::MoveGroup::Plan my_plan;
 
  // 进行运动规划,计算机器人移动到目标的运动轨迹,对应moveit中的plan按钮
  moveit::planning_interface::MoveGroup::Plan my_plan_1;
//bool success = (ptr_group->plan(my_plan_1) == moveit::planning_interface::MoveItErrorCode::SUCCESS;
  bool success1 = group.plan(my_plan_1)== moveit::planning_interface::MoveItErrorCode::SUCCESS;;
 
  ROS_INFO("Visualizing plan 1 (pose goal) %s",success?"":"FAILED");   
 
  //让机械臂按照规划的轨迹开始运动,对应moveit中的execute。
  if(success1)
      group.execute(my_plan_1);
第三个位置
geometry_msgs::Pose target_pose3;
  
  target_pose3.orientation.x= -0.1993;
  target_pose3.orientation.y = 0.3054;
  target_pose3.orientation.z = -0.2284;
  target_pose3.orientation.w = 0.902;
 
  target_pose3.position.x = 0.1219;
  target_pose3.position.y = -0.9801;
  target_pose3.position.z = 1.9163;
 
  group.setPoseTarget(target_pose3);
  group.setMaxVelocityScalingFactor(0.01);
 
 
  // 进行运动规划,计算机器人移动到目标的运动轨迹,对应moveit中的plan按钮
  moveit::planning_interface::MoveGroup::Plan my_plan_2;
//bool success = (ptr_group->plan(my_plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS;
  bool success2 = group.plan(my_plan_2)== moveit::planning_interface::MoveItErrorCode::SUCCESS;;
 
  ROS_INFO("Visualizing plan 1 (pose goal) %s",success?"":"FAILED");   
 
  //让机械臂按照规划的轨迹开始运动,对应moveit中的execute。
  if(success2)
      group.execute(my_plan_2);
  
  ros::shutdown(); 
  return 0;
}

注意:
程序控制机器人运动三个位置,分别为 target_pose1、 target_pose2、 target_pose3,可以通过4.1的办法获取;三段程序相同,对应的my_plan、my_plan_1、my_plan_2;success也需要修改。

  1. 更改puncture_demo功能包下的CMakeLists.txt文件
    将如下代码添加到下面:
add_executable(puncture_demo src/puncture_demo.cpp)
target_link_libraries(puncture_demo
  ${catkin_LIBRARIES} 
)

在工作空间catkin_ws下编译功能包:catkin_make
编译成功会在catkin_ws/devel/lib/puncture_demo/文件夹下出现执行文件puncture_demo文件
执行如下命令即可控制机器人运动:

$roslaunch ur_robot_driver ur5_e_bringup.launch limited:=true robot_ip:=192.168.56.2 [reverse_port=REVERSE_PORT]
# 新终端启动
$roslaunch ur5_e_moveit_config ur5e_moveit_planning_execution.launch limited:=true
# 新终端启动
$roslaunch ur5_e_moveit_config moveit_rviz.launch config:=true
# 新终端启动
$rosrun puncture_demo puncture_demo

注意:
需要Rviz里面仿真验证采集的3个6D位姿,进行路径规划没有差错时,才可以在真实机器人上面进行路径规划测试,最好在URsim里面也验证一下!

文件构成:
在这里插入图片描述

参考资料

  1. Jetson AGX Xavier避坑指南(四)——安装ur_robot_driver,驱动真实的ur5机器人
  2. ROS下使用moveit控制UR机械臂,moveit驱动真实机械臂
  3. ROS中查看机械臂当前位姿
  4. ROS试炼——UR5机器人配置、通讯、RVIZ-moveit控制、C++调用moveit控制
  5. Ubuntu16+ROS驱动UR机器人(仿真+实体)亲测
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值