ROSAMTIForce.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 #
00003 # Copyright (c) 2009, Georgia Tech Research Corporation
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #     * Redistributions of source code must retain the above copyright
00009 #       notice, this list of conditions and the following disclaimer.
00010 #     * Redistributions in binary form must reproduce the above copyright
00011 #       notice, this list of conditions and the following disclaimer in the
00012 #       documentation and/or other materials provided with the distribution.
00013 #     * Neither the name of the Georgia Tech Research Corporation nor the
00014 #       names of its contributors may be used to endorse or promote products
00015 #       derived from this software without specific prior written permission.
00016 #
00017 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00018 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00021 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00025 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00026 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 #
00028 
00029 #  \author Advait Jain (Healthcare Robotics Lab, Georgia Tech.)
00030 #  \author Cressel Anderson (Healthcare Robotics Lab, Georgia Tech.)
00031 #  \author Hai Nguyen (Healthcare Robotics Lab, Georgia Tech.)
00032 
00033 import roslib; roslib.load_manifest('force_torque')
00034 import rospy
00035 from hrl_msgs.msg import FloatArray
00036 #import hrl_lib.rutils as ru
00037 
00038 import AMTIForce2 as af
00039 
00040 import threading
00041 import time
00042 
00043 #import rutils as ru
00044 
00045 class AMTIForceServer(threading.Thread):
00046     def __init__(self, device_path, str_id):
00047         threading.Thread.__init__(self)
00048         try:
00049             rospy.init_node('AMTIForceServer')
00050             print 'AMTIForceServer: ros is up!'
00051         except rospy.ROSException:
00052             pass
00053         print 'AMTIForceServer: connecting to', device_path
00054         self.force_plate = af.AMTI_force(device_path)
00055 
00056         name = 'force_torque_' + str_id
00057         print 'AMTIForceServer: publishing', name, 'with type FloatArray'
00058         self.channel = rospy.Publisher(name, FloatArray, tcp_nodelay=True)
00059 
00060     def broadcast(self):
00061         print 'AMTIForceServer: started!'
00062         while not rospy.is_shutdown():
00063             time.sleep(1/5000.0)
00064             self.channel.publish(FloatArray(None, self.force_plate.read().T.tolist()[0]))
00065 
00066 #DEPRECATED, use FTClient from ROSFTSensor with id = 0
00067 #def AMTIForceClient():
00068 #    return ru.FloatArrayListener('AMTIForceClient', 'force_plate', 100.0)
00069 
00070 #import roslib; roslib.load_manifest('force_torque')
00071 #import force_torque.ROSAMTIForce as ft
00072 if __name__ == '__main__':
00073     import optparse
00074     p = optparse.OptionParser()
00075     p.add_option('--path', action='store', default='/dev/robot/force_plate0', type = 'string',
00076                  dest='path', help='path to force torque device in (linux)')
00077     p.add_option('--name', action='store', default='ft1', type='string', 
00078                  dest='name', help='name given to FTSensor')
00079     opt, args = p.parse_args()
00080 
00081     server = AMTIForceServer(opt.path, opt.name)
00082     server.broadcast()
00083 
00084 


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