# Remote control of Robotiq Gripper connected to the UR5 via USB

**URL:** <https://forum.universal-robots.com/t/remote-control-of-robotiq-gripper-connected-to-the-ur5-via-usb/18269>\
**Category:** Technical Questions\
**Created:** [December 20, 2021, 12:43pm UTC](https://forum.universal-robots.com/t/remote-control-of-robotiq-gripper-connected-to-the-ur5-via-usb/18269 "2021-12-20T12:43:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon63743231](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@anon63743231](https://forum.universal-robots.com/u/anon63743231)\
**Post date:** [December 20, 2021, 12:43pm UTC](https://forum.universal-robots.com/t/remote-control-of-robotiq-gripper-connected-to-the-ur5-via-usb/18269/1 "2021-12-20T12:43:10Z")

</div>

Hello everyone,

Currently, we are trying to control the Robotiq Gripper which is connected via USB to a UR5 remotely using the Universal\_Robots\_ROS2\_Driver but couldn’t manage to do so. Regarding this topic, we would appreciate some instructions.

**Setup**

> PC OS: Ubuntu 20.4  
> ROS Distribution: Foxy  
> UR model: UR5

**What we tried**

Apart from using the ROS2 driver, we tried using the [URX library](https://github.com/SintefManufacturing/python-urx). The approach of this library is to connect via a TCP socket on port 30002 and send a URScript that controls the gripper. This was successful. But if we run the ROS2 driver and send a trajectory to the UR5n and start controlling the gripper using the URX library, the driver loses connection. This gets printed in the consol where the driver runs:

> [ros2\_control\_node-1] [INFO] [1638961383.669717614] [UR\_Client\_Library]: Connection to reverse interface dropped.

In order to make sure, there is nothing else happening in the URX library that distracts the ROS2 driver, we extracted a minimal example in python on how the gripper is controlled:

gripper\_control.py

> import socket  
> from time import sleep
> 
> HOST = “192.168.1.102”  
> SEC\_PORT = 50002
> 
> i\_sec = socket.create\_connection((HOST, SEC\_PORT), timeout=0.5)
> 
> with open(‘gripper\_close.txt’) as f:  
> close\_program = f.read()
> 
> i\_sec.send(str.encode(close\_program))

And this is the URScript that is loaded from ‘gripper\_close.txt’ (the code between myProg and end should be indented):

**gripper\_close.txt**

> def myProg():  
> socket\_close(“gripper\_socket”)  
> socket\_open(“127.0.0.1”,63352,“gripper\_socket”)  
> set\_analog\_inputrange(0,0)  
> set\_analog\_inputrange(1,0)  
> set\_analog\_inputrange(2,0)  
> set\_analog\_inputrange(3,0)  
> set\_analog\_outputdomain(0,0)  
> set\_analog\_outputdomain(1,0)  
> set\_tool\_voltage(0)  
> set\_runstate\_outputs()  
> set\_payload(0.85)  
> socket\_set\_var(“SPE”,255,“gripper\_socket”)  
> sync()  
> socket\_set\_var(“FOR”,50,“gripper\_socket”)  
> sync()  
> socket\_set\_var(“ACT”,1,“gripper\_socket”)  
> sync()  
> socket\_set\_var(“GTO”,1,“gripper\_socket”)  
> sync()  
> sleep(0.1)  
> socket\_set\_var(“POS”,255,“gripper\_socket”)  
> sync()  
> sleep(2.0)  
> end

Still with this minimal version, the ROS2 driver loses connection, when we run this example when sending a trajectory through the ros interface.

We haven’t tried that yet but we are also thinking about forwarding the port of the grippe (63352), so we can access it remotely.

**What we understand so far**

There are different ports used for communicating with the UR:

**50002** : primary interface, remote computer sends URScript to the UR that is interpreted by the URCap, 125Hz  
**50001** : UR requests the the remote computer to send URScript  
**30003** : UR sends the current status of the robot in real-time  
**30002** : secondary interface, remote computer sends URScript that contains commands that are not interfering with commands from the primary interface, 10Hz  
**54321** : port of the tool communication interface for a remote computer to use tools connected to the UR?, not available for the UR5 but for UR5e?

Is this interpretation correct? Is there anything else happening on these ports that is important for our problem?

We searched in the ROS2 driver repository for more clues on why using port 30002 from another program interferes with the ROS2 driver but we couldn’t find a clue. Maybe we missed something.

Ideally, we would like to use a controller with a topic where we can publish control messages for the Robotiq gripper.  
Is this possible or are there any other workarounds to achieve remote control of the gripper?

We would much appreciate some tips and explanations.
