Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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]
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
00066 self._sub.unregister()
00067
00068
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
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