sm_aware_home_explore.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 import roslib
00003 roslib.load_manifest('smach_ros')
00004 roslib.load_manifest('actionlib')
00005 roslib.load_manifest('rfid_datacapture')
00006 roslib.load_manifest('rfid_demos')
00007 roslib.load_manifest('rfid_behaviors')
00008 roslib.load_manifest('hrl_lib')
00009 import rospy
00010 
00011 
00012 tdb = { 0: ['OrangeMedBot',[]],
00013         1: ['TravisTVremo',[]],
00014         2: ['RedBottle   ',[]],
00015         3: ['OnMetalKeys ',[]],
00016         4: ['WhiteMedsBot',[]],
00017         5: ['BlueMedsBox ',[]],
00018         6: ['TeddyBearToy',[]],
00019         7: ['CordlessPhon',[]],
00020         8: ['BlueHairBrus',[]]}
00021 
00022 pts = { 0: ['BehindTree',[3.757, 6.017, 0.036]],
00023         1: ['FireplaceMantle',[5.090, 4.238, 1.514]],
00024         2: ['CircleEndTable',[5.399, 2.857, 0.607]],
00025         3: ['Couch',[3.944, 1.425, 0.527]],
00026         4: ['RectEndTable',[3.302, 0.932, 0.534]],
00027         5: ['BehindKitchenTable',[-0.339, -2.393, 0.793]],
00028         6: ['NearDishwaser',[-1.926, -0.835, 0.946]],
00029         7: ['InCupboard',[-3.257, 1.294, 1.397]],
00030         8: ['OnFilingCabinet',[-0.083, 2.332, 0.670]]}
00031 
00032 import smach
00033 import actionlib
00034 
00035 from smach_ros import SimpleActionState, ServiceState, IntrospectionServer
00036 from rfid_demos import sm_rfid_explore
00037 from rfid_behaviors import recorder
00038 from hrl_lib import util
00039 from rfid_datacapture.srv import BagCapture, BagCaptureRequest
00040 
00041 class DummyClass():
00042     def __init__(self, tagid):
00043         self.tagid = tagid
00044 
00045 if __name__ == '__main__':
00046     import optparse
00047     p = optparse.OptionParser()
00048     p.add_option('--fname', action='store', type='string', dest='fname',
00049                  help='File name.  Should be without extension. [eg. \'trial\']', default='')
00050     p.add_option('--radius', action='store', type='float', dest='radius',
00051                  help='Exploration radius in meters.', default=4.0)
00052 
00053     opt, args = p.parse_args()
00054 
00055     if opt.fname == '':
00056         print 'Fname required'
00057         exit()
00058     fname_base = '/u/travis/svn/robot1/src/projects/rfid_datacapture/src/rfid_datacapture/search_cap/search_bags/'
00059     fname = fname_base + opt.fname
00060 
00061 
00062 
00063     sm = smach.StateMachine(outcomes=['succeeded','aborted','preempted'],
00064                             input_keys = [ 'bagfile_name',
00065                                            'bagfile_topics',
00066                                            'tagid',
00067                                            'explore_radius' ])
00068     with sm:
00069         smach.StateMachine.add(
00070             'START_BAG_CAPTURE',
00071             ServiceState( '/bag_cap/capture',
00072                           BagCapture,
00073                           request_slots = ['topics','dest'] ),
00074             remapping = {'topics':'bagfile_topics',
00075                          'dest':'bagfile_name'},
00076             transitions = {'succeeded':'SEARCH'})
00077 
00078         sm_search = sm_rfid_explore.sm_search()
00079 
00080         smach.StateMachine.add(
00081             'SEARCH',
00082             sm_search,
00083             transitions = {'succeeded':'STOP_BAG_CAPTURE'},
00084             remapping = {'tagid':'tagid',
00085                          'explore_radius':'explore_radius'})
00086 
00087         smach.StateMachine.add(
00088             'STOP_BAG_CAPTURE',
00089             ServiceState( '/bag_cap/capture',
00090                           BagCapture,
00091                           request = BagCaptureRequest('','') ),
00092             transitions = {'succeeded':'succeeded'})
00093 
00094 
00095 
00096     rospy.init_node('smach_datacap_rfid_explore')
00097 
00098     rec = recorder.Recorder( serv_name = 'temp_recorder', node_name = 'temp_recorder_py' )
00099     rec.process_service( None )  # start recording
00100 
00101 
00102     sm.userdata.tagid = ''
00103     sm.userdata.explore_radius = opt.radius
00104     sm.userdata.bagfile_name = fname
00105     sm.userdata.bagfile_topics = '/tf /visarr /rfid/ears_reader /rfid/ears_reader_arr /map /robot_pose_ekf/odom_combined'
00106 
00107     outcome = sm.execute()
00108 
00109     rec.process_service( None )  # stop recording
00110 
00111     print 'Saving recorder pickle data.'
00112     util.save_pickle( rec.recorder_data, fname + '_reads.pkl' )
00113 
00114     print 'Saving best read locations.'
00115     tagids = ['person      ','OrangeMedBot' ,'SpectrMedBot','OnMetalKeys ',
00116               'TravisTVremo','Red Mug     ']
00117 
00118     for t in tagids:
00119         print '\tTagid: \'%s\'' % t,
00120         tname = t.replace( ' ', '' )
00121 
00122         try:
00123             pos = rec.bestvantage( DummyClass( t ))
00124             pos.header.stamp = rospy.Time(0)
00125             dat = pos.__str__() + '\n'
00126 
00127             f = open( fname + '_tag_' + tname + '.yaml', 'w' )
00128             f.write( dat )
00129             f.close()
00130             print ' Done.'
00131         except:
00132             print ' No reads.  Done.'
00133             pass
00134     


rfid_datacapture
Author(s): Travis Deyle
autogenerated on Wed Nov 27 2013 12:11:16