Robotics StackExchange | Archived questions

Filling up Point Cloud in ROS Python

I looked at this: http://answers.ros.org/question/207071/how-to-fill-up-a-pointcloud-message-with-data-in-python/

And tried the following:

Point cloud

    h = std_msgs.msg.Header()
    h.stamp = rospy.Time.now()
    pcl = PointCloud()
    pcl.header = h
    pcl.points = self.Npop_particles
    pcl.channels = 3
    point = Point()

    print pcl.points

    for i in range(0, self.Npop_particles):
        point.x = 0
        point.y = 0
        point.z = 0
        pcl.points[i].x = point.x
        pcl.points[i].y = point.y
        pcl.points[i].z = point.z

But I get an error saying pcl.points[i] is an integer:

print pcl.points[i].x TypeError: 'int' object has no attribute 'getitem'

Asked by soulslicer on 2015-10-08 03:10:54 UTC

Comments

Answers

That's because pcl.points is a binary blob. If you want to modify the coordinates you will need to parse this blob according to the point cloud type specification in pcl library. For example, if you are working with message storing pcl::PointCloud<pcl::PointXYZ>, each point is represented as 3 floats for coordinates and one float for padding.

Asked by VitaliyProoks on 2015-10-08 03:32:04 UTC

Comments

this is python code!

Asked by soulslicer on 2015-10-08 04:01:06 UTC

also..now i get this error: field channels must be a list or tuple type

How am i suppose to fill up the field

Asked by soulslicer on 2015-10-08 04:02:36 UTC

Yes, my answer applies to your python code. But you will need to read C++ docs to achieve your task.

Asked by VitaliyProoks on 2015-10-08 07:41:07 UTC