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

Python ApproximateTimeSynchronizer not working

asked 2015-11-18 23:29:42 -0600

Markus Eich gravatar image

Dear all,

I want to subscribe to synchronized depth and rgb images using message_filters and ApproximateTImeSynchoronizer.

def rgb_callback(image):
     rospy.loginfo("got RGB image")

def depth_callback(image):
    rospy.loginfo("got DEPTH image")

def scan_callback(image,depth):
    rospy.loginfo("got synched images")


def hand_tracker():

    rospy.init_node('hand_tracker')
    image_sub=message_filters.Subscriber('/kinect2/hd/image_color_rect',Image)
    depth_sub=message_filters.Subscriber('/kinect2/hd/image_dept_rect',Image)        

    rospy.Subscriber('/kinect2/hd/image_color_rect',Image,rgb_callback)    
    rospy.Subscriber('/kinect2/hd/image_depth_rect',Image,depth_callback)    

    ts=message_filters.ApproximateTimeSynchronizer([image_sub,depth_sub],10,1)    
    ts.registerCallback(scan_callback)
    try:
        rospy.spin()
    except KeyboardInterrupt:        
        print "Shutting down"

The problem is that rgb callback and depth callback are called, but the scan_callback using ApproximateTimeSynchronizer not. Is it a bug or is there something I am doing wrong?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-11-20 05:51:39 -0600

Chrissi gravatar image

This is something I recently discovered as well, you cannot subscribe to the same topic twice from within the same node. The second subscribers is just ignored and the callback will never be called. Try removing the

rospy.Subscriber('/kinect2/hd/image_color_rect',Image,rgb_callback)    
rospy.Subscriber('/kinect2/hd/image_depth_rect',Image,depth_callback)

and see if your scan callback is now called.

edit flag offensive delete link more

Comments

This is in conflict with this post here that says you can subscribe to the same topic multiple times within one node: https://answers.ros.org/question/2892...

zkytony gravatar image zkytony  ( 2022-09-05 12:22:56 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-11-18 23:29:42 -0600

Seen: 1,810 times

Last updated: Nov 20 '15