ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Republish a topic data

asked 2018-05-29 09:26:12 -0500

Baumboon gravatar image

updated 2018-05-29 09:30:26 -0500


first of all here is my setup : Ubuntu 16.04 with ROS kinetic and Gazebo 7.0.

I have a Scenario where a simulated turtlebot drives to several objects. Actual i need some pointcloud data from him but only from the approach.

I got already some help from jarvisschultz, he helps me with the idea to use pointcloud_to_pcd to subscribe a node that only publishs pointcloud data during the approach. My question now is how to republish the pointcloud data from /depth/points ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-29 14:01:47 -0500

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.
edit flag offensive delete link more

Question Tools



Asked: 2018-05-29 09:26:12 -0500

Seen: 1,942 times

Last updated: May 29 '18