I'm using a ROS node (C++ code) to perform some image processing reading images from different visual sensors living in a simulator. I have a big problem that, so far, is without solution...
let's say that my node is active and is performing some operations on an image acquired from a topic"A"; at a certain point (so at run time) i need to unsubscribe from this topic"A" and subscribe from another topic"B" (the name of this topic"B" is communicated to the node by another subscriber) to read images from another visual sensor: i'd like to do that just changing the topic name (using a string variable for instance) and using the same callback used for topic"A".
the difficulties are the following:
i cannot read the all images and choose the one i need: the sensor are too many to handle such a stream of data and, furthermore, this system is not scalable at all.
i need to declare this new subscriber in a scope that "lives" sufficiently long for the process of reading from the topic (it is the reason, i think, the subscribers are defined in the main scope, before the while) but, in the same time, in a scope that gives me the possibility to update the topic (so a sort of loop and not in the part before the while that is performed just one time).
please help me...i really don't know how to do that