Ask Your Question
0

Republish a topic data

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

Baumboon gravatar image

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

Hello,

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
1

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

Here's a quick example adapted from the talker.py 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!")
        pub.publish(data)
    return

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

if __name__ == '__main__':
    listener()

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 511 times

Last updated: May 29 '18