Ask Your Question

Revision history [back]

Here's a quick example adapted from the in the tutorials:

#!/usr/bin/env python
import rospy
from sensor_msgs.msg import PointCloud2
import random

def callback(data, pub):
    # Here would be a place to do some sort of computation to decide if you want
    # the data republished on the new topic. I've inserted a dummy computation.:
    if random.randint(1,10) <= 5:
        rospy.loginfo("republish this cloud!")

def listener():
    pub = rospy.Publisher("pcd_points", PointCloud2, queue_size=1)
    rospy.Subscriber("depth/points", PointCloud2, callback, callback_args=(pub))

if __name__ == '__main__':

The only real differences are:

  • In the callback you'd want to decide if this is a topic that you would want published for the pointcloud_to_pcd node to save as a pcd file.
  • I've used the callback_args optional argument to the Subscriber constructor so that we can keep using the same Publisher object for all publishing on the pcd_points topic.