Home Programming


Left ArrowBack to discussions page
bcastetsbcastets Vacuum Beta tester Posts: 398 Handy
edited October 2020 in Programming
I share with you a python program I did to control Robotiq grippers from a PC using Python and MODBUS RTU protocol.

The code is hosted on github:

I did this program after receiving several questions about how to connect our gripper on different robots, PC,... If you want to make such prooject, I recommend that you check the user manual (https://robotiq.com/support/2f-85-2f-140/downloads-instruction-manual-cb-series?document=). Everything is explain in details with examples.
Robotiq grippers are using MODBUS RTU protocol and can be control just by writing command in their registers. I used  minimalMobus library to write in gripper register and request actions.

I hope this will help to understand how its working.


  • nicolasmarcstephannicolasmarcstephan Posts: 5 Apprentice
    Thank you for referring me here @bcastets !

    You were right, this was exactly what I was looking for.
    But unfortunately also this code doesn't work for me. MinimalModbus is installed and I checked the Robotiq User Interface where it shows me that the port is COM6 and the slave number is 9. The gripper is sitting on a Robotiq wrist camera. Could this be the problem?

    This is the error message:

    MinimalModbus debug mode. Will write to instrument (expecting 17 bytes back): '\t\x03\x07Ð\x00\x06Ä\r' (09 03 07 D0 00 06 C4 0D)
    MinimalModbus debug mode. Clearing serial buffers for port COM6
    MinimalModbus debug mode. No sleep required before write. Time since previous read: 7298031.00 ms, minimum silent period: 2.01 ms.
    Traceback (most recent call last):
      File "...\pyRobotiqGripper-master\robotiqGripper.py", line 554, in <module>
        grip = RobotiqGripper("COM6")  # /dev/ttyUSB1
      File "...\pyRobotiqGripper-master\robotiqGripper.py", line 76, in __init__
      File "...\pyRobotiqGripper-master\robotiqGripper.py", line 235, in readAll
        registers = self.read_registers(2000, 6)
      File "...\pyRobotiqGripper-master\venv\lib\site-packages\minimalmodbus.py", line 844, in read_registers
        return self._generic_command(
      File "...\pyRobotiqGripper-master\venv\lib\site-packages\minimalmodbus.py", line 1170, in _generic_command
        payload_from_slave = self._perform_command(functioncode, payload_to_slave)
      File "...\pyRobotiqGripper-master\venv\lib\site-packages\minimalmodbus.py", line 1240, in _perform_command
        response = self._communicate(request, number_of_bytes_to_read)
      File "...\pyRobotiqGripper-master\venv\lib\site-packages\minimalmodbus.py", line 1406, in _communicate
        raise NoResponseError("No communication with the instrument (no answer)")
    minimalmodbus.NoResponseError: No communication with the instrument (no answer)
    MinimalModbus debug mode. Response from instrument: '' () (0 bytes), roundtrip time: 47.0 ms. Timeout for reading: 50.0 ms.

    Process finished with exit code 1

    Thank you so much for your help!

  • bcastetsbcastets Vacuum Beta tester Posts: 398 Handy
    edited February 18
    It is a bit complex to control the gripper through the wrist camera. I would recommend to separate the connection.

    You can mount a gripper coupling on top of the camera to separate communication.
  • nicolasmarcstephannicolasmarcstephan Posts: 5 Apprentice
    edited February 18
    Thank you for your answer.

    Is there an API for the wrist camera?
    Otherwise I will just use the gripper coupling.
  • bcastetsbcastets Vacuum Beta tester Posts: 398 Handy
    Unfortunately we don't have API our documentation to make advance control of the camera and connected components.
    The camera is made to be use in combinaison of UR robot and controlled via its URCAP on polyscope.
  • Ruben_SpeybrouckRuben_Speybrouck Posts: 12 Apprentice
    Hi again @bcastets

    I have gotten my robot working with the camera and urscript in python, things are starting to be awesome. 
    However, accessing the gripper is not working. 

    Does the modbus go over the ethernet cable I already have in place? How do I set this up on the robot and computer end? 
    Did I understand correctly that this will not work if the robot has the camera wrist? 

    I have also looked at the RTDE library you linked (https://sdurobotics.gitlab.io/ur_rtde/index.html) but I do not get this to work in pycharm. 
    Have you managed to get this library working? 
  • bcastetsbcastets Vacuum Beta tester Posts: 398 Handy
    It is challenging.
    The best reference for this is sdurobotics: https://sdurobotics.gitlab.io/ur_rtde/api/api.html#robotiq-gripper-api
    I never tried it but I think that if the system communicate with the gripper via RTDE it should work even if the gripper is mounted on the camera.

    This article is to control a gripper directly connected to a PC. In you case the gripper is connected to the camera and the camera is connected to the controller so it cannot work.

  • Ruben_SpeybrouckRuben_Speybrouck Posts: 12 Apprentice
    @bcastets Thank you for clarifying that. I found a guide online where the author makes a program on the pendant that drives the grippers, saves it to usb stick inserted in the pendant and then uses a socket command (send via python) to send the same program back to the robot to control the gripper. 

    It works as the robot executes the same script that was made on the pendant, and the pendant does manage to control the grippers. 

    The guide is here: http://axisnj.com/controlling-a-universal-robots-cobot-using-python/

    Sadly i must be doing it wrong as nothing happens. The author is a reseller so they do not actually share the code, i think they might just be baiting paid consultancy, but myself and I bet a lot of robotiq clients would be really happy to learn how to do this. I have several robots and it is really imperative that I get camera, robot and gripper controlled via openCV in python if I want to do advanced things. 

    Could this saved script trick work, do you know how to get this to work?  
  • bcastetsbcastets Vacuum Beta tester Posts: 398 Handy
    This method is described in this article:
    The gripper is controlled by sending UR script to UR interface. It is easy, it works but it is a bit slow because there is a lot of code to send for one action.

  • Ruben_SpeybrouckRuben_Speybrouck Posts: 12 Apprentice
    @bcastets once again you come to the rescue. Its a huge file to send for one command but I cannot say it is noticeably slow. THANK YOU for pointing me in the right direction! Seriously, thank you! 
Sign In or Register to comment.
Left ArrowBack to discussions page