Left ArrowBack to discussions page
NaNNaN Posts: 4 Apprentice
I am able to open and close the 2F-85 gripper I have, which is mounted on an UR5, but am struggling to figure out how to read the gripper position.

Originally I had the USB-serial converter directly plugged into my computer and reading the gripper position (over /dev/ttyUSB0) was really easy (I used python, as per https://blog.robotiq.com/controlling-the-robotiq-2f-gripper-with-modbus-commands-in-python). However, then I could not coordinate the gripper with my UR5's movements.

Therefore I plugged the converter to the USB port within the UR5 control box, so that I can command the gripper in sync with the robot `movel` commands. I am able to open and close it using the library https://github.com/jkur/python-urx/blob/SW3.5/urx/robotiq_two_finger_gripper.py, or roughly:



        header = "def myProg():\n"
        prog = header
        prog += 'socket_open(\"{}\",{},\"{}\"\n)'.format("",
        prog += "socket_set_var(\"{}\",{},\"{}\")\n".format("ACT", 1,
        prog += "socket_set_var(\"{}\",{},\"{}\")\n".format("GTO", 1,

        if str(command) == 'open':
                msg = "socket_set_var(\"{}\",{},\"{}\")\n".format("POS", 0,
                msg = "socket_set_var(\"{}\",{},\"{}\")\n".format("POS", 1,
                prog += msg
        prog +=

However, the python-urx library leaves "getting the gripper status" as an exercise for the reader, and for the life of me I cannot figure out how to do it. I thought it would be so easy, since when I had it plugged into the laptop it was very straightforward. But now, I'm unclear how to read the data.

The library includes code to get the robot status (e.g. joint configuration, tool position), but as far as I can tell the robotiq gripper status is not included in that information.

Does anyone have python code for reading the gripper status over the UR5 tcp/ip protocol, or be able to give an example of how to do so?

Thank you!


  • NaNNaN Posts: 4 Apprentice
    And the data I can get via `self.get_all_data()` is:

    However, none of this appears to correlate to the gripper position.
    I'm wondering if perhaps I could issue

    and hope the textmsg will be picked up by get_all_data somehow? I really thought this would be straightforward...

  • NaNNaN Posts: 4 Apprentice
    Unfortunately, as mentioned, I am not connected directly to the gripper's usb-serial port (thus, communicating over /etc/ttyUSB0, which I did get working). Since I need to coordinate the gripper with the UR5 waypoints, which are a blended command (so several movel's in the same program, in the middle of which I open or close the gripper), I've plugged the gripper into the ur control box. However, now I cannot easily read the gripper position, or otherwise check if an object has been grasped.

    Thanks though! I will post back if/when I find a solution. At this point I'm almost entertaining putting on a esp8266 or nrf24l01 with a battery and a limit switch wedged between the the V linkages... but I'll give it another shot with setting an analogout or something to the gripper pos.
  • NaNNaN Posts: 4 Apprentice
    I've gotten the hack of using the analogOutput on the UR to report the gripper position to work. So, in URSCRIPT I have
    def myProg():

    Of course, this is actually streamed out on my end over python. For instance, using the python-urx library linked above,

    edit urx/urrobot.py

    After calling the above, I can use the python-urx library to read the analog port.
              data = rob.secmon.get_all_data(wait=False)


    As a documentation of the trouble shooting process:

    I downloaded the robotiq urcap (as per the "software" page) and used the ur pendant write short programs.
    I saved that program to a usb, and opened it in a text editor on my computer. There I found the functions (as described in the robotiq user manual pdf). For instance there is the function --
      def rq_current_pos(gripper_socket="1"):

    I also used liberally, textmsg() to write values to the pendant's log. This helped debug e.g. rq_current_pos_norm outputs between [0,100] and rq_pos as defined above outputs [0,255], whereas the set_standard_analog_out desires a value between [0,1]. On the other hand, when I am reading the analog output over the so-called "ur5 matlab interface / secondary monitor / port 3002", I will get a value between [0,10].

    I can also use the pendant to both view in the I/O tab, the "Analog Output', as well as drag the slider to make sure my state reader is behaving.
    Finally, I realized that I need to wait a little longer (~1 sec) to read the analogoutput, since I'm not waiting until the gripper has stopped moving (for now) to proceed.
    For instance,

            robotiqgrip.gripper_action(0) # open

    Now I can set my own threshold for whether an object has been picked up. Maybe in the future I will investigate the rest of the robotiq urcap functions, e.g. for object detection.

Sign In or Register to comment.
Left ArrowBack to discussions page