How to match messages coming from several nodes to be able to cross-reference data based on timestamps?
Hello, I was wondering whether it is possible to cache two synced messages with message_filters API in Melodic?
I got two synced messages:
using namespace sensor_msgs;
message_filters::Subscriber<Image> depth_sub(nodeHandle, "/camera/depth/image_raw", 1);
message_filters::Subscriber<LaserScan> laser_sub(nodeHandle, "/scan", 1);
message_filters::TimeSynchronizer<Image, LaserScan> sync(depth_sub, laser_sub, 10);
And I tried to cache it:
message_filters::Cache< <Image, LaserScan>> cache(sync, 20);
But it didn't work:
/home/alfierra/catkin_ws/src/distance_estimator/src/DistanceEstimator.cpp:11:46: error: template argument 1 is invalid message_filters::Cache< <Image, LaserScan>> cache(sync, 20);
Is there any way to achieve that? Example code to reproduce:
#include <message_filters/subscriber.h>
#include <message_filters/cache.h>
#include <message_filters/time_synchronizer.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/CameraInfo.h>
using namespace sensor_msgs;
using namespace message_filters;
void callback(const ImageConstPtr& image, const CameraInfoConstPtr& cam_info)
{
// Solve all of perception here...
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "vision_node");
ros::NodeHandle nh;
message_filters::Subscriber<Image> image_sub(nh, "image", 1);
message_filters::Subscriber<CameraInfo> info_sub(nh, "camera_info", 1);
TimeSynchronizer<Image, CameraInfo> sync(image_sub, info_sub, 10);
// my attempt
Cache< <Image, LaserScan>> cache(sync, 20);
ros::spin();
return 0;
}
EDIT:
To avoid an xy-problem, could you please explain to readers here why you want to do this?
I'm implementing a package for a robot equipped with a LIDAR and RGBD camera. The robot is supposed to detect objects (chair, person, etc) and estimate the distance to them. The task of the first node is to analyze camera feed, detect objects and publish relevant information (class label and coords of rectangle that encloses the object). The second node's task is to estimate distance to each of detected objects. It subscribes to the first node but it also needs sensor information (Lidar scan and RBGD image) in order to estimate distance. That's why I need a Cache: to be able to store sensor data and retrieve a sample that corresponds to the timestamp of analyzed image.
I thought that synchronizing laserScan and RGBDImage msgs and caching them would be an elegant solution. Although if it's not supported, I'll just cache them independently.
To avoid an xy-problem, could you please explain to readers here why you want to do this?
Thanks, I edited the post.
It would seem this is an xy-problem: you'd like to be able to match messages coming from several nodes to be able to cross-reference data based on timestamps.
Your question title does not reflect this.
You may want to update it.