Issue with message_filters and PointCloud2 in python
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?