Go to the documentation of this file.00001
00002 import roslib
00003 roslib.load_manifest('rfid_behaviors')
00004 import rospy
00005
00006 from rfid_behaviors.srv import FlapEarsSrv, FlapperSrv
00007
00008 from threading import Thread
00009
00010
00011
00012 class Flapper( Thread ):
00013 def __init__( self, serv_name = 'rfid_orient/flap' ):
00014 Thread.__init__( self )
00015 self.should_run = True
00016
00017 self.should_flap = False
00018 self.tagid = ''
00019 rospy.logout( 'flapper: initializing' )
00020 try:
00021 rospy.init_node('flapper_py')
00022 except:
00023 pass
00024
00025 rospy.wait_for_service( serv_name )
00026
00027 self.flap = rospy.ServiceProxy( '/rfid_orient/flap', FlapEarsSrv )
00028
00029 self._service = rospy.Service( '/flapper/flap',
00030 FlapperSrv,
00031 self.process_service )
00032
00033 rospy.logout( 'flapper: ready' )
00034 self.start()
00035
00036 def run( self ):
00037 rospy.logout( 'flapper: running' )
00038 r = rospy.Rate( 10 )
00039 while self.should_run and not rospy.is_shutdown():
00040 if self.should_flap:
00041 self.flap( self.tagid, 0.0 )
00042 r.sleep()
00043 rospy.logout( 'flapper: exiting' )
00044
00045 def stop( self ):
00046 self.should_run = False
00047 self.join(3)
00048 if (self.isAlive()):
00049 raise RuntimeError("ROS_M5e: unable to stop thread")
00050
00051
00052 def process_service( self, req ):
00053 self.tagid = req.tagid
00054 self.should_flap = not self.should_flap
00055 return True
00056
00057 if __name__ == '__main__':
00058 fl = Flapper()
00059 rospy.spin()