Go to the documentation of this file.00001
00002
00003 import roslib;
00004 roslib.load_manifest('hrl_pr2_kinematics_tutorials')
00005 roslib.load_manifest('rfid_people_following')
00006 roslib.load_manifest('std_srvs')
00007 roslib.load_manifest('joy')
00008 import rospy
00009
00010 from rfid_people_following.srv import StringInt32_Int32
00011 from rfid_people_following.srv import String_Int32
00012 from rfid_people_following.srv import Int32_Int32
00013 from rfid_people_following.srv import String_StringArr
00014 from rfid_people_following.srv import rfid_gui as gui_srv
00015 from rfid_people_following.srv import HandoffSrv
00016 from std_srvs.srv import Empty
00017 from joy.msg import Joy
00018 from cmd_process import CmdProcess
00019
00020 import numpy as np, math
00021 import time
00022
00023 class DemoNode():
00024 def __init__( self ):
00025 rospy.init_node( 'rfid_demo', anonymous = True )
00026 rospy.logout( 'demo_node: Initializing' )
00027
00028 rospy.logout( 'demo_node: Waiting for services' )
00029 rospy.wait_for_service( '/rfid_servo/servo' )
00030 rospy.wait_for_service( '/rfid_orient/orient' )
00031 rospy.wait_for_service( '/rfid_orient/flap' )
00032 rospy.wait_for_service( '/rfid_handoff/initialize' )
00033 rospy.wait_for_service( '/rfid_handoff/handoff' )
00034 rospy.wait_for_service( '/rfid_handoff/wave' )
00035
00036 rospy.logout( 'demo_node: All services ready.' )
00037
00038 self.last_button = time.time()
00039 self.run_demo = False
00040 self.run_hoinit = False
00041 self.run_handoff = False
00042
00043 self._joy_sub = rospy.Subscriber( 'joy', Joy, self.joy_process )
00044
00045 self._servo = rospy.ServiceProxy( '/rfid_servo/servo', StringInt32_Int32 )
00046 self.follow1 = lambda : self._servo( 'person ', 1 )
00047 self.follow = lambda : self._servo( 'person ', 0 )
00048
00049 self._servo_stop = rospy.ServiceProxy( '/rfid_servo/stop_next_obs', Int32_Int32 )
00050 self.servo_toggle = lambda : self._servo_stop( 1 )
00051
00052 self._handoff = rospy.ServiceProxy( '/rfid_handoff/handoff', HandoffSrv )
00053 self.handoff = lambda : self._handoff()
00054
00055 self._hoinit = rospy.ServiceProxy( '/rfid_handoff/initialize', HandoffSrv )
00056 self.hoinit = lambda : self._hoinit()
00057
00058 self._howave = rospy.ServiceProxy( '/rfid_handoff/wave', HandoffSrv )
00059 self.howave = lambda : self._howave()
00060
00061 self._flap = rospy.ServiceProxy( '/rfid_orient/flap', String_StringArr )
00062 self.flap = lambda : self._flap( '' )
00063
00064 self._orient = rospy.ServiceProxy( '/rfid_orient/orient', String_Int32 )
00065 self.orient = lambda tagid: self._orient( tagid )
00066
00067
00068
00069
00070 self._service = rospy.Service( '/rfid_demo/demo', Empty, self.demo )
00071 self._service = rospy.Service( '/rfid_demo/gui', Empty, self.gui_test )
00072
00073
00074 rospy.logout( 'demo_node: Demo service ready!' )
00075
00076 def joy_process( self, msg ):
00077 if msg.buttons[11] == 1 and time.time() - self.last_button > 1.0:
00078 if msg.buttons[12] == 1:
00079 rospy.logout( 'demo_node: joy_process: Calling demo service' )
00080 p = CmdProcess( ['rosservice', 'call', '/rfid_demo/demo'] )
00081 p.run()
00082 self.last_button = time.time()
00083 elif msg.buttons[13] == 1:
00084 rospy.logout( 'demo_node: joy_process: Calling handoff service' )
00085 p = CmdProcess( ['rosservice', 'call', '/rfid_handoff/handoff'] )
00086 p.run()
00087 self.last_button = time.time()
00088 elif msg.buttons[14] == 1:
00089 rospy.logout( 'demo_node: joy_process: Calling servo toggle service' )
00090 p = CmdProcess( ['rosservice', 'call', '/rfid_servo/stop_next_obs', '1'] )
00091 p.run()
00092 self.last_button = time.time()
00093 elif msg.buttons[15] == 1:
00094 rospy.logout( 'demo_node: joy_process: Calling handoff initialization service' )
00095 p = CmdProcess( ['rosservice', 'call', '/rfid_handoff/initialize'] )
00096 p.run()
00097 self.last_button = time.time()
00098 elif msg.buttons[9] == 1:
00099 rospy.logout( 'demo_node: joy_process: Calling handoff wave service' )
00100 p = CmdProcess( ['rosservice', 'call', '/rfid_handoff/wave'] )
00101 p.run()
00102 self.last_button = time.time()
00103
00104 def gui_test( self, msg = None ):
00105 tags = self.flap().value
00106 gui_resp = self.gui( tags )
00107
00108 def demo( self, msg = None ):
00109 tags = self.flap().value
00110
00111
00112
00113 self.orient( 'person ' )
00114
00115
00116 self.follow()
00117 self.handoff()
00118
00119 if __name__ == '__main__':
00120 dn = DemoNode()
00121 rospy.spin()