baseRobotiq3FGripper.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Robotiq, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Robotiq, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 #
33 # Copyright (c) 2012, Robotiq, Inc.
34 # Revision $Id$
35 
36 """@package docstring
37 Module baseRobotiq3FGripper: defines a base class for handling command and status of the Robotiq 3F gripper gripper.
38 
39 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 'Robotiq3FGripperTcpNode.py' instanciate a robotiqbaseRobotiq3FGripper and adds a client defined in the module comModbusTcp.
40 """
41 
42 from robotiq_3f_gripper_articulated_msgs.msg import Robotiq3FGripperRobotInput
43 
44 
46  """Base class (communication protocol agnostic) for sending commands and receiving the status of the Robotic 3F gripper gripper."""
47 
48  def __init__(self):
49  # Initiate output message as an empty list
50  self.message = []
51 
52  # Note: after the instantiation, a ".client" member must be added to the object
53 
54  def verifyCommand(self, command):
55  """Function to verify that the value of each variable satisfy its limits."""
56 
57  # Verify that each variable is in its correct range
58  command.rACT = max(0, command.rACT)
59  command.rACT = min(1, command.rACT)
60 
61  command.rMOD = max(0, command.rMOD)
62  command.rMOD = min(3, command.rMOD)
63 
64  command.rGTO = max(0, command.rGTO)
65  command.rGTO = min(1, command.rGTO)
66 
67  command.rATR = max(0, command.rATR)
68  command.rATR = min(1, command.rATR)
69 
70  command.rGLV = max(0, command.rGLV)
71  command.rGLV = min(1, command.rGLV)
72 
73  command.rICF = max(0, command.rICF)
74  command.rICF = min(1, command.rICF)
75 
76  command.rICS = max(0, command.rICS)
77  command.rICS = min(1, command.rICS)
78 
79  command.rPRA = max(0, command.rPRA)
80  command.rPRA = min(255, command.rPRA)
81 
82  command.rSPA = max(0, command.rSPA)
83  command.rSPA = min(255, command.rSPA)
84 
85  command.rFRA = max(0, command.rFRA)
86  command.rFRA = min(255, command.rFRA)
87 
88  command.rPRB = max(0, command.rPRB)
89  command.rPRB = min(255, command.rPRB)
90 
91  command.rSPB = max(0, command.rSPB)
92  command.rSPB = min(255, command.rSPB)
93 
94  command.rFRB = max(0, command.rFRB)
95  command.rFRB = min(255, command.rFRB)
96 
97  command.rPRC = max(0, command.rPRC)
98  command.rPRC = min(255, command.rPRC)
99 
100  command.rSPC = max(0, command.rSPC)
101  command.rSPC = min(255, command.rSPC)
102 
103  command.rFRC = max(0, command.rFRC)
104  command.rFRC = min(255, command.rFRC)
105 
106  command.rPRS = max(0, command.rPRS)
107  command.rPRS = min(255, command.rPRS)
108 
109  command.rSPS = max(0, command.rSPS)
110  command.rSPS = min(255, command.rSPS)
111 
112  command.rFRS = max(0, command.rFRS)
113  command.rFRS = min(255, command.rFRS)
114 
115  # Return the modified command
116  return command
117 
118  def refreshCommand(self, command):
119  """Function to update the command which will be sent during the next sendCommand() call."""
120 
121  # Limit the value of each variable
122  command = self.verifyCommand(command)
123 
124  # Initiate command as an empty list
125  self.message = []
126 
127  # Build the command with each output variable
128  self.message.append(command.rACT + (command.rMOD << 1) + (command.rGTO << 3) + (command.rATR << 4))
129  self.message.append(command.rGLV + (command.rICF << 2) + (command.rICS << 3))
130  self.message.append(0)
131  self.message.append(command.rPRA)
132  self.message.append(command.rSPA)
133  self.message.append(command.rFRA)
134  self.message.append(command.rPRB)
135  self.message.append(command.rSPB)
136  self.message.append(command.rFRB)
137  self.message.append(command.rPRC)
138  self.message.append(command.rSPC)
139  self.message.append(command.rFRC)
140  self.message.append(command.rPRS)
141  self.message.append(command.rSPS)
142  self.message.append(command.rFRS)
143 
144  def sendCommand(self):
145  """Send the command to the Gripper."""
146 
147  self.client.sendCommand(self.message)
148 
149  def getStatus(self):
150  """Request the status from the gripper and return it in the Robotiq3FGripper_robot_input msg type."""
151 
152  # Acquire status from the Gripper
153  status = self.client.getStatus(16);
154 
155  # Message to output
156  message = Robotiq3FGripperRobotInput()
157 
158  # Assign the values to their respective variables
159  message.gACT = (status[0] >> 0) & 0x01;
160  message.gMOD = (status[0] >> 1) & 0x03;
161  message.gGTO = (status[0] >> 3) & 0x01;
162  message.gIMC = (status[0] >> 4) & 0x03;
163  message.gSTA = (status[0] >> 6) & 0x03;
164  message.gDTA = (status[1] >> 0) & 0x03;
165  message.gDTB = (status[1] >> 2) & 0x03;
166  message.gDTC = (status[1] >> 4) & 0x03;
167  message.gDTS = (status[1] >> 6) & 0x03;
168  message.gFLT = status[2]
169  message.gPRA = status[3]
170  message.gPOA = status[4]
171  message.gCUA = status[5]
172  message.gPRB = status[6]
173  message.gPOB = status[7]
174  message.gCUB = status[8]
175  message.gPRC = status[9]
176  message.gPOC = status[10]
177  message.gCUC = status[11]
178  message.gPRS = status[12]
179  message.gPOS = status[13]
180  message.gCUS = status[14]
181 
182  return message


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