Home Programming

Discussion

Left ArrowBack to discussions page
bcastetsbcastets Vacuum Beta tester Posts: 673 Expert
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 [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

Comments

  • FabioFabio Unconfirmed Posts: 1 Recruit
    edited July 2021
    Fantastic, this is exactly what I was looking for! I have had many issues while connecting through python and this works.
    I can perform almost everything! Thank you so much!
  • bcastetsbcastets Vacuum Beta tester Posts: 673 Expert
    @Fabio
    Thank you for your feedback.
    Happy to know that it helps !
  • cwang344cwang344 Posts: 4 Apprentice
    Hi @bcastets, this looks fantastic. Does this method works on the Robotiq E-pick vaccum gripper? 
  • bcastetsbcastets Vacuum Beta tester Posts: 673 Expert
    @cwang344
    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.
  • cwang344cwang344 Posts: 4 Apprentice
    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.
  • bcastetsbcastets Vacuum Beta tester Posts: 673 Expert
    That is a good question. I think it goes through the same port. The switch between gripper is probably done through some commadn send to the URCAP server.

    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.
  • David_GariepyDavid_Gariepy Beta Tester Beetle, Wrist Camera URCap 1.3.0, Vacuum Beta tester Posts: 190 Handy
    It is possible to select which gripper to send the command to by using the command sid followed by the gripper id.
    ex
    sid2 (will send commands to gripper with ID 2
    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
    David Gariépy
    Integration Coach
  • cwang344cwang344 Posts: 4 Apprentice
    Hi @bcastets, this looks fantastic. Does this method works on the Robotiq E-pick vaccum gripper? 
  • aumaxaumax Posts: 5 Apprentice
    edited November 2021
    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?
  • bcastetsbcastets Vacuum Beta tester Posts: 673 Expert
    @aumax
    Could you precise how you are sending your code ?
  • aumaxaumax Posts: 5 Apprentice
    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

  • bcastetsbcastets Vacuum Beta tester Posts: 673 Expert
    @aumax

    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.
  • aumaxaumax Posts: 5 Apprentice
    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?
  • nishantg96nishantg96 Unconfirmed Posts: 1 Recruit
    edited June 2022
    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.

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