Transforming a pointcloud2 in python

asked 2017-08-08 17:10:04 -0600

zacwitte gravatar image

updated 2017-08-08 18:18:54 -0600

I've searched and searched, but can't find a good answer to this. I'm using python so don't have access to pcl_ros (which seems deprecated anyway?) and other answers are all for older versions of ROS (I'm using kinetic). The tf2_sensor_msgs looks like it's supposed to do it, but I can't import it directly (no module found). I'm using the tf2_ros package with a Transform buffer and listener.

self.transform_buffer = tf2.Buffer()
self.transform_listener = tf2.TransformListener(self.transform_buffer)

# Later I try:
pointcloud = self.transform_buffer.transform(pointcloud, 'base_link')
Error:
  ....

  File "/home/zac/mbot/ros/src/mbot_api/src/web_server.py", line 266, in get_laserscan
    pointcloud = ros_thread.get_velodyne_points_for_time(requested_ts)
  File "/home/zac/mbot/ros/src/mbot_api/src/web_server.py", line 135, in get_velodyne_points_for_time
    pointcloud = self.transform_buffer.transform(pointcloud, 'base_link')
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_ros/buffer_interface.py", line 63, in transform
    do_transform = self.registration.get(type(object_stamped))
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_ros/buffer_interface.py", line 202, in get
    raise TypeException('Type %s if not loaded or supported'% str(key))
TypeException

I'm receiving a PointCloud2 message in the /velodyne frame and I want to transform it into the /base_link frame.

edit retag flag offensive close merge delete