Robotiq3FGripperTcpNode.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 3F gripper gripper using the Modbus TCP protocol.
40 
41 The script takes as an argument the IP address of the gripper. It initializes a baseRobotiq3FGripper 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 'Robotiq3FGripperRobotInput' topic using the 'Robotiq3FGripper_robot_input' msg type. The node subscribes to the 'Robotiq3FGripperRobotOutput' topic for new commands using the 'Robotiq3FGripper_robot_output' msg type. Examples are provided to control the gripper (Robotiq3FGripperSimpleController.py) and interpreting its status (Robotiq3FGripperStatusListener.py).
42 """
43 
44 import roslib;
45 
46 roslib.load_manifest('robotiq_3f_gripper_control')
47 roslib.load_manifest('robotiq_modbus_tcp')
48 import rospy
50 import robotiq_modbus_tcp.comModbusTcp
51 import sys
52 from robotiq_3f_gripper_articulated_msgs.msg import Robotiq3FGripperRobotInput
53 from robotiq_3f_gripper_articulated_msgs.msg import Robotiq3FGripperRobotOutput
54 
55 
56 def mainLoop(address):
57  # Gripper is a 3F gripper with a TCP connection
59  gripper.client = robotiq_modbus_tcp.comModbusTcp.communication()
60 
61  # We connect to the address received as an argument
62  gripper.client.connectToDevice(address)
63 
64  rospy.init_node('robotiq3FGripper')
65 
66  # The Gripper status is published on the topic named 'Robotiq3FGripperRobotInput'
67  pub = rospy.Publisher('Robotiq3FGripperRobotInput', Robotiq3FGripperRobotInput, queue_size=1)
68 
69  # The Gripper command is received from the topic named 'Robotiq3FGripperRobotOutput'
70  rospy.Subscriber('Robotiq3FGripperRobotOutput', Robotiq3FGripperRobotOutput, gripper.refreshCommand)
71 
72  # We loop
73  while not rospy.is_shutdown():
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 
88 if __name__ == '__main__':
89  try:
90  # TODO: Add verification that the argument is an IP address
91  mainLoop(sys.argv[1])
92  except rospy.ROSInterruptException:
93  pass


robotiq_3f_gripper_control
Author(s): Nicolas Lauzier (Robotiq inc.), Allison Thackston
autogenerated on Tue Jun 1 2021 02:29:58