Universal_Robots_ROS_Driver
Universal_Robots_ROS_Driver copied to clipboard
use ' /ur_hardware_interface/set_io'Service of ur_robot_driver to control the onrobot RG2
we want to use ' /ur_hardware_interface/set_io'Service of ur_robot_driver to control the onrobot RG2. TWO node had been created: Node one!
_#!/usr/bin/env python
import rospy
from ur_msgs.srv import *
from ur_msgs.msg import IOStates
class Gripper:
def __init__(self, service='/ur_hardware_interface/set_io'):
rospy.wait_for_service(service)
try:
self.set_io = rospy.ServiceProxy(service, SetIO)
print('Connected with service')
except rospy.ServiceException as e:
print('Service unavailable: %s'%e)
def open(self):
self.set_io(1, 7, 0)
self.set_io(1, 2, 0)
def close(self):
self.set_io(1, 7, 0)
self.set_io(1, 2, 1)
def grip_detect(self):
"""grasp success or not"""
# grip_detect_pin = 0
try:
return rospy.wait_for_message('/ur_hardware_interface/io_states', IOStates).digital_in_states[0].state
except rospy.ServiceException as e:
print('cannot get io states: %s'%e)_
Node two:
_#!/usr/bin/env python
import rospy
from gripper import Gripper
from std_msgs.msg import String
class GripperNode:
def __init__(self, service='/ur_hardware_interface/set_io'):
self.gripper = Gripper(service)
rospy.init_node('gripper_node', anonymous=True)
self.subscriber = rospy.Subscriber('/gripper/command', String, self.callback, queue_size=1)
self.time_wait = 0
print('Created gripper_node')
rospy.spin()
def callback(self, data):
if data.data == 'open':
self.gripper.open()
elif data.data == 'close':
self.gripper.close()
elif data.data == 'detect':
if self.gripper.grip_detect():
print 'grasp success'
else:
print "failed to grasp"
if __name__ == '__main__':
node = GripperNode()_
——-------------------------------------------------—— Sending commands directly to the service has also been tried!
_rosservice call /ur_hardware_interface/set_io 1 2 1
success: True_
But nothing happened!(NO error/warning), Please help me!
Could you please post the full output of the driver node?
This issue has not been updated for a long time. If no further updates are added, this will be closed automatically. Comment on the issue to prevent automatic closing.
This issue has been closed due to inactivity. Feel free to comment or reopen if this is still relevant.