Robotiq2FGripperTcpNode.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2012, Robotiq, Inc.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of Robotiq, Inc. nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 # Copyright (c) 2012, Robotiq, Inc.
36 # Revision $Id$
37 
38 """@package docstring
39 ROS node for controling a Robotiq 2F gripper using the Modbus TCP protocol.
40 
41 The script takes as an argument the IP address of the gripper. It initializes a baseRobotiq2FGripper object and adds a comModbusTcp client to it. It then loops forever, reading the gripper status and updating its command. The gripper status is published on the 'Robotiq2FGripperRobotInput' topic using the 'Robotiq2FGripper_robot_input' msg type. The node subscribes to the 'Robotiq2FGripperRobotOutput' topic for new commands using the 'Robotiq2FGripper_robot_output' msg type. Examples are provided to control the gripper (Robotiq2FGripperSimpleController.py) and interpreting its status (Robotiq2FGripperStatusListener.py).
42 """
43 
44 import roslib; roslib.load_manifest('robotiq_2f_gripper_control')
45 roslib.load_manifest('robotiq_modbus_tcp')
46 import rospy
48 import robotiq_modbus_tcp.comModbusTcp
49 import os, sys
50 from robotiq_2f_gripper_control.msg import _Robotiq2FGripper_robot_input as inputMsg
51 from robotiq_2f_gripper_control.msg import _Robotiq2FGripper_robot_output as outputMsg
52 
53 def mainLoop(address):
54 
55  #Gripper is a 2F with a TCP connection
57  gripper.client = robotiq_modbus_tcp.comModbusTcp.communication()
58 
59  #We connect to the address received as an argument
60  gripper.client.connectToDevice(address)
61 
62  rospy.init_node('robotiq2FGripper')
63 
64  #The Gripper status is published on the topic named 'Robotiq2FGripperRobotInput'
65  pub = rospy.Publisher('Robotiq2FGripperRobotInput', inputMsg.Robotiq2FGripper_robot_input)
66 
67  #The Gripper command is received from the topic named 'Robotiq2FGripperRobotOutput'
68  rospy.Subscriber('Robotiq2FGripperRobotOutput', outputMsg.Robotiq2FGripper_robot_output, gripper.refreshCommand)
69 
70 
71  #We loop
72  while not rospy.is_shutdown():
73 
74  #Get and publish the Gripper status
75  status = gripper.getStatus()
76  pub.publish(status)
77 
78  #Wait a little
79  rospy.sleep(0.05)
80 
81  #Send the most recent command
82  gripper.sendCommand()
83 
84  #Wait a little
85  rospy.sleep(0.05)
86 
87 if __name__ == '__main__':
88  try:
89  #TODO: Add verification that the argument is an IP address
90  mainLoop(sys.argv[1])
91  except rospy.ROSInterruptException: pass


robotiq_2f_gripper_control
Author(s): Nicolas Lauzier (Robotiq inc.)
autogenerated on Tue Jun 1 2021 02:29:54