00001
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 roslib.load_manifest('tf')
00010 import rospy
00011
00012 import rfid_datacapture.math_util as mu
00013 import sm_aware_home_explore as ahe
00014 import glob
00015 import yaml
00016 import tf
00017 import tf.transformations as tft
00018 import json
00019 import numpy as np, math
00020 import cPickle as pkl
00021 import template
00022
00023
00024 print 'THIS FILE DEPRICATED AND INACCURATE!!! USE REL_STATS!'
00025
00026
00027 res = []
00028
00029 for i in xrange( 9 ):
00030 for j in xrange( 9 ):
00031 skip = False
00032
00033 obj_num = j
00034 obj_name = ahe.tdb[j][0]
00035 tname = obj_name.replace( ' ', '' )
00036
00037 trial_num = i
00038
00039 loc = (i + j) % 9
00040 loc_name = ahe.pts[loc][0]
00041 loc_pos = np.array(ahe.pts[loc][1])
00042
00043 print 'Trial %d with Object %d (%s) at Position %d (%s)' % (i, obj_num, obj_name, loc, loc_name)
00044
00045 fname = 'search_aware_home/woot_150_'+str(i)+'_reads.pkl'
00046 f = open( fname, 'r' )
00047 summary = pkl.load( f )
00048 f.close()
00049
00050 pos_readings = sum([ True for p in summary if p.read.rssi != -1 and p.read.tagID == obj_name ])
00051 tot_readings = len( summary )
00052 print '\t Positive Reads: %d of %d (%2.2f)' % ( pos_readings,
00053 tot_readings,
00054 100.0 * pos_readings / tot_readings )
00055
00056
00057 search_fname = 'search_aware_home/woot_150_' + str(i) + '_tag_' + tname + '.yaml'
00058 glob_r = glob.glob( search_fname )
00059 if glob_r == []:
00060 print '\t No results for this instance.'
00061 skip = True
00062 if len(glob_r) > 1:
00063 print '\t Multiple results...?! Weirdness. Skipping.'
00064 skip = True
00065
00066
00067 servo_fname = 'search_aware_home/woot_150_' + str(i) + '_tag_' + tname + '_end.txt'
00068 glob_r = glob.glob( servo_fname )
00069 if glob_r == []:
00070 print '\t No results for this instance.'
00071 skip = True
00072 if len(glob_r) > 1:
00073 print '\t Multiple results...?! Weirdness. Skipping.'
00074 skip = True
00075
00076
00077
00078 if not skip:
00079 f = open( search_fname )
00080 y = yaml.load( f )
00081 f.close()
00082
00083
00084 efq = tft.euler_from_quaternion
00085 search_theta = efq( [ y['pose']['orientation']['x'],
00086 y['pose']['orientation']['y'],
00087 y['pose']['orientation']['z'],
00088 y['pose']['orientation']['w'] ])[-1]
00089
00090 search_pos = np.array([ y['pose']['position']['x'],
00091 y['pose']['position']['y'],
00092 y['pose']['position']['z'] ])
00093
00094 search_true_theta = np.arctan2( loc_pos[1] - search_pos[1],
00095 loc_pos[0] - search_pos[0] )
00096 search_theta_diff = mu.standard_rad( search_theta - search_true_theta )
00097 search_pos_diff = np.linalg.norm( search_pos - loc_pos )
00098
00099 print '\t Post-Search Stats:'
00100 print '\t\t Tag-Robot distance err (m): %2.3f' % (search_pos_diff)
00101 print '\t\t Tag-Robot orient err (deg): %2.3f' % (math.degrees(search_theta_diff))
00102 print '\t\t Debug Stats', math.degrees(search_theta), math.degrees(search_true_theta), search_pos, loc_pos
00103
00104
00105 f = open( servo_fname )
00106 r = f.readlines()
00107 f.close()
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 rpy = r[-1].find('RPY')+3
00118 servo_theta = json.loads( r[-1][rpy:] )[-1]
00119
00120 tion = r[-3].find('tion:')+5
00121 servo_pos = np.array(json.loads( r[-3][tion:] ))
00122
00123 servo_true_theta = np.arctan2( loc_pos[1] - servo_pos[1],
00124 loc_pos[0] - servo_pos[0] )
00125 servo_theta_diff = mu.standard_rad( servo_theta - servo_true_theta )
00126 servo_pos_diff = np.linalg.norm( servo_pos - loc_pos )
00127
00128 print '\t Post-Servo Stats:'
00129 print '\t\t Tag-Robot distance err (m): %2.3f' % (servo_pos_diff)
00130 print '\t\t Tag-Robot orient err (deg): %2.3f' % (math.degrees(servo_theta_diff))
00131 print '\t\t Debug Stats', math.degrees(servo_theta), math.degrees(servo_true_theta), servo_pos, loc_pos
00132
00133 res.append( [ loc, obj_num, i, pos_readings, tot_readings, servo_pos_diff, math.degrees(servo_theta_diff) ] )
00134
00135 else:
00136 res.append( [ loc, obj_num, i, pos_readings, tot_readings, '--', '--' ] )
00137
00138 print '\t Done.\n\n'
00139
00140 res.sort()
00141 print '\n\nRESULTS SORTED\n\n'
00142 def pprint(r):
00143 print 'Location %d, Object %d, Trial %d' % (r[0], r[1], r[2])
00144 if r[3] > 0:
00145 print '\tPos Reads: %d' % (r[3])
00146 print '\tTot Reads: %d' % (r[4])
00147 print '\tPercent Reads: %2.3f' % (r[3]*100.0/r[4])
00148 print '\tDist Err (m): %2.3f' % (r[5])
00149 print '\tAng Err (deg): %2.3f' % (r[6])
00150 else:
00151 print '\tPos Reads: %d' % (r[3])
00152 print '\tTot Reads: %d' % (r[4])
00153 print '\tPercent Reads: %2.3f' % (r[3]*100.0/r[4])
00154 print '\tDist Err (m): ----'
00155 print '\tAng Err (deg): ----'
00156
00157 [ pprint(r) for r in res ]
00158
00159
00160
00161 print '\n\n######### OUTPUTTING TEX TABLES from template.py #########\n\n'
00162
00163 def delta_xy( r ):
00164 if r[3] > 0:
00165 return '%2.3f m' % (r[5])
00166 else:
00167 return '$--$'
00168
00169 def delta_theta( r ):
00170 if r[3] > 0:
00171 return '%2.1f$^o$' % (r[6])
00172 else:
00173 return '$--$'
00174
00175
00176 for i in xrange( 9 ):
00177 io = [ r for r in res if r[0] == i ]
00178
00179
00180 if len(io) != 9:
00181 print 'BIG PROBLEM. IO != 9'
00182 exit()
00183
00184 args = []
00185
00186 args += [ '%d / %d (%2.1f\\%%)' % (r[3], r[4], r[3] * 100.0 / r[4]) for r in io ][0:4]
00187 args += [ delta_xy(r) for r in io ][0:4]
00188 args += [ delta_theta(r) for r in io ][0:4]
00189
00190 args += [ '%d / %d (%2.1f\\%%)' % (r[3], r[4], r[3] * 100.0 / r[4]) for r in io ][4:]
00191 args += [ delta_xy(r) for r in io ][4:]
00192 args += [ delta_theta(r) for r in io ][4:]
00193
00194 args += [ io[0][0] ]
00195 args += [ np.mean( [ r[3] for r in io ] ),
00196 np.std( [ r[3] for r in io ] ) ]
00197 args += [ np.mean( [ r[5] for r in io if r[3] > 0 ] ),
00198 np.std( [ r[5] for r in io if r[3] > 0 ] )]
00199 args += [ np.mean( np.abs([ r[6] for r in io if r[3] > 0 ]) ),
00200 np.std( np.abs([ r[6] for r in io if r[3] > 0 ]) )]
00201
00202
00203 args += [ io[0][0], io[0][0] ]
00204
00205 io_templated = template.x % tuple( args )
00206 f = open('rfid_search_loc%d_table.tex' % (i),'w')
00207 f.write( io_templated )
00208 f.close()
00209
00210
00211 print 'THIS FILE DEPRICATED AND INACCURATE!!! USE REL_STATS!'