Home› Programming
Discussion
Back to discussions page
bcastets
Vacuum Beta tester Posts: 673 Expert
Control Robotiq gripper mounted on UR robot via Socket communication (python) |
2.2K views
|
Answered | |
/ Most recent by nishantg96
in Programming
|
14 comments |

in Programming
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:
#############################################################
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:
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
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)
#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 [email protected]
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
Tagged:
I can perform almost everything! Thank you so much!
Thank you for your feedback.
Happy to know that it helps !
It would work as well but the but the commands send to the server will be different. You can check what would be the commands in the .script file of your program in the definition of Vacuum functions.
Thanks.
What you can make a simple program with an action with gripper 1 and an action with gripper 2 using the Robotiq URCAP node. Save this program and check the script version. You should have some hints in the script explaining how to select a gripper before requesting an action.
ex
Note that ID1 in polyscope represent ID9 in socket communication(default)
Here's the full list
drivergripper SET/GET commands SET commands :
ACT activateRequest
MOD gripperMode
GTO goto
ATR automaticReleaseRoutine
ARD autoreleaseDirection
MSC maxPeakSupplyCurrent
POS positionRequest
SPE speedRequest
FOR forceRequest
SCN_BLOCK scanBlockRequest
SCN scanRequest
NID updateGripperSlaveId
SID socketSlaveId
GET commands :
ACT activateRequest
MOD gripperMode
GTO goto
STA status
VST vacuumStatus
OBJ objectDetected
FLT fault
MSC maxPeakSupplyCurrent
PRE positionRequestEcho
POS positionRequest
COU motorCurrent
SNU serialNumber
PYE productionYear
NCY numberOfCycles
PON numberOfSecondsPumpIsOn
NPA numberOfPumpActivations
FWV firmwareVersion
VER driverVersion
SPE speedRequest
FOR forceRequest
DRI printableState
SID socketSlaveId
Integration Coach
@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?
Could you precise how you are sending your code ?
just follow the code above. what I used was ur3e and 2f-85 gripper and set ur to remote control
#Gripper finger position is between 0 (Full open) and 255 (Full close)
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
You are right. If it works you should have something like POS 25 (value should be between 0 and 255).
I don't have the capability to make this test at the moment.
@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?