baseCModel.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Robotiq, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Robotiq, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 #
00033 # Copyright (c) 2012, Robotiq, Inc.
00034 # Revision $Id$
00035 
00036 """@package docstring
00037 Module baseCModel: defines a base class for handling command and status of the Robotiq C-Model gripper. 
00038 
00039 After being instanciated, a 'client' member must be added to the object. This client depends on the communication protocol used by the Gripper. As an example, the ROS node 'CModelTcpNode.py' instanciate a robotiqBaseCModel and adds a client defined in the module comModbusTcp.
00040 """
00041 
00042 from   robotiq_c_model_control.msg import _CModel_robot_input  as inputMsg
00043 from   robotiq_c_model_control.msg import _CModel_robot_output as outputMsg
00044 
00045 class robotiqBaseCModel:
00046     """Base class (communication protocol agnostic) for sending commands and receiving the status of the Robotic C-Model gripper"""
00047 
00048     def __init__(self):
00049 
00050         #Initiate output message as an empty list
00051         self.message = []
00052 
00053         #Note: after the instantiation, a ".client" member must be added to the object
00054 
00055     def verifyCommand(self, command):
00056         """Function to verify that the value of each variable satisfy its limits."""
00057                 
00058         #Verify that each variable is in its correct range
00059         command.rACT = max(0, command.rACT)
00060         command.rACT = min(1, command.rACT)
00061         
00062         command.rGTO = max(0, command.rGTO)
00063         command.rGTO = min(1, command.rGTO)
00064 
00065         command.rATR = max(0, command.rATR)
00066         command.rATR = min(1, command.rATR)
00067         
00068         command.rPR  = max(0,   command.rPR)
00069         command.rPR  = min(255, command.rPR)    
00070 
00071         command.rSP  = max(0,   command.rSP)
00072         command.rSP  = min(255, command.rSP)    
00073 
00074         command.rFR  = max(0,   command.rFR)
00075         command.rFR  = min(255, command.rFR) 
00076         
00077         #Return the modified command
00078         return command
00079 
00080     def refreshCommand(self, command):
00081         """Function to update the command which will be sent during the next sendCommand() call."""
00082     
00083         #Limit the value of each variable
00084         command = self.verifyCommand(command)
00085 
00086         #Initiate command as an empty list
00087         self.message = []
00088 
00089         #Build the command with each output variable
00090         #To-Do: add verification that all variables are in their authorized range
00091         self.message.append(command.rACT + (command.rGTO << 3) + (command.rATR << 4))
00092         self.message.append(0)
00093         self.message.append(0)
00094         self.message.append(command.rPR)
00095         self.message.append(command.rSP)
00096         self.message.append(command.rFR)     
00097 
00098     def sendCommand(self):
00099         """Send the command to the Gripper."""    
00100         
00101         self.client.sendCommand(self.message)
00102 
00103     def getStatus(self):
00104         """Request the status from the gripper and return it in the CModel_robot_input msg type."""    
00105 
00106         #Acquire status from the Gripper
00107         status = self.client.getStatus(6);
00108 
00109         #Message to output
00110         message = inputMsg.CModel_robot_input()
00111 
00112         #Assign the values to their respective variables
00113         message.gACT = (status[0] >> 0) & 0x01;        
00114         message.gGTO = (status[0] >> 3) & 0x01;
00115         message.gSTA = (status[0] >> 4) & 0x03;
00116         message.gOBJ = (status[0] >> 6) & 0x03;
00117         message.gFLT =  status[2]
00118         message.gPR  =  status[3]
00119         message.gPO  =  status[4]
00120         message.gCU  =  status[5]       
00121 
00122         return message
00123         


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