ros_zenither_client.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 # Copyright (c) 2009, Georgia Tech Research Corporation
00003 # All rights reserved.
00004 # 
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 #     * Redistributions of source code must retain the above copyright
00008 #       notice, this list of conditions and the following disclaimer.
00009 #     * Redistributions in binary form must reproduce the above copyright
00010 #       notice, this list of conditions and the following disclaimer in the
00011 #       documentation and/or other materials provided with the distribution.
00012 #     * Neither the name of the Georgia Tech Research Corporation nor the
00013 #       names of its contributors may be used to endorse or promote products
00014 #       derived from this software without specific prior written permission.
00015 # 
00016 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00020 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00021 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00022 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 #
00027 # ROS wrapper for zenither.
00028 
00029 ## author Advait Jain (Healthcare Robotics Lab, Georgia Tech.)
00030 ## author Travis Deyle (Healthcare Robotics Lab, Georgia Tech.)
00031 
00032 
00033 from threading import RLock
00034 
00035 import roslib
00036 roslib.load_manifest('zenither')
00037 import zenither_config as zc
00038 import rospy
00039 from hrl_srvs.srv import Float_Int
00040 from hrl_msgs.msg import FloatArray
00041 
00042 
00043 
00044 class ZenitherClient():
00045     def __init__(self, robot):
00046         try:
00047             rospy.init_node('ZenitherClient')
00048             rospy.logout('ZenitherServer: Initialized Node')
00049         except rospy.ROSException:
00050             pass
00051 
00052         if robot not in zc.calib:
00053             raise RuntimeError('unknown robot')
00054         self.calib = zc.calib[robot]
00055 
00056         srv = '/zenither/move_position'
00057         rospy.wait_for_service(srv)
00058         self.move_position = rospy.ServiceProxy(srv, Float_Int)
00059         
00060         srv = '/zenither/stop'
00061         rospy.wait_for_service(srv)
00062         self.stop = rospy.ServiceProxy(srv, Float_Int)
00063         
00064         srv = '/zenither/apply_torque'
00065         rospy.wait_for_service(srv)
00066         self.apply_torque = rospy.ServiceProxy(srv, Float_Int)
00067 
00068         srv = '/zenither/torque_move_position'
00069         rospy.wait_for_service(srv)
00070         self.torque_move_position = rospy.ServiceProxy(srv, Float_Int)
00071 
00072         zenither_pose_topic = 'zenither_pose'
00073         self.h = None
00074         self.lock = RLock()
00075         rospy.Subscriber(zenither_pose_topic, FloatArray, self.pose_cb)
00076         
00077     #---------- functions to send zenither commands. -------------
00078     def estop(self):
00079         self.stop(0)
00080 
00081     def zenith(self, torque=None):
00082         if torque == None:
00083             torque=self.calib['zenith_torque']
00084         self.apply_torque(torque)
00085 
00086     def nadir(self, torque=None):
00087         if torque == None:
00088             torque=self.calib['nadir_torque']
00089         self.apply_torque(torque)
00090 
00091 
00092     #--------- zenither height functions --------------
00093     def pose_cb(self, fa):
00094         self.lock.acquire()
00095         self.h = fa.data[0]
00096         self.lock.release()
00097 
00098     ## return the current height of the zenither.
00099     def height(self):
00100         self.lock.acquire()
00101         h = self.h
00102         self.lock.release()
00103         return h
00104 
00105 
00106 
00107 if __name__ == '__main__':
00108     import time
00109 
00110     cl = ZenitherClient('HRL2')
00111 
00112     cl.zenith()
00113     time.sleep(0.5)
00114     cl.estop()
00115 
00116 


zenither
Author(s): Cressel Anderson, Advait Jain, Hai Nguyen, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:54:59