Subscribe

Latest Blog Post

build your in-house robotic expertise program

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.

 

Download the Essential Guide to   Force Sensors in Robotics Research

 

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

Sneak Peek on the Upcoming Wrist Camera URCap Update for DoF Pros Only!

Hi Pros, I wanted to take a few minutes to talk about the upcoming release for the Wrist Camera URCap! We've noticed that a lot of people want to use the Wrist Camera to locate stock parts...Read more

Handy Helper Functions for Universal Robots

I thought that we might want a single thread where everyone can post up any handy little helper functions that they have developed over time that make programming and using the UR robots easier....Read more

Program speed

When the UR is in run mode, does the program speed slider default to 100%? Also, is there a way to use a script function of some sort to verify or set the speed slider to 100%? I am using the UR in a...Read more

Remote control of Universal Robots user interface

Hi. Has anyone tried to or does anyone know how to remote control Polyscope, the user interface of Universal robots? I’ve had the idea to install VNC server on a robot to be able to remote control...Read more