Ask Your Question

endrju's profile - activity

2021-04-27 07:56:54 -0600 received badge  Famous Question (source)
2019-12-15 13:44:49 -0600 received badge  Notable Question (source)
2019-12-15 11:16:05 -0600 edited question How to match messages coming from several nodes to be able to cross-reference data based on timestamps?

Is it possible to chain TimeSynchronizer with Cache? Hello, I was wondering whether it is possible to cache two synced m

2019-12-15 11:06:49 -0600 marked best answer 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.

2019-12-15 11:06:49 -0600 received badge  Scholar (source)
2019-12-15 11:06:48 -0600 received badge  Supporter (source)
2019-12-15 11:06:45 -0600 commented answer How to match messages coming from several nodes to be able to cross-reference data based on timestamps?

You understood correctly. Your solution is much simpler - although won't the delay be a problem here? Camera outputs ~90

2019-12-15 10:33:21 -0600 received badge  Popular Question (source)
2019-12-15 09:03:08 -0600 edited question How to match messages coming from several nodes to be able to cross-reference data based on timestamps?

Is it possible to chain TimeSynchronizer with Cache? Hello, I was wondering whether it is possible to cache two synced m

2019-12-15 09:03:08 -0600 received badge  Editor (source)
2019-12-15 09:01:51 -0600 commented question How to match messages coming from several nodes to be able to cross-reference data based on timestamps?

Thanks, I edited the post.

2019-12-15 09:01:27 -0600 commented question How to match messages coming from several nodes to be able to cross-reference data based on timestamps?

Thanks, I edited a post.

2019-12-15 08:59:56 -0600 edited question How to match messages coming from several nodes to be able to cross-reference data based on timestamps?

Is it possible to chain TimeSynchronizer with Cache? Hello, I was wondering whether it is possible to cache two synced m

2019-12-15 07:33:25 -0600 asked a question How to match messages coming from several nodes to be able to cross-reference data based on timestamps?

Is it possible to chain TimeSynchronizer with Cache? Hello, I was wondering whether it is possible to cache two synced m