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

subscribe to 4 different topics with 2 asus xtions callback error

asked 2014-07-22 15:12:37 -0600

lukashernandez gravatar image

updated 2014-07-22 15:32:33 -0600

Hello everyone,

I have 2 asus xtions and want to subscribe to both of the depth and rgb topics. But the callback of all 4 topics in my program never gets called. The problem only occurs when I subscribe to 4 different topics. Subscribing let's say twice the same depth topic works fine. I checked the topics in rviz and they are all correct. This is the code where I register the callback

message_filters::Subscriber<sensor_msgs::Image> depthSub1(nh, "/camera1/depth/image", 1);
message_filters::Subscriber<sensor_msgs::Image> colorSub1(nh, "/camera1/rgb/image_color", 1);
message_filters::Subscriber<sensor_msgs::Image> depthSub2(nh, "/camera2/depth/image", 1);
message_filters::Subscriber<sensor_msgs::Image> colorSub2(nh, "/camera2/rgb/image_color", 1);
message_filters::Synchronizer<SyncPolicy> sync(SyncPolicy(10), depthSub1, colorSub1,depthSub2, colorSub2);

sync.registerCallback(boost::bind(&PointCloudCalibration::callbackCombi, this, _1, _2, _3, _4));

SyncPolicy is defined as:

typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image,sensor_msgs::Image, sensor_msgs::Image > SyncPolicy;

When I change depthSub2 "/camera2/depth/image" to "/camera1/depth/image" it works. It appears to me like if it would not be possible to subscribe to 4 different topics.

How can I fix that and what might be the reason?

Thanks in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by ┬╗ oldest newest most voted

answered 2014-07-26 08:54:09 -0600

lukashernandez gravatar image

Finally I know what the problem was, thanks for your help, because it made me realize that the frequency was too low. I used 2 USB 2.0 interfaces because the xtion didn't work with USB 3.0. But for USB 2.0 the bandwidth was too high, so I updated the cameras firmware and now they work with USB 3.0 and my problems are gone :)

edit flag offensive delete link more

answered 2014-07-22 19:21:37 -0600

demmeln gravatar image

Have you confirmed your camera2 is being published correctly? Does it work if you subscribe to 4 topics from camera2? Have you confirmed that the timestamps from camera1 and camera2 are properly synced, i.e. reasonably close in comparison to the queue size and frame rate? What happens when you dramatically increase the queue size from 10 to say 10000?

edit flag offensive delete link more


It makes no difference if I subsribe to camera 1 or 2 and in rviz both are displayed correctly, they also have the same frame rate (30 hz). Increasing the queue didn't help either. How can I check the timestamps? I didn't find the command to do so. Thanks for your help!

lukashernandez gravatar image lukashernandez  ( 2014-07-23 10:20:02 -0600 )edit

`rostopic echo /camera1/depth/image/header/stamp` in one terminal and `rostopic echo /camera2/depth/image/header/stamp` in another to view side by side

demmeln gravatar image demmeln  ( 2014-07-23 10:37:51 -0600 )edit

Ok I checked that, the weird thing is that when i subscribe to both the rgb and the depth topics of camera1, very few messages are send out. secs: 1406138337 nsecs: 431660880 --- secs: 1406138338 nsecs: 100028746 for camera 2 It was secs: 1406138339 nsecs: 428893245 --- secs: 1406138339 nsecs: 462437619

lukashernandez gravatar image lukashernandez  ( 2014-07-23 11:03:38 -0600 )edit

so it seems like my program slows down the publishing rate when it subscribes to both rgb and depth??

lukashernandez gravatar image lukashernandez  ( 2014-07-23 11:05:39 -0600 )edit

I checked it with rostopic hz /camera1/depth/image when my program was running and average rate: 3.790

lukashernandez gravatar image lukashernandez  ( 2014-07-23 11:12:53 -0600 )edit

This is probably part of the problem. Does your callback every get invoked if you increase the queue size of the Synchronizer?

demmeln gravatar image demmeln  ( 2014-07-23 13:46:35 -0600 )edit

Also, try to add callbacks to the 4 indiviual message_filters::Subscriber at the same time as the combined callback and in each individual callback print the timestamp of the arriving message to help debugging.

demmeln gravatar image demmeln  ( 2014-07-23 18:51:32 -0600 )edit

Also increase the tolerance for how close all the messages need to be for a match. documents several parameters.

tfoote gravatar image tfoote  ( 2014-07-24 12:40:01 -0600 )edit

Question Tools

1 follower


Asked: 2014-07-22 15:12:37 -0600

Seen: 264 times

Last updated: Jul 22 '14