labeled_cloud_pub_client.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 #
00003 # Copyright (c) 2010, Georgia Tech Research Corporation
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #     * Redistributions of source code must retain the above copyright
00009 #       notice, this list of conditions and the following disclaimer.
00010 #     * Redistributions in binary form must reproduce the above copyright
00011 #       notice, this list of conditions and the following disclaimer in the
00012 #       documentation and/or other materials provided with the distribution.
00013 #     * Neither the name of the Georgia Tech Research Corporation nor the
00014 #       names of its contributors may be used to endorse or promote products
00015 #       derived from this software without specific prior written permission.
00016 #
00017 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00018 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00021 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00025 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00026 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 #
00028 
00029 #  \author Jason Okerman (Healthcare Robotics Lab, Georgia Tech.)
00030 
00031 import roslib; roslib.load_manifest('pr2_clutter_helper')
00032 import rospy
00033 from std_msgs.msg import String
00034 from sensor_msgs.msg import PointCloud
00035 from sensor_msgs.msg import ChannelFloat32
00036 from geometry_msgs.msg import Point32
00037 from random import *
00038 from pr2_lcs_helper.srv import *
00039 
00040 '''
00041     client to test broadcaster.
00042     
00043     NOT FINISHED YET, have not tested -- hope to soon!
00044 
00045 '''
00046 
00047 
00048 def local_rand_cloud():
00049 
00050     #Create a new cloud object and stuff it
00051     ROS_pointcloud = PointCloud() #sensor_msgs.msg.PointCloud()
00052     x = random()*5 #const offset easy to change.
00053     
00054     #stuff point cloud with random points in a rectangle which drifts over time.
00055     #Add an extra intensity channel as well.
00056     intensity_channel = ChannelFloat32()
00057     intensity_channel.name = 'intensities'
00058     for i in range(3000):
00059         intensity_channel.values += [random()]
00060    
00061     for i in range(3000):
00062         ROS_pointcloud.points += [Point32(random()*5-x,random(), intensity_channel.values[i])]
00063     #rgb color has maximum value of 0xFFFFFF
00064     rgb_channel = ChannelFloat32()
00065     rgb_channel.name = 'rgb'
00066     rgb_channel.values = normList(intensity_channel.values, 0xFF)
00067     
00068     #Separate r,g,b channels range betweeon 0 and 1.0.
00069     r, g, b = [], [], []
00070     for pt in ROS_pointcloud.points: 
00071         b += [pt.y]; 
00072         r += [pt.z];
00073         g += [0];
00074     r_channel = ChannelFloat32(name='r', values = normList(r) )
00075     g_channel = ChannelFloat32(name='g', values = normList(g) )
00076     b_channel = ChannelFloat32(name='b', values = b)
00077     
00078     ROS_pointcloud.channels = (intensity_channel, rgb_channel, r_channel, g_channel, b_channel)
00079     return ROS_pointcloud
00080     
00081 def normList(L, normalizeTo=1):
00082     '''normalize values of a list to make its max = normalizeTo'''
00083     vMax = max(L)
00084     if vMax == 0: vMax = 1; #avoid divide by zero
00085     return [ x/(vMax*1.0)*normalizeTo for x in L]
00086     
00087 def labeled_cloud_pub_client(cloud, frame):
00088     rospy.wait_for_service('pub_cloud_service')
00089     try:
00090         service = rospy.ServiceProxy('pub_cloud_service', CloudPub)
00091         cloud.header = rospy.Header(frame_id=frame)
00092         
00093         resp = service(cloud, frame)
00094         return resp.success #bool
00095     except rospy.ServiceException, e:
00096         print "Service call failed: %s"%e
00097     
00098     
00099 if __name__== "__main__":
00100     print "creating local random pointcloud"
00101     
00102     
00103     cloud = local_rand_cloud()
00104     
00105     print "sending cloud, receiving success/fail"
00106     
00107     frame_id = 'my_frame'
00108     success = labeled_cloud_pub_client(cloud, frame_id)
00109     print "status of success: ", success
00110     n =1
00111     print 'loop'
00112     while True:
00113         cloud = local_rand_cloud()
00114         rospy.sleep(.1)
00115         success = labeled_cloud_pub_client(cloud, frame_id)
00116         print "status of success: ", success, n
00117         n+=1
00118     
00119     
00120     
00121     
00122     
00123     


pr2_clutter_helper
Author(s): Jason Okerman, Advisors: Prof. Charlie Kemp and Jim Regh, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:53:06