|Note: The procedure is similar for controlling a Robotiq 3-Finger Gripper using the "robotiq_3f_gripper_control" package.|
|Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.|
Control of a 2-Finger Gripper using the Modbus RTU protocol (ros indigo and earlier releases)Description: This tutorial explains how to use the "robotiq_c_model_control" and "robotiq_modbus_tcp" packages to control an 2-Finger Gripper configured with the Modbus RTU protocol. Please visit this website for more information on the Robotiq Adaptive Robot Grippers.
Tutorial Level: BEGINNER
This tutorial assumes that you have connected a 2-Finger Gripper via the serial connection with a serial to USB converter to a USB port of your computer.
For connecting the gripper via the TCP protocol, see the tutorial on Control of a 3-Finger Gripper using the Modbus TCP Protocol.
To test your gripper and the serial interface you can try the windows driver as explained in the Robotiq software installation page.
It is assumed you have the robotiq_c_model_control package and the robotiq_modbus_rtu package installed for your ROS distribution (see the [[https://github.com/ros-industrial/robotiq || robotiq packages on ROS-I github).
Finally, make sure that the external dependency for the package "robotiq_modbus_tcp" has been installed. The dependency is the python package pyModbus. On Ubuntu Precise, it is simply installed using "rosdep install robotiq_modbus_tcp". On other systems, it can be installed using "easy_install -U pymodbus".
Configuring the serial port
To control the gripper over a serial port, you may need to give proper privileges to the user:
$ usermod -a -G dialout YOURUSERNAME
To find out the port on which the controller is connected, use:
dmesg | grep tty
It's probably something like ttyUSB0.
ROS Nodes to Control the Gripper
Run the 2-Finger Gripper Driver Node
The gripper is driven by the node "CModelRtuNode.py" contained in the package "robotiq_c_model_control". Note that "roscore" should be running prior to launching the driver node. The gripper device ID will also need to be provided as an argument. Thus, to know what is the device ID of your 2-finger gripper, one way is simply by typing "dmesg | grep ttyUSB" in a terminal right after the gripper was connected to the computer's USB port.
For example, the driver for controlling a 2-finger gripper having "ttyUSB0" as its device ID is launched using the following command:
rosrun robotiq_c_model_control CModelRtuNode.py /dev/ttyUSB0
Run the 2-Finger Gripper Simple Controller Node
The driver listens for messages on "CModelRobotOutput" using the "CModel_robot_output" msg type. The messages are interpreted and commands are sent to the gripper accordingly. A simple controller node is provided which can be run (in another terminal) using "rosrun robotiq_c_model_control CModelSimpleController.py"
The "CModel_robot_output" msg type is simply composed of the robot output variables described in the Robotiq 2-Finger Gripper Instruction Manual. The simple controller node can therefore be modified to send custom commands to the Gripper.
Run the 2-Finger Gripper Status Listener Node
In the package "robotiq_c_model_control", there is also a node for listening to and interpreting the status of the Gripper. The driver publishes the status of the Gripper on "CModelRobotInput" using the "CModel_robot_input" msg type. The msg type is composed of the robot input variables described in the Robotiq 2-Finger Gripper Instruction Manual. The status listener node can be run (in another terminal) using the following command: "rosrun robotiq_c_model_control CModelStatusListener.py".