Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 import roslib; roslib.load_manifest('pr2_clutter_helper')
00032 from pr2_lcs_helper.srv import *
00033 import rospy
00034 from std_msgs.msg import String
00035 from sensor_msgs.msg import PointCloud
00036 from sensor_msgs.msg import ChannelFloat32
00037 from geometry_msgs.msg import Point32
00038
00039 '''
00040 This function publishes a sensor_msgs.msg.PointCloud object for rviz
00041 It doesn't import anything but generates points in a rectangular region and
00042 lets this region move accross the screen over time.
00043
00044 The frame is '/my_frame', so rviz view frame must be changed accordingly.
00045
00046 NOT FINISHED YET, have not tested -- hope to soon!
00047
00048 '''
00049
00050 pub=''
00051
00052 def handle_service_request(req):
00053
00054 cloud = req.cloud
00055 try:
00056
00057
00058
00059 print 'sending cloud at time', cloud.header.stamp, '&', rospy.Time.now()
00060 global pub
00061 pub.publish(cloud)
00062 return True
00063 except:
00064 return False
00065
00066
00067 def start_server():
00068 rospy.init_node('cloud_broadcaster_node')
00069 s = rospy.Service('pub_cloud_service', CloudPub, handle_service_request)
00070 print "Ready to publish cloud"
00071
00072 global pub
00073 pub = start_publisher()
00074
00075 rospy.spin()
00076
00077
00078
00079 def start_publisher():
00080
00081 pub = rospy.Publisher('my_cloud_chatter', PointCloud)
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 return pub
00093
00094
00095 if __name__ == '__main__':
00096 try:
00097
00098 start_server()
00099
00100 except rospy.ROSInterruptException: pass
00101
00102 '''
00103 def local_rand_cloud()
00104 ### Create a new cloud object and stuff it
00105 from random import *
00106
00107 ROS_pointcloud = PointCloud() #sensor_msgs.msg.PointCloud()
00108 x = 0 #const offset easy to change.
00109
00110 #stuff point cloud with random points in a rectangle which drifts over time.
00111 #Add an extra intensity channel as well.
00112 intensity_channel = ChannelFloat32()
00113 intensity_channel.name = 'intensities'
00114 for i in range(3000):
00115 intensity_channel.values += [random()]
00116
00117 for i in range(3000):
00118 ROS_pointcloud.points += [Point32(random()*5-x,random(), intensity_channel.values[i])]
00119 #rgb color has maximum value of 0xFFFFFF
00120 rgb_channel = ChannelFloat32()
00121 rgb_channel.name = 'rgb'
00122 rgb_channel.values = normList(intensity_channel.values, 0xFF)
00123
00124 #Separate r,g,b channels range betweeon 0 and 1.0.
00125 r, g, b = [], [], []
00126 for pt in ROS_pointcloud.points:
00127 b += [pt.y];
00128 r += [pt.z];
00129 g += [0];
00130 r_channel = ChannelFloat32(name='r', values = normList(r) )
00131 g_channel = ChannelFloat32(name='g', values = normList(g) )
00132 b_channel = ChannelFloat32(name='b', values = b)
00133
00134 ROS_pointcloud.channels = (intensity_channel, rgb_channel, r_channel, g_channel, b_channel)
00135 return ROS_pointcloud
00136
00137 def normList(L, normalizeTo=1):
00138
00139 vMax = max(L)
00140 if vMax == 0: vMax = 1;
00141 return [ x/(vMax*1.0)*normalizeTo for x in L]
00142
00143 '''
00144
00145
00146