Robotiq3FGripperSimpleController.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2012, Robotiq, Inc.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of Robotiq, Inc. nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 #
36 # Copyright (c) 2012, Robotiq, Inc.
37 # Revision $Id$
38 
39 """@package docstring
40 Command-line interface for sending simple commands to a ROS node controlling a 3F gripper gripper.
41 
42 This serves as an example for publishing messages on the 'Robotiq3FGripperRobotOutput' topic using the 'Robotiq3FGripper_robot_output' msg type for sending commands to a 3F gripper gripper. In this example, only the simple control mode is implemented. For using the advanced control mode, please refer to the Robotiq support website (support.robotiq.com).
43 """
44 
45 from __future__ import print_function
46 
47 import roslib;
48 
49 roslib.load_manifest('robotiq_3f_gripper_control')
50 import rospy
51 from robotiq_3f_gripper_articulated_msgs.msg import Robotiq3FGripperRobotOutput
52 
53 
54 def genCommand(char, command):
55  """Update the command according to the character entered by the user."""
56 
57  if char == 'a':
58  command = Robotiq3FGripperRobotOutput();
59  command.rACT = 1
60  command.rGTO = 1
61  command.rSPA = 255
62  command.rFRA = 150
63 
64  if char == 'r':
65  command = Robotiq3FGripperRobotOutput();
66  command.rACT = 0
67 
68  if char == 'c':
69  command.rPRA = 255
70 
71  if char == 'o':
72  command.rPRA = 0
73 
74  if char == 'b':
75  command.rMOD = 0
76 
77  if char == 'p':
78  command.rMOD = 1
79 
80  if char == 'w':
81  command.rMOD = 2
82 
83  if char == 's':
84  command.rMOD = 3
85 
86  # If the command entered is a int, assign this value to rPRA
87  try:
88  command.rPRA = int(char)
89  if command.rPRA > 255:
90  command.rPRA = 255
91  if command.rPRA < 0:
92  command.rPRA = 0
93  except ValueError:
94  pass
95 
96  if char == 'f':
97  command.rSPA += 25
98  if command.rSPA > 255:
99  command.rSPA = 255
100 
101  if char == 'l':
102  command.rSPA -= 25
103  if command.rSPA < 0:
104  command.rSPA = 0
105 
106  if char == 'i':
107  command.rFRA += 25
108  if command.rFRA > 255:
109  command.rFRA = 255
110 
111  if char == 'd':
112  command.rFRA -= 25
113  if command.rFRA < 0:
114  command.rFRA = 0
115 
116  return command
117 
118 
119 def askForCommand(command):
120  """Ask the user for a command to send to the gripper."""
121 
122  currentCommand = 'Simple 3F gripper Controller\n-----\nCurrent command:'
123  currentCommand += ' rACT = ' + str(command.rACT)
124  currentCommand += ', rMOD = ' + str(command.rMOD)
125  currentCommand += ', rGTO = ' + str(command.rGTO)
126  currentCommand += ', rATR = ' + str(command.rATR)
127  ## currentCommand += ', rGLV = ' + str(command.rGLV)
128  ## currentCommand += ', rICF = ' + str(command.rICF)
129  ## currentCommand += ', rICS = ' + str(command.rICS)
130  currentCommand += ', rPRA = ' + str(command.rPRA)
131  currentCommand += ', rSPA = ' + str(command.rSPA)
132  currentCommand += ', rFRA = ' + str(command.rFRA)
133 
134  # We only show the simple control mode
135  ## currentCommand += ', rPRB = ' + str(command.rPRB)
136  ## currentCommand += ', rSPB = ' + str(command.rSPB)
137  ## currentCommand += ', rFRB = ' + str(command.rFRB)
138  ## currentCommand += ', rPRC = ' + str(command.rPRC)
139  ## currentCommand += ', rSPC = ' + str(command.rSPC)
140  ## currentCommand += ', rFRC = ' + str(command.rFRC)
141  ## currentCommand += ', rPRS = ' + str(command.rPRS)
142  ## currentCommand += ', rSPS = ' + str(command.rSPS)
143  ## currentCommand += ', rFRS = ' + str(command.rFRS)
144 
145  print(currentCommand)
146 
147  strAskForCommand = '-----\nAvailable commands\n\n'
148  strAskForCommand += 'r: Reset\n'
149  strAskForCommand += 'a: Activate\n'
150  strAskForCommand += 'c: Close\n'
151  strAskForCommand += 'o: Open\n'
152  strAskForCommand += 'b: Basic mode\n'
153  strAskForCommand += 'p: Pinch mode\n'
154  strAskForCommand += 'w: Wide mode\n'
155  strAskForCommand += 's: Scissor mode\n'
156  strAskForCommand += '(0-255): Go to that position\n'
157  strAskForCommand += 'f: Faster\n'
158  strAskForCommand += 'l: Slower\n'
159  strAskForCommand += 'i: Increase force\n'
160  strAskForCommand += 'd: Decrease force\n'
161 
162  strAskForCommand += '-->'
163 
164  return raw_input(strAskForCommand)
165 
166 
167 def publisher():
168  """Main loop which requests new commands and publish them on the Robotiq3FGripperRobotOutput topic."""
169 
170  rospy.init_node('Robotiq3FGripperSimpleController')
171 
172  pub = rospy.Publisher('Robotiq3FGripperRobotOutput', Robotiq3FGripperRobotOutput)
173 
174  command = Robotiq3FGripperRobotOutput();
175 
176  while not rospy.is_shutdown():
177  command = genCommand(askForCommand(command), command)
178 
179  pub.publish(command)
180 
181  rospy.sleep(0.1)
182 
183 
184 if __name__ == '__main__':
185  publisher()


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