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

Revision history [back]

click to hide/show revision 1
initial version

I believe the best way to do this is to use the boost::shared_ptr<synchronizer>. For example the openni node uses this to synchronize a depth_msg and rgb_msg and pass them as arguments to callback a function. The following code is from the openni_nodelet.cpp:

boost::shared_ptr<synchronizer> depth_rgb_sync_; //from header file

SyncPolicy sync_policy (4); // queue size

depth_rgb_sync_.reset (new Synchronizer (sync_policy));

depth_rgb_sync_->registerCallback (boost::bind (&OpenNINodelet::publishXYZRGBPointCloud, this, _1, _2));

depth_rgb_sync_->add < 1 > (rgb_msg);

depth_rgb_sync_->add < 0 > (depth_msg);

and the callback function is:

void OpenNINodelet::publishXYZRGBPointCloud (const sensor_msgs::ImageConstPtr& depth_msg, const sensor_msgs::ImageConstPtr& rgb_msg) const {}

So you can subscribe to 2 different topics, each having their own message, and in their callback functions you can add the msg to the boost synchronizer. For example in the first callback you can do depth_rgb_sync_->add < 1 > (rgb_msg) and in the second one depth_rgb_sync_->add < 0 > (depth_msg) where depth_rgb_sync_ will be replaced by your boost::shared_ptr<synchronizer> and rgb_msg and depth_msg will be replaced by the messages of the 2 topics. When both messages are received the boost synchronizer will call your function with the 2 msgs as arguments.

Hope this help. Ivan