gen_costmap_locations.py
Go to the documentation of this file.
00001 import roslib
00002 roslib.load_manifest( 'costmap_services' )
00003 import rospy
00004 
00005 import numpy as np, math
00006 import costmap_services.python_client as costmap
00007 from display_particles import DisplayParticles
00008 import cPickle as pkl
00009 
00010 
00011 
00012 
00013 if __name__ == '__main__':
00014     import optparse
00015     p = optparse.OptionParser()
00016     p.add_option('--recalc', action='store_true', dest='recalc',
00017                  help='recalculate the costmap points?', default = False)
00018     p.add_option('--fname', action='store', type='string', dest='fname',
00019                  help='pkl file to use', default = False)
00020     p.add_option('--combine', action='store_true', dest='combine',
00021                  help='Combine results of multiple costmaps', default = False)
00022     opt, args = p.parse_args()
00023     
00024 
00025     rospy.init_node( 'tmp2243425' )
00026 
00027     # fname = 'costmap_costs.pkl'
00028     fname = opt.fname
00029 
00030     if opt.combine:
00031         # OK, this is just a hack.  I need a way to combine a masked map with a previously captured costmap.
00032         print 'YAY!'
00033 
00034         f = open( 'gen_costmap_mask.pkl', 'r' )
00035         mask = pkl.load( f )
00036         f.close()
00037 
00038         f = open( 'gen_costmap_aware_home.pkl', 'r' )
00039         obs = pkl.load( f )
00040         f.close()
00041 
00042         # fname = 'pf_costmap.pkl'
00043 
00044         ind_m = np.where( mask[:,2] < 127.0 )[0]
00045         ind_o = np.where( obs[:,2] < 127.0 )[0]
00046         ind = np.intersect1d( ind_m, ind_o )  # Locations that are good in both costmaps
00047 
00048         p_set = np.copy( obs )
00049         p_set[:,2] = np.zeros( obs.shape[0] )
00050         p_set[:,2][ind] = True
00051 
00052         f = open( fname, 'w' )
00053         pkl.dump( p_set, f )
00054         f.close()
00055 
00056 
00057         
00058     if not opt.fname:
00059         print 'fname required here on out.'
00060         exit()
00061 
00062     if opt.recalc:
00063         res = 0.05
00064 
00065         cs = costmap.CostmapServices()
00066         X,Y = np.meshgrid( np.arange( -5, 8, res ), np.arange( -5, 8, res ))
00067         xy = zip( X.flatten(), Y.flatten() )
00068 
00069         print 'Computing Map Costs...'
00070         mc = []
00071         for i,xyi in enumerate( xy ):
00072             if i % 100 == 0:
00073                 print 'Still working ( %d of %d -- %3.2f%%)' % (i, len(xy), 100.0*i/len(xy))
00074             mc += [ cs.getMapCost( *xyi ) ]
00075         print 'Done.'
00076 
00077         p_set = np.column_stack([ np.array( X.flatten() ),
00078                                   np.array( Y.flatten() ),
00079                                   np.array( mc ) ])
00080 
00081         f = open( fname, 'w' )
00082         pkl.dump( p_set, f )
00083         f.close()
00084 
00085 
00086     dp = DisplayParticles()
00087 
00088     f = open( fname, 'r' )
00089     p_set = pkl.load( f )
00090     f.close()
00091 
00092     while not rospy.is_shutdown():
00093         print 'Displaying particles'
00094         dp.update( p_set )
00095         rospy.sleep( 0.3 )


rfid_pf
Author(s): Travis Deyle
autogenerated on Wed Nov 27 2013 12:03:34