Home Programming

Discussion

Left ArrowBack to discussions page
bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
You may be interested in controlling from your PC Robotiq grippers (2F85, 2F140, Hand-e, ePick, airPick,...) using modbusTCP, Python and Robotiq universal controller.
I made a sample program which activate the gripper. I would like to share it with you.
I hope it will help in your projects !

For more details about how to control Robotiq gripper by reading and writing its memory registers, I recommend to check the user manual.

Comments

  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    Here is the Zip file with the python program.
  • s0972456s0972456 Unconfirmed Posts: 3 Apprentice
    Hi, could you also share a python program to open and close the e-pick gripper? thanks
  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    I will try to add this. Please give me some time to do that.
  • s0972456s0972456 Unconfirmed Posts: 3 Apprentice
    Thank you, that will be very helpful!
  • s0972456s0972456 Unconfirmed Posts: 3 Apprentice
    Hi, wonder if you have any update on that, still haven't figured out a way to control the epick remotely. Thanks
  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    s0972456 said:
    Hi, wonder if you have any update on that, still haven't figured out a way to control the epick remotely. Thanks
    I did not had time to work on this. Will try to do something next week.
  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    Sorry for waiting. I attach a simple program to control ePick using Modbus TCP.
    The program make a automatic grip followed by an automatic release.
    The user manual of ePick remain the best source of information to make this kind of control.
  • FanwangFanwang Unconfirmed Posts: 3 Apprentice
    Hi thank you for the code, I registered another account as for some reason I cannot post comment using my previous account.

    somehow I still cannot get the code to work, I use the robot’s IP address but I am reading just none from the register. If I delete the earlier print output part, I will be able to reach further and print out gripper status and gripper control, but the gripper itself doesn’t respond.

    I wonder whether this has anything to do with the fact that the gripper is connected to the wrist cable ? Should it be a different port then? I also tried to use a random ip but this time even printing gripper status and gripper control fails, so the IP address should be right.

    Any help will be greatly appreciated !
  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    This code will only work if your pc is connected to the gripper via a robotiq modbus tcp universal controller.

    Can you describe the connection between the gripper and the pc ?
    Also give ip of your pc ?
  • FanwangFanwang Unconfirmed Posts: 3 Apprentice
    I see, well I guess the TCP method wouldn't work on my setup. There is no physical form of connection between the gripper and the pc. The gripper is connected to the robot through the wrist cable, and the internet cable of the ur5 is connected to the same network switch where my pc's internet cable is connected to.

    My IP is 192.17.178.227, but I think it doesn't matter if the pc and the gripper is not connected?



  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    Unfortunatelly it cannot work with this setup.
  • FanwangFanwang Unconfirmed Posts: 3 Apprentice
    Thanks for the information though. Do you have other suggestions for driving the epick gripper with a python script? I hacked python_urx's code (send urscripts) that drives the parallel gripper to work on the epick, but it doesn't work completely as the gripper only stay on for a short period of time and shut down, I haven't figured out how to have it stay on until I turn it off.
  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    I am not familiar with this way to communicate with tools connected on ur controller.
    I imagine python code running on the controller should be able to controller gripper over modbus rtu.
  • nicolasmarcstephannicolasmarcstephan Posts: 5 Apprentice
    Hi!
    I'm experiencing some issues with your python script:
    I'm using a Hand-e gripper which is connected to my computer via USB. With the Robotiq User Interface I can access and control the gripper normally. But as soon as I try to use your Python script there seems to be no connection at all. I'm using pyCharm and have the pyModbusTCP library installed.

    I noticed that in the script you are not defining a serial port (like COM6 in my case) but an ip address. Does the gripper have its own ip address and if yes how can I find it? Or do you think there is a different problem?

    I would really appreciate your help!

  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    @nicolasmarcstephan
    This post is about communicating with a robotiq gripper in modbus TCP. It involve the use of a universal controller.

    I suppose that in your case you don't use a universal controller and have the gripper directly connected on your PC and try to communicate in Modbus RTU.

    You can check the following article to learn how to do that:
    https://dof.robotiq.com/discussion/1382/control-grippers-from-python-using-modbus-rtu#latest
  • TXSTUniTXSTUni Posts: 5 Apprentice
    Hi,
    When I run the code it says Module error: Cannot find 'PyModbus TCP'. your help would be appreciated. Thank you

  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    @TXSTUni
    pyModbusTCP is a python library that you need to install to be able to run this script.

    https://pypi.org/project/pyModbusTCP/

    You can PIP install it:
    sudo pip install pyModbusTCP

  • TXSTUniTXSTUni Posts: 5 Apprentice
    edited May 2021
    Hi,

    I was able to open and close the gripper using the activation gripper python code, thank you. 

    I have another question, how can I edit the code to close the gripper and not open it immediately?

    Thank you for your time.


  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    @TXSTUni

    This sample code activate the gripper. It is not a simple closing and opening.
    The gripper activation is necessary before doing any action with the gripper. During activation the gripper check what is its maximum and minimum opening position.

    To control the gripper, you need to read and write its modbus registers. Please check the section control of the manaul to learn more about modbus registers and gripper control.

    https://assets.robotiq.com/website-assets/support_documents/document/2F-85_2F-140_General_PDF_20200211.pdf
  • learningrobotlearningrobot Posts: 1 Recruit
    bcastets said:
    Here is the Zip file with the python program.
    Hi @bcastets
    In your sample, what is the driver for the gripper? Was it on Ubuntu or Windows? Is the code still working?
    I tried to follow the ROS library at http://wiki.ros.org/robotiq, but failed at Modbus TCP installation, as it said "Rosdep cannot find all required resouces of robotiq_modbus_tcp. How to configure it btw? 

    Thanks,
  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    I got a question from @rsalehzadeh in a private message about how to open and close the gripper using python and modbus TCP.
    From what I understand @rsalehzadeh manage to execute the code provided in this article and succesfully activate his gripper.

    To control the gripper you have to write what you want him to do in its memory registers. Those memory registers are described in the griper manual.

    Here below is a simple description of the program.

    First the Modbus TCP connection with the gripper is established.

    # Setup parameters of the Modbus TCP connection
    c = ModbusClient(host=MODBUS_SERVER_IP, port=502, auto_open=True)
    c.host(MODBUS_SERVER_IP)
    c.port(502)
    c.unit_id(9)
    #Open the connection with the gripper
    c.open()
    #Wait for the connection to establish
    time.sleep(5)

    Then some data in written gripper registers to initiate activation.

    #Write output register to request and activation
    response=c.write_multiple_registers(0,[0b0000000100000000,0,0])






    With this command, we write the 3 first registers. Each register is composed of 2 bytes.

    Registers 1 and 2 are set to 0. There is nothing specific we do with does registers. Just set it at 0.
    Register 0 is the important register here. In register 0, there are 2 bytes. Byte 1 is reserved which means that there is nothing we can do with it. Byte 0 is ACTION REQUEST Byte. The Bit 0 of ACTION REQUEST byte is the rACT bit which will trigger the gripper activation if it is set to 1. This is what we are doing here:

    response=c.write_multiple_registers(0,[0b0000000100000000,0,0])

    Register 0 : 00000001(Byte 0) 00000000(Byte1)
    Register 1 : 00000000(Byte 2) 00000000(Byte3)
    Register 2 : 00000000(Byte 4) 00000000(Byte5)

    Now, let's say that you want to move the gripper. If you read the documentation, you will learn that first the gripper needs to be activated. Then the request gripper position, speed and force needs to be set and the rGTO bit has to be set to 1.

    If I want to fully close the gripper at full speed and full force, I will have to write the following information in our registers.

    Register 0 : 00001001(Byte 0) 00000000(Byte1) -> rACT=1 AND rGTO=1
    Register 1 : 00000000(Byte 2) 11111111(Byte3) -> position_request=0b11111111=255
    Register 2 : 11111111(Byte 4) 11111111(Byte5) -> Speed=0b11111111=255 AND Force=0b11111111=255

    response=c.write_multiple_registers(0,[0b0000000100000000,0b0000000011111111,0b1111111111111111])

    I hope this will help.
  • rsalehzadehrsalehzadeh Posts: 2 Recruit
    bcastets 
    Thank you @ bcastets so much for the answer and detailed explanation. It was very helpful and understandable. I tried to close it using your instruction by the following code, but nothing happens after gripper activation (the gripper gets closed and opened once). Could you help me with this? What could be the reason for this?

    #Import libraries
    ##################
    from pyModbusTCP.client import ModbusClient
    import time

    #Initialize variables
    ##################
    executionTime=0
    MODBUS_SERVER_IP="10.139.0.101"

    #Process initialization
    ##################
    #communication
    # TCP auto connect on first modbus request
    c = ModbusClient(host=MODBUS_SERVER_IP, port=502, auto_open=True, unit_id=9)

    # managing TCP sessions with call to c.open()/c.close()
    c.open()

    #Wait for the connection to establish
    time.sleep(5)

    #Write output register to request and activation
    response=c.write_multiple_registers(0,[0b0000000100000000,0,0])
    print(response)

    #Give some time for the gripper to activate
    print("Gripper activate")
    time.sleep(5)

    response=c.write_multiple_registers(0,[0b0000000100000000,0b0000000011111111,0b1111111111111111])

    #Give some time for the gripper to reach the desired position
    print("Close Gripper")
    time.sleep(3)

    #close connection
    c.close()
    exit()
  • rsalehzadehrsalehzadeh Posts: 2 Recruit
    @bcastets

    I apologize for this. The system was frozen and probably I have posted the same comment several times.
    Also, there was a mistake in the value of register 0 byte zero that I fixed it. It works fine.

  • bcastetsbcastets Vacuum Beta tester Posts: 674 Expert
    @rsalehzadeh
    You but the rACT bit at 1 but you forgot to but the rGTO at 1. If the rGTO bit is at 0 the gripper will not go to the requested position.

    response=c.write_multiple_registers(0,[0b0000100100000000,0b0000000011111111,0b1111111111111111])


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