CModelStatusListener.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2012, Robotiq, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of Robotiq, Inc. nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 #
00035 # Copyright (c) 2012, Robotiq, Inc.
00036 # Revision $Id$
00037 
00038 """@package docstring
00039 Command-line interface for receiving and interpreting the status of a C-Model gripper.
00040 
00041 This serves as an example for receiving messages from the 'CModelRobotInput' topic using the 'CModel_robot_input' msg type and interpreting the corresponding status of the C-Model gripper.
00042 """
00043 
00044 import roslib; roslib.load_manifest('robotiq_c_model_control')
00045 import rospy
00046 from std_msgs.msg import String
00047 from robotiq_c_model_control.msg import _CModel_robot_input  as inputMsg
00048 
00049 def printStatus(status):
00050     """Print the status string generated by the statusInterpreter function."""
00051 
00052     print statusInterpreter(status)
00053 
00054 def CModelStatusListener():
00055     """Initialize the node and subscribe to the CModelRobotInput topic."""
00056 
00057     rospy.init_node('CModelStatusListener')
00058     rospy.Subscriber("CModelRobotInput", inputMsg.CModel_robot_input, printStatus)
00059     rospy.spin()
00060 
00061 def statusInterpreter(status):
00062     """Generate a string according to the current value of the status variables."""
00063 
00064     output = '\n-----\nC-Model status interpreter\n-----\n'
00065 
00066     #gACT
00067     output += 'gACT = ' + str(status.gACT) + ': '
00068     if(status.gACT == 0):
00069        output += 'Gripper reset\n'
00070     if(status.gACT == 1):
00071        output += 'Gripper activation\n'
00072 
00073     #gGTO
00074     output += 'gGTO = ' + str(status.gGTO) + ': '
00075     if(status.gGTO == 0):
00076         output += 'Standby (or performing activation/automatic release)\n'
00077     if(status.gGTO == 1):
00078         output += 'Go to Position Request\n'
00079 
00080     #gSTA
00081     output += 'gSTA = ' + str(status.gSTA) + ': '
00082     if(status.gSTA == 0):
00083         output += 'Gripper is in reset ( or automatic release ) state. see Fault Status if Gripper is activated\n'
00084     if(status.gSTA == 1):
00085         output += 'Activation in progress\n'
00086     if(status.gSTA == 2):
00087         output += 'Not used\n'
00088     if(status.gSTA == 3):
00089         output += 'Activation is completed\n'
00090 
00091     #gOBJ
00092     output += 'gOBJ = ' + str(status.gOBJ) + ': '
00093     if(status.gOBJ == 0):
00094         output += 'Fingers are in motion (only meaningful if gGTO = 1)\n'
00095     if(status.gOBJ == 1):
00096         output += 'Fingers have stopped due to a contact while opening\n'
00097     if(status.gOBJ == 2):
00098         output += 'Fingers have stopped due to a contact while closing \n'
00099     if(status.gOBJ == 3):
00100         output += 'Fingers are at requested position\n'
00101  
00102     #gFLT
00103     output += 'gFLT = ' + str(status.gFLT) + ': '
00104     if(status.gFLT == 0x00):
00105         output += 'No Fault\n'
00106     if(status.gFLT == 0x05):
00107         output += 'Priority Fault: Action delayed, initialization must be completed prior to action\n'
00108     if(status.gFLT == 0x07):
00109         output += 'Priority Fault: The activation bit must be set prior to action\n'
00110     if(status.gFLT == 0x09):
00111         output += 'Minor Fault: The communication chip is not ready (may be booting)\n'   
00112     if(status.gFLT == 0x0B):
00113         output += 'Minor Fault: Automatic release in progress\n'
00114     if(status.gFLT == 0x0E):
00115         output += 'Major Fault: Overcurrent protection triggered\n'
00116     if(status.gFLT == 0x0F):
00117         output += 'Major Fault: Automatic release completed\n'
00118 
00119     #gPR
00120     output += 'gPR = ' + str(status.gPR) + ': '
00121     output += 'Echo of the requested position for the Gripper: ' + str(status.gPR) + '/255\n'
00122 
00123     #gPO
00124     output += 'gPO = ' + str(status.gPO) + ': '
00125     output += 'Position of Fingers: ' + str(status.gPO) + '/255\n'
00126 
00127     #gCU
00128     output += 'gCU = ' + str(status.gCU) + ': '
00129     output += 'Current of Fingers: ' + str(status.gCU * 10) + ' mA\n'   
00130 
00131     return output
00132     
00133 if __name__ == '__main__':
00134     CModelStatusListener()


robotiq_c_model_control
Author(s): Nicolas Lauzier (Robotiq inc.)
autogenerated on Thu Jun 6 2019 17:58:00