[ros-users] How to identify the subscriber or the topic name related to a callback
leibs at willowgarage.com
Tue Feb 1 19:42:41 UTC 2011
On Tue, Feb 1, 2011 at 10:22 AM, Brian Gerkey <gerkey at willowgarage.com> wrote:
> On Mon, Jan 31, 2011 at 5:46 AM, Markus Bader <markus.bader at tuwien.ac.at> wrote:
>> I have multiple subscriber calling the same callback function. How can
>> I determinate within my callback function the related topic name?
>> getPublisherName gives me the related publisher but not the topic?
> hi Markus,
> At the time that you make the subscription, you can arrange for the
> topic to be passed into the callback, using boost::bind. Appended
> below is a simple example that demonstrates this.
While Brian's recommendation certainly works, and is a useful pattern
for storing arbitrary data along with a generic callback, a different
approach is to use the "MessageEvent" callback signature instead.
The connection_header is a std::map of std::strings, including keys,
"topic" and "callerid" among others. This can be very useful for
getting more information about the context of your callback than just
More information about the ros-users