display_tags_and_poses.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 roslib.load_manifest('tf')
00010 roslib.load_manifest('sensor_msgs')
00011 roslib.load_manifest('visualization_msgs')
00012 import rospy
00013 
00014 import cPickle as pkl
00015 import hrl_lib.rutils as ru
00016 import hrl_lib.viz as viz
00017 import sensor_msgs.msg as sm
00018 import numpy as np, math
00019 import sm_aware_home_explore as ahe
00020 import visualization_msgs.msg as vm
00021 import tf
00022 import tf.transformations as tft
00023 import glob
00024 import json
00025 import yaml
00026 import time
00027 import os
00028 
00029 rospy.init_node( 'derp' )
00030 vsm = viz.single_marker
00031 m_id = 0
00032 # Tags
00033 # tag_pts = np.array([ ahe.pts[k][1] for k in ahe.pts.keys() ]).T
00034 # tm = [ viz.single_marker( tag_pts[:,i].reshape([3,1]),
00035 #                           np.matrix([ [0.0], [0.0], [0.0], [1.0] ]),
00036 #                           'sphere', '/map',
00037 #                           color=[0.0, 1.0, 0.0, 1.0],
00038 #                           m_id=i ) for i in xrange( tag_pts.shape[1] )]
00039 # Results:
00040 # 'Obj5_Trial8_Servo1_rel_results.pkl'
00041 # {'best_pos': array([-2.165,  0.979,  0.055]),
00042 #  'dtheta': 0.041245071031409619,
00043 #  'dxy': 1.1365249667297239,
00044 #  'loc': 7,
00045 #  'obj_num': 5,
00046 #  'orient_est': 2.8607549289685905,
00047 #  'pos_readings': 717,
00048 #  'servo_yn': True,
00049 #  'tot_readings': 3580,
00050 #  'trial_num': 2}
00051 
00052 
00053 fnames = glob.glob('Obj[0-9]_Trial[0-9]_Servo1_rel_results.pkl')
00054 def load( fn ):
00055     f = open( fn )
00056     dat = pkl.load( f )
00057     f.close()
00058     return dat
00059 
00060 d = [ load( f ) for f in fnames ]
00061 d = [ di for di in d if di['pos_readings'] > 0 ]
00062 
00063 def arrow( m_id, res_dict, color ):
00064     m = vsm( np.matrix([ res_dict['best_pos'] ]).T,
00065              np.matrix([ tft.quaternion_from_euler( 0.0,
00066                                                     0.0,
00067                                                     res_dict['orient_est']) ]).T,
00068              'arrow', '/map',
00069              scale = [0.5, 1.0, 1.0],
00070              color = color, # rgba
00071              duration = 10.0,
00072              m_id = m_id )
00073     # color = [0./255, 205./255, 255./255, 1.0], # rgba
00074 
00075     return m
00076 
00077 pub_mark = rospy.Publisher( '/tag_poses', vm.Marker )
00078 
00079 tag_spheres = []
00080 servo_arrows = []
00081 
00082 def hextorgba( h ):
00083     return h * 1.0 / 255.0
00084 
00085 colors = [ [ hextorgba( i ) for i in [ 0x00, 0x99, 0x00, 0xFF ]], # green
00086            [ hextorgba( i ) for i in [ 0xEE, 0x00, 0x00, 0xFF ]], # red
00087            [ hextorgba( i ) for i in [ 0x00, 0xCC, 0xFF, 0xFF ]]] # teal
00088 
00089 for loc in range( 0, 9 ):
00090     m_id += 1
00091     color = colors[ loc % len(colors) ]
00092     tag_spheres.append( vsm( np.matrix([ ahe.pts[loc][1][0],
00093                                          ahe.pts[loc][1][1],
00094                                          ahe.pts[loc][1][2] ]).T,
00095                              np.matrix([ [0.0], [0.0], [0.0], [1.0] ]),
00096                              'sphere', '/map',
00097                              color = color, # rgba
00098                              duration = 10.0,
00099                              m_id = m_id ))
00100 
00101     for di in d:
00102         if di['loc'] == loc:
00103             m_id += 1
00104             servo_arrows.append( arrow( m_id, di, color ))
00105 
00106     
00107 
00108 marks = tag_spheres + servo_arrows
00109 
00110 while not rospy.is_shutdown():
00111     [ pub_mark.publish( x ) for x in marks ]
00112     rospy.sleep( 1.0 )
00113     print 'WOOT'
00114 
00115 


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