Using PointCloud2 data (getting x,y points) in Python
In a Python ROS node, I've subscribed to a sensor_msgs/LaserScan topic, converted them to sensor_msgs/PointCloud2 messages, and am trying to extract X, Y (and Z) point coordinates. The transformation from LaserScan to PointCloud2 uses the LaserProjection class of laser_geometry. What is the data format of sensor_msgs/LaserScan.data? From the documentation and other questions, it's a binary format usually converted in C++ with the pcl_ros or pcl_conversions packages (eg http://answers.ros.org/question/10947... ), but I'm working in Python.
This is my code:
import rospy, math, random
import numpy as np
from sensor_msgs.msg import LaserScan
from laser_geometry import LaserProjection
...
class Lidar():
def __init__(self, scan_topic="/robot_0/base_scan"):
self.scan_sub = rospy.Subscriber(scan_topic, LaserScan, self.on_scan)
self.laser_projector = LaserProjection()
def on_scan(self, scan):
print scan
rospy.loginfo("Got scan, projecting")
cloud = self.laser_projector.projectLaser(scan)
print cloud
rospy.loginfo("Printed cloud")
Thank you in advance!