Home› Programming
Discussion
Back to discussions page
bcastets
Vacuum Beta tester Posts: 674 Expert
Control gripper using python and Modbus TCP |
2K views
|
Answered | |
/ Most recent by bcastets
in Programming
|
24 comments |

in Programming
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.
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.
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.
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 !
Can you describe the connection between the gripper and the pc ?
Also give ip of your pc ?
I imagine python code running on the controller should be able to controller gripper over modbus rtu.
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
When I run the code it says Module error: Cannot find 'PyModbus TCP'. your help would be appreciated. Thank you
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:
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.
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
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,
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.
#Open the connection with the gripper
c.open()
Then some data in written gripper registers to initiate 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.
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?
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.
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])