Skip to content

Tutorial Control the Robotiq Grippers

Daniel Ordonez edited this page Jun 6, 2019 · 1 revision

Tutorial: Connect to Robotiq grippers through Modbus RTU

This tutorial covers the connection and control of both Robotiq grippers (85 and 150mm stroke ones) with a ROS computer through the Modbus RTU interface.

Preparation

Prior to executing control of the grippers make sure you have connected a 2-finger adaptive gripper model to a USB port of your computer. The RS-485 to USB converter ACC-ADT-USB-RS485 that comes by default when you order these grippers allow connecting the 2-finger gripper directly to a computer through a USB 2.0 port using Modbus RTU communication protocol.

Serial Port Configuration

To control the gripper over a serial port, you may need to give proper privileges to the user:

usermod -a -G dialout <YOUR_USERNAME>
# or try
sudo adduser <YOUR_USERNAME> dialout

To find out the port on which the controller is connected, use:

dmesg | grep tty

The output should look something similar to:

[####.#####] USB 1-2: FTDI USB Serial Device converter now attached to ttyUSB0

If no other USB device is around, the default port should be ttyUSB0. Note the port number since it will be used later.

Control Robotiq gripper/s

This package use a modified version of the waypointrobotics/robotiq_85_gripper that can be found in the robotiq_2finger_grippers folder of this project. The changes allow the control of both 140mm and 85mm stroke robotiq grippers though an actionlib client-server interaction (see actionlib documentation).

robotiq_actionlib_structure

The robotiq_2f_gripper_control package

This package contains all the necessary code required to control the 2-finger grippers through Modbus RTU. Let's test the connection and operation of one of your grippers. On a new terminal run the following line:

roslaunch robotiq_2f_gripper_control test_85mm_gripper.launch comport:="<YOUR GRIPPER TTY PORT>"

This launch file starts an action server and an example action client which recursively move the real gripper and update a simulated gripper model on rviz.

Node: robotiq_2f_action_server.py

This node takes as parameters:

  • comport: Communication port to which the gripper is connected.
  • baud: Communication baud rate (must be the same baud rate as configured on the gripper)
  • stroke: Stroke of the gripper which differentiates between the 85mm or 140mm model.
  • joint_name: Name of the gripper driver joint as defined in your robot URDF description. This parameter is used to publish the state of the gripper joint on the /joint_states topic.
  • rate: Frequency in Hz of send/request of data to the real gripper.

The node defines an instance of Robotiq2FingerGripperDriver which is the hardware interface between ROS and the gripper. It also starts a SimpleActionServer for the CommandRobotiqGripper.action (with action name: /command_robotiq_action) that waits until the gripper is initialized and ready to take commands, to start and listen for new Goals.

A launch file (robotiq_action_server) wraps this node and can be used as in the following example:

    < !-- Launch action server for gripper -->
    <include file="$(find robotiq_2f_gripper_control)/launch/robotiq_action_server.launch">
        <arg name="comport" value="/dev/ttyUSB1"/>
        <arg name="baud" value="115200"/>
        <arg name="stroke" value="0.085"/>
        <arg name="joint_name" value="finger_joint"/>
        <arg name="verbose" value="true"/>
    </include>

Operate gripper through an instance of a SimpleActionClient

An example action client implementation is provided on the script robotiq_2f_action_client_example.py, showing how to initialize the client, create custom goals, and use predefined functions for fast control of the gripper, position, speed and force. But basically you just need to:

Python example

Import the Action messages and actionlib library

import actionlib
from robotiq_2f_gripper_msgs.msg import CommandRobotiqGripperFeedback, CommandRobotiqGripperResult, CommandRobotiqGripperAction, CommandRobotiqGripperGoal
from robotiq_2f_gripper_control.robotiq_2f_gripper_driver import Robotiq2FingerGripperDriver as Robotiq

Instantiate the action client

action_name = 'command_robotiq_action'    # Use your action server namespace if necesary
# Create an action client
robotiq_client = actionlib.SimpleActionClient(action_name, CommandRobotiqGripperAction)   
# Wait until grippers are ready to take command (communication is stablished and gripper is activated)
robotiq_client.wait_for_server()   

Command your robotiq gripper

# Use pre-defined functions for robot gripper manipulation.
Robotiq.close(robotiq_client, block=True)   # Close and wait until completion
Robotiq.open(robotiq_client, block=False)   # Open and do not block thread while completing goal
Robotiq.goto(robotiq_client, pos=0.04, speed=0.1, force=10, block=True)  # Send command Pose[m], speed[m/s], force [N]
Robotiq.emergency_release(robotiq_client)   # Slowly open gripper and deactivate it

Dual/Multiple Gripper Control

To control multiple grippers simultaneously you need to correctly namespace the grippers Action service and client nodes. A correct example is provided in the robotiq_dual_action_server.launch file.