parallel_gripper_controller.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4  parallel_gripper_controller.py - controls a gripper built of two servos
5  Copyright (c) 2011 Vanadium Labs LLC. All right reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14  * Neither the name of Vanadium Labs LLC nor the names of its
15  contributors may be used to endorse or promote products derived
16  from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL VANADIUM LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 """
29 
30 import rospy
31 import thread
32 
33 from std_msgs.msg import Float64
34 from math import asin
35 
37  """ A simple controller that operates two opposing servos to
38  open/close to a particular size opening. """
39  def __init__(self):
40  rospy.init_node("parallel_gripper_controller")
41  rospy.logwarn("parallel_gripper_controller.py is deprecated and will be removed in ROS Indigo, please use gripper_controller")
42 
43  # trapezoid model: base width connecting each gripper's rotation point
44  # + length of gripper fingers to computation point
45  # = compute angles based on a desired width at comp. point
46  self.pad_width = rospy.get_param("~pad_width", 0.01)
47  self.finger_length = rospy.get_param("~finger_length", 0.02)
48  self.min_opening = rospy.get_param("~min", 0.0)
49  self.max_opening = rospy.get_param("~max", 2*self.finger_length)
50 
51  self.center_l = rospy.get_param("~center_left", 0.0)
52  self.center_r = rospy.get_param("~center_right", 0.0)
53  self.invert_l = rospy.get_param("~invert_left", False)
54  self.invert_r = rospy.get_param("~invert_right", False)
55 
56  # publishers
57  self.l_pub = rospy.Publisher("l_gripper_joint/command", Float64, queue_size=5)
58  self.r_pub = rospy.Publisher("r_gripper_joint/command", Float64, queue_size=5)
59 
60  # subscribe to command and then spin
61  rospy.Subscriber("~command", Float64, self.commandCb)
62  rospy.spin()
63 
64  def commandCb(self, msg):
65  """ Take an input command of width to open gripper. """
66  # check limits
67  if msg.data > self.max_opening or msg.data < self.min_opening:
68  rospy.logerr("Command exceeds limits.")
69  return
70  # compute angles
71  angle = asin((msg.data - self.pad_width)/(2*self.finger_length))
72  if self.invert_l:
73  l = -angle + self.center_l
74  else:
75  l = angle + self.center_l
76  if self.invert_r:
77  r = angle + self.center_r
78  else:
79  r = -angle + self.center_r
80  # publish msgs
81  lmsg = Float64(l)
82  rmsg = Float64(r)
83  self.l_pub.publish(lmsg)
84  self.r_pub.publish(rmsg)
85 
86 if __name__=="__main__":
87  try:
89  except rospy.ROSInterruptException:
90  rospy.loginfo("Hasta la Vista...")
91 


arbotix_controllers
Author(s): Michael Ferguson
autogenerated on Mon Jun 10 2019 12:43:39