ros_M5e_client.py
Go to the documentation of this file.
00001 #
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 
00028 #  \author Travis Deyle (Healthcare Robotics Lab, Georgia Tech.)
00029 
00030 
00031 
00032 # ROS imports
00033 import roslib; roslib.load_manifest('hrl_rfid')
00034 import rospy
00035 from hrl_rfid.msg import RFIDread
00036 from hrl_rfid.srv import RfidSrv
00037 import hrl_rfid.lib_M5e as M5e
00038 
00039 import time
00040 import thread
00041 
00042 class ROS_M5e_Client():
00043     QUERY_MODE = 'query'
00044     TRACK_MODE = 'track'
00045 
00046     def __init__(self, name = 'reader1', callbacks=[]):
00047         self.name = name
00048         self._create_ros_objects()
00049     
00050         self.callbacks = callbacks
00051         self.last_read = ['', '', -1] # antenna_name, tagID, rssi
00052 
00053         try:
00054             rospy.init_node( self.name + '_listener', anonymous=True )
00055         except rospy.ROSException:
00056             pass
00057 
00058         self._sub = rospy.Subscriber( '/rfid/' + self.name + '_reader', RFIDread, self._sub_cb)
00059 
00060     def _sub_cb(self, datum):
00061         [ cb( datum ) for cb in self.callbacks ]
00062         self.last_read = [datum.antenna_name, datum.tagID, datum.rssi]
00063 
00064     def unregister( self ):
00065         # Stop processing new reads.
00066         self._sub.unregister()
00067 
00068     # ROS Services
00069     def stop(self):
00070         self._mode_service_obj([ '' ])
00071 
00072     def track_mode(self, tag_id):
00073         self._mode_service_obj([ self.TRACK_MODE, tag_id ])
00074 
00075     def query_mode(self):
00076         self._mode_service_obj([ self.QUERY_MODE ])
00077 
00078     # Create ROS Objects (for internal use only)
00079     def _create_ros_objects(self):
00080         reader_service_name = '/rfid/'+self.name+'_mode'
00081         rospy.wait_for_service(reader_service_name)
00082         self._mode_service_obj = rospy.ServiceProxy(reader_service_name,
00083                                                     RfidSrv)
00084 
00085     def read(self, antenna = ''):
00086         if antenna == '':
00087             return self.last_read
00088         else:
00089             r = self.last_read
00090             while r[0] != antenna and not rospy.is_shutdown():
00091                 time.sleep(0.02)
00092                 r = self.last_read
00093             return r
00094         


hrl_rfid
Author(s): Travis Deyle, Advisor: Prof. Charlie Kemp (Healthcare Robotics Lab at Georgia Tech) and Prof. Matt Reynolds (Duke University)
autogenerated on Wed Nov 27 2013 11:32:45