Subscribe

Latest Blog Post

compare new collaborative robots

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

Lars Skovsgaard
by Lars Skovsgaard on Mar 29, 2016 7:00:00 AM

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.

 2F85140.png

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.

 cableconnections.jpg

 

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.

pythoncode.png

 

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.

Outputcode.png

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.

 

Force Sensors in Robotics Research: The Essential Guide

 

Lars-1.jpgLars 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.

 

 
x

Subscribe to Robotiq's Blog

Leave a comment

Lars Skovsgaard
Written 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.
Connect with the writer:

Related posts

Demo Week Highlights

What's trending on DoF this week? Demo week kick-off, circle move looped twice, security planes, use of Arduino to control...

Amanda Lee
By Amanda Lee - February 9, 2017
Trending on DoF This Week - Nov. 17

What's trending on DoF this week? Using one snapshot position to sort multiple parts, sampling rate for polishing, Revtech...

Amanda Lee
By Amanda Lee - November 17, 2016
Trending on DoF This Week - Nov. 10

What's trending on DoF this week? Screw insertion using Robotiq camera, Robotiq products weights, bottle packaging with UR and...

Amanda Lee
By Amanda Lee - November 10, 2016

How to control 2-Finger Gripper via MODBUS RTU ?

I and using 2-Finger Gripper and I want to control its position, force speed using MODBUS RTU.The gripper is connected to a Windows PC via a USB port and uses a USB to RS-485 converter.I'm writing...Read more

50 Different pallet layouts

I have an application where a UR10 is palletizing boxes. There is about 50 different sizes which means 50 different pallet layouts. Multiple box sizes a day so it is always changing. I am...Read more

2 Finger Gripper(85) on a Universal Robot 5

I need to have in ROS Gazebo and MoveIt an UR5 robot who has the Robotiq 2 Finger Gripper(85) in the simulation models. At the moment all I have is the UR5 model only for simulations. How do I add...Read more

open source robot arm

Hi everyone,  how can I get a low cost open source robot arm for my final year projet.Thanks.PRINCEWILL Read more