one_side_gripper_controller.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """
00004   one_side_gripper_controller.py - controls a gripper built with one servo
00005   Copyright (c) 2011 Vanadium Labs LLC.  All right reserved.
00006 
00007   Redistribution and use in source and binary forms, with or without
00008   modification, are permitted provided that the following conditions are met:
00009       * Redistributions of source code must retain the above copyright
00010         notice, this list of conditions and the following disclaimer.
00011       * Redistributions in binary form must reproduce the above copyright
00012         notice, this list of conditions and the following disclaimer in the
00013         documentation and/or other materials provided with the distribution.
00014       * Neither the name of Vanadium Labs LLC nor the names of its 
00015         contributors may be used to endorse or promote products derived 
00016         from this software without specific prior written permission.
00017   
00018   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00019   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021   DISCLAIMED. IN NO EVENT SHALL VANADIUM LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00023   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00024   OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00025   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00026   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00027   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 """
00029 
00030 import roslib; roslib.load_manifest('arbotix_controllers')
00031 import rospy
00032 import thread
00033 
00034 from std_msgs.msg import Float64
00035 from math import asin
00036 
00037 class OneSideGripperController:
00038     """ A simple controller that operates a servos to
00039         open/close to a particular size opening. """
00040     def __init__(self):
00041         rospy.init_node("one_side_gripper_controller")
00042         rospy.logwarn("one_side_gripper_controller.py is deprecated and will be removed in ROS Indigo, please use gripper_controller")
00043 
00044         self.pad_width = rospy.get_param("~pad_width", 0.01)
00045         self.finger_length = rospy.get_param("~finger_length", 0.02)
00046         self.center = rospy.get_param("~center", 0.0)
00047         self.invert = rospy.get_param("~invert", False)
00048 
00049         # publishers
00050         self.pub = rospy.Publisher("gripper_joint/command", Float64)
00051 
00052         # subscribe to command and then spin
00053         rospy.Subscriber("~command", Float64, self.commandCb)
00054         rospy.spin()
00055 
00056     def commandCb(self, msg):
00057         """ Take an input command of width to open gripper. """
00058         # check limits
00059         #if msg.data > self.max_opening or msg.data < self.min_opening:
00060         #    rospy.logerr("Command exceeds limits.")
00061         #    return
00062         # compute angle
00063         angle = asin((msg.data - self.pad_width)/(2*self.finger_length))
00064         # publish message
00065         if self.invert:
00066             self.pub.publish(-angle + self.center)
00067         else:
00068             self.pub.publish(angle + self.center)
00069 
00070 if __name__=="__main__":
00071     try:
00072         OneSideGripperController()
00073     except rospy.ROSInterruptException:
00074         rospy.loginfo("Hasta la Vista...")
00075         


arbotix_controllers
Author(s): Michael Ferguson
autogenerated on Wed Aug 26 2015 10:44:22