Latest Blog Post

Controlling the Robotiq 2-Finger Gripper with MODBUS Commands in Python

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.

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.

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.

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, follow the link below.

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.