ros_occupancy_grid.py
Go to the documentation of this file.
00001 
00002 import numpy as np, math
00003 
00004 import roslib; roslib.load_manifest('point_cloud_ros')
00005 import rospy
00006 
00007 import hrl_tilting_hokuyo.display_3d_mayavi as d3m
00008 from point_cloud_ros.msg import OccupancyGrid
00009 import point_cloud_ros.occupancy_grid as pog
00010 
00011 ## convert OccupancyGrid message to the  occupancy_grid_3d object.
00012 # @param to_binary - want the occupancy grid to be binarified.
00013 # @return occupancy_grid_3d object
00014 def og_msg_to_og3d(og, to_binary=True):
00015     c = np.matrix([og.center.x, og.center.y, og.center.z]).T
00016     s = np.matrix([og.grid_size.x, og.grid_size.y, og.grid_size.z]).T
00017     r = np.matrix([og.resolution.x, og.resolution.y, og.resolution.z]).T
00018     og3d = pog.occupancy_grid_3d(c, s, r, np.array(og.data),
00019                     og.occupancy_threshold, to_binary = to_binary)
00020     return og3d
00021 
00022 ## convert occupancy_grid_3d object to OccupancyGrid message.
00023 # sets the frame to base_link and stamp to the current time.
00024 # @return OccupancyGrid object
00025 def og3d_to_og_msg(og3d):
00026     og = OccupancyGrid()
00027 
00028     og.center.x = og3d.center[0,0]
00029     og.center.y = og3d.center[1,0]
00030     og.center.z = og3d.center[2,0]
00031 
00032     og.grid_size.x = og3d.size[0,0]
00033     og.grid_size.y = og3d.size[1,0]
00034     og.grid_size.z = og3d.size[2,0]
00035 
00036     og.resolution.x = og3d.resolution[0,0]
00037     og.resolution.y = og3d.resolution[1,0]
00038     og.resolution.z = og3d.resolution[2,0]
00039 
00040     og.occupancy_threshold = 1
00041 
00042     og.data = og3d.grid.flatten().tolist()
00043     og.header.frame_id = 'base_link'
00044     og.header.stamp = rospy.rostime.get_rostime()
00045     return og
00046 
00047 ## create an OccupancyGrid msg object for the purpose of setting the
00048 # grid parameters for pc_to_og node.
00049 # @param center -  3x1 np matrix.
00050 # @param size -  3x1 np matrix.
00051 # @param resolution -  3x1 np matrix.
00052 # @param occupancy_threshold - integer
00053 # @param frame_id - string.
00054 def og_param_msg(center, size, resolution, occupancy_threshold, frame_id):
00055     og = OccupancyGrid()
00056 
00057     og.center.x = center[0,0]
00058     og.center.y = center[1,0]
00059     og.center.z = center[2,0]
00060 
00061     og.grid_size.x = size[0,0]
00062     og.grid_size.y = size[1,0]
00063     og.grid_size.z = size[2,0]
00064 
00065     og.resolution.x = resolution[0,0]
00066     og.resolution.y = resolution[1,0]
00067     og.resolution.z = resolution[2,0]
00068 
00069     og.occupancy_threshold = occupancy_threshold
00070     og.header.frame_id = frame_id
00071     og.header.stamp = rospy.rostime.get_rostime()
00072     return og
00073 
00074 if __name__ == '__main__':
00075     rospy.init_node('og_sample_python')
00076     param_list = [None, False]
00077     rospy.Subscriber('occupancy_grid', OccupancyGrid, cb, param_list)
00078     rospy.logout('Ready')
00079 
00080     while not rospy.is_shutdown():
00081         if param_list[1] == True:
00082             og3d = param_list[0]
00083             print 'grid_shape:', og3d.grid.shape
00084             pts = og3d.grid_to_points()
00085             print pts.shape
00086             break
00087         rospy.sleep(0.1)
00088 
00089     d3m.plot_points(pts)
00090     d3m.show()
00091 
00092 


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