Two Topics with Same Callback
Hi everyone,
I am subscribing to two different topics (each with different md5sums) using a single callback. I am using the message_filters
class to achieve this. In my broadcaster, I am publishing a point cloud
and an opencv image
. I want to subscribe in a separate code. My callback signature looks like so:
void callback(const sensor_msgs::ImageConstPtr& ensensoImage, const sensor_msgs::PointCloud2ConstPtr& ensensoCloud)
{
cv::Mat ir;
PointCloudT cloud;
getImage(ensensoImage, ir);
getCloud(ensensoCloud, cloud);
ROS_INFO_STREAM("cloud: " << cloud);
std::lock_guard<std::mutex> lock(mutex);
this->ir = ir;
this->cloud = cloud;
updateImage = true;
updateCloud = true;
}
When I run my code, however, I get an std::terminate
as follows:
user@user:~/catkin_ws$ rosrun ensenso ensenso_viewer
terminate called after throwing an instance of 'ros::ConflictingSubscriptionException'
what(): Tried to subscribe to a topic with the same name but different md5sum as a topic that was already subscribed [sensor_msgs/PointCloud2/1158d486dd51d683ce2f1be655c3c181 vs. sensor_msgs/Image/060021388200f6f0f447d0fcd9c64743]
Aborted (core dumped)
Is it not possible to have a callback with different classes of a namespace or am I missing something?
For reference, the whole code is here.
I would appreciate any help. Thanks!
Why do you even need to do this in 1 callback function? Why don't just use 2 callback functions, store the data and create another function using the data? I've never encountered this approach and according to the error you've got it's not maybe even supported.
Did you read that I was using message_filters? The parameters are templated and the user should be free to put their classes within the policies as they might deem fit. I want to receive two different topics in a particular time. An ordinary callback would not fit my purpose.