Robotics StackExchange | Archived questions

How to subscribe to multiple image topics using image_transport

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.

Asked by lucas2009 on 2019-06-03 05:14:39 UTC

Comments

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

Asked by PeteBlackerThe3rd on 2019-06-03 12:01:49 UTC

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

Asked by lucas2009 on 2019-06-03 12:13:41 UTC

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

Asked by stevemacenski on 2019-06-03 16:19:31 UTC

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

Asked by lucas2009 on 2019-06-03 21:43:14 UTC

Answers