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

Hi,

Using Python to do the conversion simplifies a lot.

I wanted to provide an answer using Python instead of C++, that is why I have created a video (https://youtu.be/GvilxcePD64) showing how to use the laser_geometry with Python in order to convert from laser scan to point cloud.

Hope it helps.

Hi,

Using Python to do the conversion simplifies a lot.

I wanted to provide an answer using Python instead of C++, that is why I have created a video (https://youtu.be/GvilxcePD64) showing how to use the laser_geometry with Python in order to convert from laser scan to point cloud.

Edited after suggestion of gvdhoom (thanks a lot for the comment ;-)

The video shows the following steps:

  1. Create a pkg that will contain the node to be launched for conversion of the topic
  2. Create a Python file in the src directory that imports the LaserProjection class from laser_geometry package (that package can be found here: http://wiki.ros.org/laser_geometry)
  3. Create a subscriber to the laser topic
  4. Create a publisher that will publish PointCloud2 messages
  5. On the callback of the laser subscriber, we take the laser scan, and by means of the LaserProjection class, we convert it into a PointCloud2
  6. On the same callback, we publish the point cloud
  7. We test everything with a simulated turtlebot and observe the result in Rviz

Hope it helps.

Hi,

Using Python to do the conversion simplifies a lot.

I wanted to lot. Let's see how to do that using the laser_geometry package.

First, you need to launch the laser_geometry package from a launch file, properly configured. Here a suggested launch file:

<launch>
<node type="laser_scan_assembler" pkg="laser_assembler"
    name="my_assembler">
<remap from="scan" to="laser_scan"/>
<param name="max_scans" type="int" value="400" />
<param name="fixed_frame" type="string" value="my_robot_link_base" />
 </node>
  <node type ="laser2pc.py" pkg="laser_to_pcl" name="laser2pc"/>
</launch>

That file launches the laser_geometry package indicating that the frame from which the transform will be done is the my_robot_link_base (that is whatever tf link of your robot you want the point cloud to be refered from). Another parameter is the max_scans which indicates the max number of last scans that will be take into account for the computation of the point cloud ( this is useful in case your laser is rotating, so you can generate a full 3D cloud).

The launch file above also launches a second node that is the one you have to create to get the data and publish it into your selected topic. What should be the code of such a node? Check the following:

#!/usr/bin/env python

import rospy 
from laser_assembler.srv import AssembleScans2
from sensor_msgs.msg import PointCloud2

rospy.init_node("assemble_scans_to_cloud")
rospy.wait_for_service("assemble_scans2")
assemble_scans = rospy.ServiceProxy('assemble_scans2', AssembleScans2)
pub = rospy.Publisher ("/laser_pointcloud", PointCloud2, queue_size=1)

r = rospy.Rate (1)

while (True):
    try:
        resp = assemble_scans(rospy.Time(0,0), rospy.get_rostime())
        print "Got cloud with %u points" % len(resp.cloud.data)
        pub.publish (resp.cloud)

    except rospy.ServiceException, e:
        print "Service call failed: %s"%e

    r.sleep()

The code shows how to subscribe to the assemble_scans2 service. That is the one that will provide an the point cloud on its answer. The code also shows that the point cloud will be published on a topic of type PoinCloud2. basically, the while loop what it does is, first, call to the service, then publish the answer using Python instead of C++, that is why of the service into a topic.

I have created a video (https://youtu.be/GvilxcePD64) showing how to use the laser_geometry with Python in order to convert from laser scan to point cloud.

Edited after suggestion of gvdhoom (thanks a lot for the comment ;-)

The video shows the following steps:

  1. Create a pkg that will contain the node to be launched for conversion of the topic
  2. Create a Python file in the src directory that imports the LaserProjection class from laser_geometry package (that package can be found here: http://wiki.ros.org/laser_geometry)
  3. Create a subscriber to the laser topic
  4. Create a publisher that will publish PointCloud2 messages
  5. On the callback of the laser subscriber, we take the laser scan, and by means of the LaserProjection class, we convert it into a PointCloud2
  6. On the same callback, we publish the point cloud
  7. We test everything with a simulated turtlebot and observe the result in Rviz
practical example.

Hope it helps.