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

Issue with message_filters and PointCloud2 in python

asked 2019-02-07 13:58:21 -0500

pedram.ghz gravatar image

I want to subscribe to pointcloud data and image data and sync them and then publish them again. I have written a short and simple script for this:

import rospy
from sensor_msgs.msg import Image as SesnorImage
from sensor_msgs.msg import CameraInfo
# from sensor_msgs.msg import PointCloud2
import message_filters


class synchronizer:
    def __init__(self):
        self.pub_Image = rospy.Publisher('image_raw_sync', SesnorImage, queue_size=1)
        self.pub_Cam_Info = rospy.Publisher('camera_info_sync', CameraInfo, queue_size=1)
        # self.pub_Lidar = rospy.Publisher('rslidar_points_sync', PointCloud2, queue_size=1)

        self.imageInput = message_filters.Subscriber('/image_raw', SesnorImage)
        self.cameraInfo = message_filters.Subscriber('/camera_info', CameraInfo)
        # self.lidar = message_filters.Subscriber('/rslidar_points', PointCloud2)

        self.ts = message_filters.TimeSynchronizer([self.imageInput
                                                    ,self.cameraInfo
                                                    # , self.lidar
                                                    ], 10)
        self.ts.registerCallback(self.general_callback)

        self._image_raw = SesnorImage()
        self._camera_info = CameraInfo()
        # self._rslidar_points = PointCloud2()

    def general_callback(self
                         , image_raw
                         , camera_info
                         # , rslidar_points
                         ):
        self._image_raw = image_raw
        self._camera_info = camera_info
        # self._rslidar_points = rslidar_points

    def publisher(self):
        while True:
            self.pub_Image.publish(self._image_raw)
            self.pub_Cam_Info.publish(self._camera_info)
            # self.pub_Lidar.publish(self._rslidar_points)


if __name__ == '__main__':
    rospy.init_node('synchronizer')
    synchronizer = synchronizer()
    synchronizer.publisher()
    rospy.spin()

But when I uncomment the commented lines, there would be no data in the published topics! so when I add the PointCloud2 sensor messages, everything gows bad and I dont know why this is happening. Why is this happening?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-02-10 04:50:43 -0500

pedram.ghz gravatar image

updated 2019-02-10 04:52:09 -0500

@gvdhoorn is right... So, in my case, the problem was that one of the topics was publishing messages with time stamp 0 all the time.

edit flag offensive delete link more
0

answered 2019-02-07 16:29:57 -0500

I suspect you want to be using the approximate time synchronizer, since the image messages and point cloud messages will be unlikely to have identical time stamps.

If the point clouds are being published with slightly different time stamps to the image messages then you would expect the callback to never be called, since there are never three messages with identical time straps.

Hope this helps.

edit flag offensive delete link more

Comments

Thanks for your answer, actually I tried that one as well but there is no difference! I also tried commenting the lines related to camera_info and image_raw and uncomment the pointcloud lines but still, it cannot subscribe to that only topic(rslidar_points).

pedram.ghz gravatar image pedram.ghz  ( 2019-02-08 03:25:08 -0500 )edit

I mean even I cannot subscribe to just one topic of pointloud data(rslidar_points) and the process does not enter the subscriber's callback function at all.

pedram.ghz gravatar image pedram.ghz  ( 2019-02-08 03:27:38 -0500 )edit

Are you sure PointClouds are being published? Is the topic correct?

gvdhoorn gravatar image gvdhoorn  ( 2019-02-08 03:43:36 -0500 )edit

yeap, everything seems to be fine :) :( :)

pedram.ghz gravatar image pedram.ghz  ( 2019-02-08 04:34:22 -0500 )edit

Just for a sanity check do you want to setup 3 normal subscribers to each topic and print the topic name and timestamp each time one is received.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-02-08 04:42:08 -0500 )edit

Thanks to all of you! as Pete suggested, I checked the topics with normal subscribers and figured out the problem was with the time stamps. Now the problem is solved :)

pedram.ghz gravatar image pedram.ghz  ( 2019-02-08 05:59:55 -0500 )edit
1

I checked the topics with normal subscribers and figured out the problem was with the time stamps

so what was the problem with the timestamps?

Future readers of this Q&A will be very grateful if you could provide a little more information on what exactly was wrong with them.

gvdhoorn gravatar image gvdhoorn  ( 2019-02-08 06:04:43 -0500 )edit

I am facing the same problem, can you explain me how the problem is solved by checking the time stamps?. I am stuck in the same thing.

gautamjain gravatar image gautamjain  ( 2019-10-23 09:30:59 -0500 )edit

Question Tools

Stats

Asked: 2019-02-07 13:58:21 -0500

Seen: 872 times

Last updated: Feb 10 '19