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


robotiq_2f_gripper_control
Author(s): Nicolas Lauzier (Robotiq inc.)
autogenerated on Tue Jun 1 2021 02:29:54