Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
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         
00051         self.message = []
00052 
00053         
00054 
00055     def verifyCommand(self, command):
00056         """Function to verify that the value of each variable satisfy its limits."""
00057                 
00058         
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         
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         
00084         command = self.verifyCommand(command)
00085 
00086         
00087         self.message = []
00088 
00089         
00090         
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         
00107         status = self.client.getStatus(6);
00108 
00109         
00110         message = inputMsg.CModel_robot_input()
00111 
00112         
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