How to subscribe to multiple image topics using image_transport

asked 2019-06-03 05:14:39 -0500

lucas2009 gravatar image

updated 2019-06-03 21:40:52 -0500

Hi,

I would like to subscribe multiple images using image_transport. Here is my code snapshot:

std::vecotr<std::string> topics = {"topicA", "topicB"};
mage_transport::ImageTransport it_(nh);
std::vector<image_transport::Subscriber> subs_;
for(size_t i = 0; i < topics.size(); i++) {
       subs_.push_back(it_->subscribe(topics[i], 1, &Process::ImageCallback, this)); 
}

When launching the node, I got the error: Tried to advertise a service that is already advertised in this node

Any suggestion is much appreciated. Thank you.

-----Update 20190604-------- This is a simplified code repo that reproduces the error: https://github.com/panda9095/example.

edit retag flag offensive close merge delete

Comments

Are you sure this error is being caused by the code above? It seems to be referring to service servers, not subscribers.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2019-06-03 12:01:49 -0500 )edit

Yes. If the size of topics is set to 1, everything works fine.

lucas2009 gravatar imagelucas2009 ( 2019-06-03 12:13:41 -0500 )edit

Can you give me a specific example of the topics you're subscribing to? I suspect that may help.

stevemacenski gravatar imagestevemacenski ( 2019-06-03 16:19:31 -0500 )edit

FYI, a github repo reproducing the error is updated. Thx. code

lucas2009 gravatar imagelucas2009 ( 2019-06-03 21:43:14 -0500 )edit