DoF - a Robotiq Community
Warning sign
The Dof Community was shut down in June 2023. This is a read-only archive.
If you have questions about Robotiq products please reach our support team.
bcastets

I would like to share with you some python code which can be use to control a gripper connected to a UR robot from an external PC using python and a socket connection.

The gripper URCAP works with a server running on the robot. The server receive the messages send by the program and manage the modbus RTU communication with the gripper.

It is possible to send message to the gripper URCAP server directly from a PC using a socket connection.

Here below is an example of python code to get the finger position:

#############################################################

#Library importation
import socket

#Socket setings
HOST="10.1.0.50" #replace by the IP address of the UR robot
PORT=63352 #PORT used by robotiq gripper

#Socket communication
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    #open the socket
    s.connect((HOST, PORT))
    s.sendall(b'GET POS\n')
    data = s.recv(2**10)

#Print finger position
#Gripper finger position is between 0 (Full open) and 255 (Full close)
print('Gripper finger position is: ', data)
#############################################################

As you can see it is quite simple. Just need to send "GET POS" to the URCAP server to get the gripper position.

The server can receive GET and SET requests.

Example of GET request:
GET POS

Example of SET request:
SET POS 100

Here below are some possible commands. Some commands can be use with both GET and SET:

ACT: Activation bit
0 - Gripper not activated
1 - Gripper activated
GTO: 1 if the gripper is set to move to requested position 0 if gripper is set to stay at the same place
PRE: Position request eco. Should be same a the requested position if
the gripper successfully received the requested position.
POS: Current position of the gripper
SPE: Speed eco. Should be same as requested speed.
FOR: Force parameter of the gripper
OBJ: Object grippings status
0 - Fingers are inmotion towards requested position.No object detected.
1 - Fingers have stopped due to a contact while opening before requested position.Object detected opening.
2 - Fingers have stopped due to a contact while closing before requested position.Object detected closing.
3 - Fingers are at requested position.No object detected or object has been loss / dropped.
STA: Gripper status, returns the current status & motion of theGripper fingers.
0 -Gripper is in reset ( or automatic release )state. See Fault Status if Gripper is activated.
1 - Activation in progress.
2 - Not used.
3 - Activation is completed.
MOD: ...
FLT: Fault status returns general errormessages that are useful for troubleshooting. Fault LED (red) is present on theGripper chassis,
LED can be blue, red or both and be solid or blinking.
0 - No fault (LED is blue)
Priority faults (LED is blue)
5 - Action delayed, activation (reactivation)must be completed prior to performing the action.
7 - The activation bit must be set prior to action.
Minor faults (LED continuous red)
8 -Maximum operating temperature exceeded,wait for cool-down.
9 No communication during at least 1 second.
Major faults (LED blinking red/blue) - Reset is required (rising edge on activation bit rACT needed).
10 - Underminimum operating voltage.
11- Automatic release in progress.
12- Internal fault; contact support@robotiq.com.
13 - Activation fault, verify that no interference or other error occurred.
14-Overcurrent triggered.
15- Automatic release completed.
MSC: Gripper maximym current.
COU: Gripper current.
NCY: Number of cycles performed by the gripper
DST: Gripper driver state
0 - Gripper Driver State : RQ_STATE_INIT
1 - Gripper Driver State : RQ_STATE_LISTEN
2 - Gripper Driver State : Q_STATE_READ_INFO
3 - Gripper Driver State : RQ_STATE_ACTIVATION
Other - Gripper Driver State : RQ_STATE_RUN
PCO: Gripper connection state
0 - Gripper Connection State : No connection problem detected
Other - Gripper Connection State : Connection problem detected


Similar post:
https://dof.robotiq.com/discussion/2291/send-and-get-data-from-ur-robot-and-control-robotiq-grippers-via-rtde-using-python-3-ur-rtde#latest

cwang344

Hi @bcastets, this looks fantastic. Does this method works on the Robotiq E-pick vaccum gripper? 

cwang344

Hi @bcastets I installed two grippers onto UR5e via socket connection using the adaptor plate. My questions is, does port 63352 point to both grippers? If yes, how can I write my code to control them separately? If not, what is the port for the other gripper?

Thanks.

cwang344

Hi @bcastets, this looks fantastic. Does this method works on the Robotiq E-pick vaccum gripper? 

aumax

hi
@bcastets I got this from this code.
Gripper finger position is:  b'POS ?\n'. 
it seems like some format error
Do you know why is that?

aumax

bcastets said:
@aumax
Could you precise how you are sending your code ?
@@bcastets
just follow the code above. what I used was ur3e and 2f-85 gripper and set ur to remote control

#Library importation
import socket

#Socket setings
HOST="192.168.12.101" #my ur ip 
PORT=63352 #PORT used by robotiq gripper

#Socket communication
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    #open the socket
    s.connect((HOST, PORT))
    s.sendall(b'GET POS\n')
    data = s.recv(2**10)

#Print finger position
#Gripper finger position is between 0 (Full open) and 255 (Full close)
print('Gripper finger position is: ', data)


and I got 


Gripper finger position is:  b'POS ?\n'.

and my question is: the ? should be something else, right? like 1 2 or something if it works correctly

aumax

hi
@bcastets I got this from this code.
Gripper finger position is:  b'POS ?\n'. it seems like some format errors
Do you know why is that?

nishantg96

aumax said:
hi
@bcastets I got this from this code.
Gripper finger position is:  b'POS ?\n'. it seems like some format errors
Do you know why is that?

@bcastets  Thank you for super easy approach! Works like a charm.
Has been a long time since the post went up but better late than never. Anyone facing problem where the output is something like this b'POS ?\n', make sure to check if the gripper ID is set to 1. In case it is not, either change it to 1 or additional steps would be required to send the commands along with the gripper ID.