DoF - a Robotiq Community
Warning sign
The Dof Community was shut down in June 2023. This is a read-only archive.
If you have questions about Robotiq products please reach our support team.
Olivier_Grenier

You can create robotic applications from many programming languages, as explored in this post by Alex Owen-Hill titled What is the Best Programming Language for Robotics? Normally the equipment you will be using will dictate somewhat the language you will use. This article presents example code for controlling a Robotq 2F Gripper with MODBUS RTU commands from a computer with a program created in Python.


 2F85140png


APPLICATION DESCRIPTION

In this example the 2F Robotiq Gripper is connected to a Windows PC via a USB port and uses a USB to RS-485 converter. This has been chosen since the Gripper uses this industrial RS-485 interface standard.


 cableconnectionsjpg

 

Robotiq’s manuals for its products and for the 2F Gripper can be found at this link

In the Robotiq instruction manual you can find explanations for the electrical and programming features of the Gripper. So, this article will concentrate on how the Gripper can be controlled from a Python program. The manual also has information for learning about the MODBUS format.

The Robotiq manual shows different MODBUS RTU commands and this example will use two commands for opening and closing the Gripper. It is important to note that an activation request must be sent prior to any command, thus you have below an activation request and a request for opening and closing the Gripper with MODBUS RTU commands.

Activation request:                    09 10 03 E8 00 03 06 00 00 00 00 00 00 73 30

Closing the Gripper:                  09 10 03 E8 00 03 06 09 00 00 FF FF FF 42 29

Opening the Gripper:                 09 10 03 E8 00 03 06 09 00 00 00 FF FF 72 19

 

PROGRAM DESCRIPTION:

Here is an example using a Python program for controlling the Gripper. In this example, the USB to RS-485 converter is plugged into a PC and has acquired the address COM14 which is used in the program for serial communication to the Gripper. The data flow is set up using the standard the Robotiq Gripper uses: 115200 Baud. The first ‘While’ loop only runs one time and this loop initializes the Gripper. Then it sends a command to the Gripper for an “Activation request” followed by a “Status request”. The second ‘While’ loop continues as long the program is active and toggles between opening and closing the Gripper at 2 second intervals.


pythoncodepng

The Python code in plain text format is:

import serial
import time
import binascii
ser = serial.Serial(port='COM14',baudrate=115200,timeout=1, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS)
counter = 0
while counter < 1:
   counter = counter + 1
   ser.write("\x09\x10\x03\xE8\x00\x03\x06\x00\x00\x00\x00\x00\x00\x73\x30")
   data_raw = ser.readline()
   print(data_raw)
   data = binascii.hexlify(data_raw)
   print "Response 1 ", data
   time.sleep(0.01)
 
   ser.write("\x09\x03\x07\xD0\x00\x01\x85\xCF")
   data_raw = ser.readline()
   print(data_raw)
   data = binascii.hexlify(data_raw)
   print "Response 2 ", data
   time.sleep(1)
 
while(True):
   print "Close gripper"
   ser.write("\x09\x10\x03\xE8\x00\x03\x06\x09\x00\x00\xFF\xFF\xFF\x42\x29")
   data_raw = ser.readline()
   print(data_raw)
   data = binascii.hexlify(data_raw)
   print "Response 3 ", data
   time.sleep(2)
 
   print "Open gripper"
   ser.write("\x09\x10\x03\xE8\x00\x03\x06\x09\x00\x00\x00\xFF\xFF\x72\x19")
   data_raw = ser.readline()
   print(data_raw)
   data = binascii.hexlify(data_raw)
   print "Response 4 ", data
  time.sleep(2)

Output when the program is run.

Outputcodepng


Notice the response that confirms that the action has been executed. The characters that look like gibberish above are because the data received from the Gripper is binary. The binary data is converted to ascii by = binascii.hexlify.

So feel free to use the Python code above for a demonstration of the 2F Gripper which generates a constant opening and closing sequence at 2 second intervals. For other code examples, like a pick and place application with UR visit my forum. And for more information about integrating a force torque sensor into the works, download the Essential Guide to Force Sensors in Robotics Research.

This answer was originally posted in Robotiq's blog by Lars Skovsgaard.

Lars Skovsgaard is Managing Director of  Zacobria Pte. Ltd. an accredited Universal Robots support Centre and Forum, as well as an authorized Robotiq and MIR distributor.

Disclaimer: While the Zacobria Pte. Ltd. believes that information and guidance provided is correct, parties must rely upon their skill and judgement when making use of them. Zacobria Pte. Ltd. assumes no liability for loss or damage caused by error or omission, whether such an error or omission is the result of negligence or any other cause. Where reference is made to legislation it is not to be considered as legal advice. Any and all such liability is disclaimed.

If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.