Universal_Robots_ROS_Driver icon indicating copy to clipboard operation
Universal_Robots_ROS_Driver copied to clipboard

use ' /ur_hardware_interface/set_io'Service of ur_robot_driver to control the onrobot RG2

Open sunnymints opened this issue 3 years ago • 1 comments

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!

sunnymints avatar Dec 24 '21 12:12 sunnymints

Could you please post the full output of the driver node?

fmauch avatar Jan 14 '22 14:01 fmauch

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.

github-actions[bot] avatar Feb 27 '23 22:02 github-actions[bot]

This issue has been closed due to inactivity. Feel free to comment or reopen if this is still relevant.

github-actions[bot] avatar Mar 30 '23 22:03 github-actions[bot]