Robotiq2FGripperStatusListener.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 Command-line interface for receiving and interpreting the status of a 2F gripper.
40 
41 This serves as an example for receiving messages from the 'Robotiq2FGripperRobotInput' topic using the 'Robotiq2FGripper_robot_input' msg type and interpreting the corresponding status of the 2F gripper.
42 """
43 
44 import roslib; roslib.load_manifest('robotiq_2f_gripper_control')
45 import rospy
46 from std_msgs.msg import String
47 from robotiq_2f_gripper_control.msg import _Robotiq2FGripper_robot_input as inputMsg
48 
49 def printStatus(status):
50  """Print the status string generated by the statusInterpreter function."""
51 
52  print statusInterpreter(status)
53 
55  """Initialize the node and subscribe to the Robotiq2FGripperRobotInput topic."""
56 
57  rospy.init_node('Robotiq2FGripperStatusListener')
58  rospy.Subscriber("Robotiq2FGripperRobotInput", inputMsg.Robotiq2FGripper_robot_input, printStatus)
59  rospy.spin()
60 
61 def statusInterpreter(status):
62  """Generate a string according to the current value of the status variables."""
63 
64  output = '\n-----\n2F gripper status interpreter\n-----\n'
65 
66  #gACT
67  output += 'gACT = ' + str(status.gACT) + ': '
68  if(status.gACT == 0):
69  output += 'Gripper reset\n'
70  if(status.gACT == 1):
71  output += 'Gripper activation\n'
72 
73  #gGTO
74  output += 'gGTO = ' + str(status.gGTO) + ': '
75  if(status.gGTO == 0):
76  output += 'Standby (or performing activation/automatic release)\n'
77  if(status.gGTO == 1):
78  output += 'Go to Position Request\n'
79 
80  #gSTA
81  output += 'gSTA = ' + str(status.gSTA) + ': '
82  if(status.gSTA == 0):
83  output += 'Gripper is in reset ( or automatic release ) state. see Fault Status if Gripper is activated\n'
84  if(status.gSTA == 1):
85  output += 'Activation in progress\n'
86  if(status.gSTA == 2):
87  output += 'Not used\n'
88  if(status.gSTA == 3):
89  output += 'Activation is completed\n'
90 
91  #gOBJ
92  output += 'gOBJ = ' + str(status.gOBJ) + ': '
93  if(status.gOBJ == 0):
94  output += 'Fingers are in motion (only meaningful if gGTO = 1)\n'
95  if(status.gOBJ == 1):
96  output += 'Fingers have stopped due to a contact while opening\n'
97  if(status.gOBJ == 2):
98  output += 'Fingers have stopped due to a contact while closing \n'
99  if(status.gOBJ == 3):
100  output += 'Fingers are at requested position\n'
101 
102  #gFLT
103  output += 'gFLT = ' + str(status.gFLT) + ': '
104  if(status.gFLT == 0x00):
105  output += 'No Fault\n'
106  if(status.gFLT == 0x05):
107  output += 'Priority Fault: Action delayed, initialization must be completed prior to action\n'
108  if(status.gFLT == 0x07):
109  output += 'Priority Fault: The activation bit must be set prior to action\n'
110  if(status.gFLT == 0x09):
111  output += 'Minor Fault: The communication chip is not ready (may be booting)\n'
112  if(status.gFLT == 0x0B):
113  output += 'Minor Fault: Automatic release in progress\n'
114  if(status.gFLT == 0x0E):
115  output += 'Major Fault: Overcurrent protection triggered\n'
116  if(status.gFLT == 0x0F):
117  output += 'Major Fault: Automatic release completed\n'
118 
119  #gPR
120  output += 'gPR = ' + str(status.gPR) + ': '
121  output += 'Echo of the requested position for the Gripper: ' + str(status.gPR) + '/255\n'
122 
123  #gPO
124  output += 'gPO = ' + str(status.gPO) + ': '
125  output += 'Position of Fingers: ' + str(status.gPO) + '/255\n'
126 
127  #gCU
128  output += 'gCU = ' + str(status.gCU) + ': '
129  output += 'Current of Fingers: ' + str(status.gCU * 10) + ' mA\n'
130 
131  return output
132 
133 if __name__ == '__main__':


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