Go to the documentation of this file.00001
00002 import roslib; roslib.load_manifest('sensor_msgs')
00003 import rospy
00004 import math
00005 from struct import *
00006 from sensor_msgs.msg import *
00007
00008
00009 def talker():
00010 rospy.init_node('empty_cloud_publisher')
00011 pub = rospy.Publisher('empty_cloud', PointCloud2)
00012 frame_id = rospy.get_param('~frame_id', '/base_laser_link')
00013 max_range = rospy.get_param('~max_range', 25.0)
00014 rate = rospy.get_param('~rate', 10)
00015 rotate_points = rospy.get_param('~rotate_points', False)
00016
00017 irange = range(-314, 315)
00018 jrange = range(-314, 315)
00019 msg = PointCloud2()
00020 msg.header.frame_id = frame_id
00021 msg.height = 1
00022 if rotate_points:
00023 msg.width = len(irange) * len(jrange)
00024 else:
00025 msg.width = len(irange)
00026
00027 msg_fieldx = PointField()
00028 msg_fieldy = PointField()
00029 msg_fieldz = PointField()
00030 msg_fieldx.name = 'x'
00031 msg_fieldx.offset = 0
00032 msg_fieldx.datatype = 7
00033 msg_fieldx.count = 1
00034 msg_fieldy.name = 'y'
00035 msg_fieldy.offset = 4
00036 msg_fieldy.datatype = 7
00037 msg_fieldy.count = 1
00038 msg_fieldz.name = 'z'
00039 msg_fieldz.offset = 8
00040 msg_fieldz.datatype = 7
00041 msg_fieldz.count = 1
00042
00043 msg.fields = [msg_fieldx, msg_fieldy, msg_fieldz]
00044 msg.point_step = 16
00045 msg.row_step = msg.point_step * msg.width;
00046 msg.is_dense = True
00047
00048 points = []
00049 for i in irange:
00050 x = max_range * math.cos(i*0.005)
00051 y = max_range * math.sin(i*0.005)
00052 if rotate_points:
00053 for j in jrange:
00054
00055
00056
00057
00058
00059 points.append(pack('<ffff', x * math.cos(j * 0.005), y, -1 * x * math.sin(j * 0.005), 0.0))
00060 else:
00061 points.append(pack('<ffff', x, y, 0.0, 0.0))
00062
00063 msg.data = ''.join(points)
00064
00065 r = rospy.Rate(rate)
00066 while not rospy.is_shutdown():
00067 msg.header.stamp = rospy.Time.now()
00068 pub.publish(msg)
00069 r.sleep()
00070
00071 if __name__ == '__main__':
00072 try:
00073 talker()
00074 except rospy.ROSInterruptException: pass