og_sample.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import numpy as np, math
00004 import time
00005 
00006 import roslib; roslib.load_manifest('point_cloud_ros')
00007 import rospy
00008 
00009 from point_cloud_ros.msg import OccupancyGrid
00010 
00011 import hrl_tilting_hokuyo.display_3d_mayavi as d3m
00012 import point_cloud_ros.ros_occupancy_grid as rog
00013 
00014 def mayavi_cb(og, param_list):
00015     og3d = rog.og_msg_to_og3d(og)
00016     param_list[0] = og3d
00017     param_list[1] = True
00018 
00019 def relay_cb(og, og_pub):
00020     rospy.logout('relay_cb called')
00021     og3d = rog.og_msg_to_og3d(og)
00022     og_new = rog.og3d_to_og_msg(og3d)
00023     og_pub.publish(og_new)
00024 
00025 
00026 def vis_occupancy_cb(og, param_list):
00027     og3d = rog.og_msg_to_og3d(og, to_binary = False)
00028     param_list[0] = og3d
00029     param_list[1] = True
00030 
00031 
00032 if __name__ == '__main__':
00033 
00034     og_pub = rospy.Publisher('relay_og_out', OccupancyGrid)
00035     rospy.Subscriber('relay_og_in', OccupancyGrid, relay_cb, og_pub)
00036     param_list = [None, False]
00037 
00038     rospy.init_node('og_sample_python')
00039     rospy.logout('Ready')
00040 
00041     #mode = rospy.get_param('~mode')
00042     #mode = 'mayavi'
00043     mode = 'vis_occupancy'
00044 
00045     if mode == 'mayavi':
00046         rospy.Subscriber('occupancy_grid', OccupancyGrid, mayavi_cb, param_list)
00047         while not rospy.is_shutdown():
00048             if param_list[1] == True:
00049                 og3d = param_list[0]
00050                 print 'grid_shape:', og3d.grid.shape
00051                 pts = og3d.grid_to_points()
00052                 print pts.shape
00053 #                param_list[1] = False
00054                 break
00055             rospy.sleep(0.1)
00056 
00057         d3m.plot_points(pts)
00058         d3m.show()
00059 
00060     if mode == 'vis_occupancy':
00061         rospy.Subscriber('occupancy_grid', OccupancyGrid, vis_occupancy_cb, param_list)
00062         import matplotlib_util.util as mpu
00063         while not rospy.is_shutdown():
00064             if param_list[1] == True:
00065                 og3d = param_list[0]
00066                 break
00067             rospy.sleep(0.1)
00068         occ_array = og3d.grid.flatten()
00069         mpu.pl.hist(occ_array, 100)
00070 #        mpu.plot_yx(occ_array)
00071         mpu.show()
00072     elif mode == 'relay':
00073         rospy.spin()
00074 
00075 
00076 
00077 
00078 
00079 
00080 


point_cloud_ros
Author(s): Advait Jain (Healthcare Robotics Lab, Georgia Tech)
autogenerated on Wed Nov 27 2013 12:16:42