ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is my solution:

import sensor_msgs.point_cloud2 as pc2

...

def on_scan(self, scan):
    rospy.loginfo("Got scan, projecting")
    cloud = self.laser_projector.projectLaser(scan)
    gen = pc2.read_points(cloud, skip_nans=True, field_names=("x", "y", "z"))
    self.xyz_generator = gen

The source/documentation for point_cloud2.py is http://docs.ros.org/indigo/api/sensor_msgs/html/point__cloud2_8py_source.html, which describes the read_points method to parse a PointCloud2. From that method source, the format of PointCloud2.data seems to be a series of fields (x, y, z, intensity, index) packed with the struct library. The deserialization in that file is done by:

fmt = _get_struct_fmt(cloud.is_bigendian, cloud.fields, field_names)
width, height, point_step, row_step, data, isnan = cloud.width, cloud.height, cloud.point_step, cloud.row_step, cloud.data, math.isnan
unpack_from = struct.Struct(fmt).unpack_from