00001
00002
00003 import random as rd
00004 import numpy as np, math
00005
00006 import rfid_model
00007 import lib_pfilter
00008
00009 import roslib
00010 roslib.load_manifest('visualization_msgs')
00011 roslib.load_manifest('hrl_lib')
00012 import rospy
00013
00014 import visualization_msgs.msg as vm
00015 import hrl_lib.transforms as tr
00016 import hrl_lib.viz as viz
00017 vsm = viz.single_marker
00018
00019 import pylab as pl
00020
00021 class DisplayWeights:
00022 def __init__( self, pub_topic = '/particles' ):
00023 self.m = None
00024 self.pub_mark = rospy.Publisher( pub_topic, vm.Marker )
00025 self.mid = 0
00026
00027 def create_mark( self, p, c = [1.0, 0.0, 0.0, 0.8], mid = None ):
00028 if mid == None:
00029 self.mid += 1
00030 mid = self.mid
00031
00032 m = vsm( np.matrix([ p[0], p[1], 0.0 ]).T,
00033 np.matrix([ 0.0, 0.0, 0.0, 1.0 ]).T,
00034 'sphere', '/map',
00035 scale = [0.05, 0.05, 0.05],
00036 color = [1.0, 0.0, 0.0, 0.8],
00037 duration = 10.0,
00038 m_id = mid )
00039 m.header.stamp = rospy.Time.now()
00040 return m
00041
00042
00043 def update( self, particles ):
00044 xyz = np.column_stack([ particles[:,0:2], np.zeros( particles.shape[0] )]).T
00045 w = particles[:,2]
00046
00047 wmin = np.min( w )
00048 wmax = np.max( w )
00049
00050
00051
00052 if wmin == wmax:
00053 colors = np.row_stack([ np.ones( particles.shape[0] ),
00054 np.zeros( particles.shape[0] ),
00055 np.zeros( particles.shape[0] ),
00056 np.ones( particles.shape[0] ) ])
00057 else:
00058 colors = np.array([ pl.cm.jet( int( 1.0 * ( wi - wmin ) / (wmax - wmin) * 255.0 ))
00059 for wi in w ]).T
00060 m = viz.list_marker( xyz, colors, [0.05, 0.05, 0.05], 'points', '/map', 300 )
00061 m.header.stamp = rospy.Time.now()
00062 for i in xrange( 10 ):
00063 self.pub_mark.publish( m )
00064 rospy.sleep( 0.2 )
00065
00066 return
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 rospy.init_node( 'test_rfid_pf' )
00083
00084
00085 X,Y = np.meshgrid( np.arange(-10,10,0.1),
00086 np.arange(-10,10,0.1) )
00087 xyw = np.row_stack([ X.flatten(),
00088 Y.flatten(),
00089 np.ones( X.shape ).flatten() ]).T
00090
00091 xyw_orig = np.copy( xyw )
00092
00093 rm = rfid_model.RfidModel( rfid_model.yaml_fname )
00094
00095
00096
00097
00098
00099
00100 rv = rm.weight_set( 83, xyw )
00101
00102
00103 xy = xyw[:,0:2]
00104 trans = tr.composeHomogeneousTransform( tr.rotZ( math.radians(-90) ), np.matrix([5,5,0]).T )
00105 xy_new = np.array((trans * tr.xyToHomogenous( xy.T) )[0:2].T)
00106
00107 xyw_new = np.column_stack([ xy_new, rv[:,2] ])
00108 rv_new = rm.weight_set( 83, xyw_new )
00109
00110 to_print = np.copy( xyw_orig )
00111 to_print[:,2] = rv_new[:,2]
00112
00113
00114
00115 dw = DisplayWeights()
00116
00117 while not rospy.is_shutdown():
00118 print 'UPDATING'
00119 dw.update( to_print )
00120
00121 m = int( raw_input( 'New RSSI: ' ))
00122
00123
00124
00125