Is that possible to synchronize an average 5 fps topic with 100 fps topic? Did I init subscriber in corret place?
Hi there,
I have a YOLO detector topic which produces Boundingboxes with average rate 2-5.
My another topic has average 100 rate.
Is that possible to synchronize both topics? And how to set the queue size or any other arguments for sync CallBack?
Right now thw ROS_INFO_STREAM inside synCB does not print onto screen, i.e. synCB is not reacted.
In pupildarknet.h I declare a class and initialize message_filters.Subscriber in the class constructor. Did I initialize in wrong place?
#ifndef PUPILDARKNET_H
#define PUPILDARKNET_H
#include <boost/bind.hpp>
#include <ros/ros.h>
#include <std_msgs/Int8.h>
#include <darknet_ros_msgs/BoundingBox.h>
#include <darknet_ros_msgs/BoundingBoxes.h>
#include <sensor_msgs/Image.h>
#include <pupil_ros_plugin/gaze_positions.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
#include <sensor_msgs/Image.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
class PupilDarknet {
private:
ros::NodeHandle nh_;
ros::Subscriber sub_numDetObj;
pupil_ros_plugin::gaze_positions in_gaze;
cv_bridge::CvImagePtr in_cv_ptr;
darknet_ros_msgs::BoundingBoxes in_bbes;
std_msgs::Int8 numDetObj;
bool verbose;
/// TODO: CHECK DIFF BETWEEN DECLARATION AS PRIVATE MEMBERS AND IN CONSTRUCTOR.
// message_filters::Subscriber<pupil_ros_plugin::gaze_positions> sub_gazePose;
// message_filters::Subscriber<sensor_msgs::Image> sub_image;
// message_filters::Subscriber<darknet_ros_msgs::BoundingBoxes> sub_DarkentBBes;
public:
PupilDarknet(ros::NodeHandle nh) : nh_(nh)
{
numDetObj.data = 0;
message_filters::Subscriber<sensor_msgs::Image> sub_image(nh_,"/camera/rgb/image_raw",30);
message_filters::Subscriber<darknet_ros_msgs::BoundingBoxes> sub_DarkentBBes(nh_,"/darknet_ros/bounding_boxes",30);
message_filters::Subscriber<pupil_ros_plugin::gaze_positions> sub_gazePose(nh_,"/pupil_capture/gaze",30);
typedef message_filters::sync_policies::ApproximateTime<
sensor_msgs::Image,
darknet_ros_msgs::BoundingBoxes,
pupil_ros_plugin::gaze_positions> syncPolicy;
message_filters::Synchronizer<syncPolicy> sync(
syncPolicy(1),
sub_image,
sub_DarkentBBes,
sub_gazePose);
sync.registerCallback(boost::bind(&PupilDarknet::synCB,this, _1,_2,_3));
sub_numDetObj = nh_.subscribe("/darknet_ros/found_object", 1, &PupilDarknet::getNumDetObj, this);
}
~PupilDarknet(){}
void getNumDetObj(std_msgs::Int8 msg);
void synCB(const sensor_msgs::ImageConstPtr& img,
const darknet_ros_msgs::BoundingBoxesConstPtr& BBes,
const pupil_ros_plugin::gaze_positionsConstPtr& gaze);
};
#endif // PUPILDARKNET_H
My cpp file:
void PupilDarknet::synCB(const sensor_msgs::ImageConstPtr& img, const darknet_ros_msgs::BoundingBoxesConstPtr& BBes, const pupil_ros_plugin::gaze_positionsConstPtr& gaze)
{
ROS_INFO_STREAM("Hello This is pupil_darknet synCB...");
}
Yes, the ApproximateTimeSynchronizer will do this.
I would say this is the answer @ahendrix. Did you have a particular reason for not posting it as one?
My synCB is not working, and there is no compile error, so I guess it is the rate differs too much and therefore can not be synchronized.
Or it could because I init subscribers in wrong place.
Try syncPolicy(10) or even higher- 100 or more? I wonder if the queue size for the policy needs to be big enough to hold 50 messages each for the 2 topics + 1 message from the low frequency topic to have a chance at working. (The individual queue sizes for the subscribers are irrelevant?)
And/or the individual subscribers need bigger queue sizes also?http://wiki.ros.org/message_filters/ApproximateTime
I tried out queue_size=1 for everything in rospy and it worked fine with 100:1 ratios between topic frequencies and it works fine. C++ is possibly different.
Thank you @lucasw, I will check this method later.