Can I detect the currently active nodelet?
I have a helper function that I want to calls NODELET_INFO
within:
void foo(int x) {
NODELET_INFO_STREAM("X is " << x);
}
class MyNodelet : public ::nodelet::Nodelet {
...
void some_message_callback(const SomeMsg::ConstPtr &msg) {
foo(3)
}
}
Obviously, this doesn't work, because the nodelet is not available within the helper function.
My next idea would be to somehow get the active nodelet:
void foo(int x) {
nodelet::Nodelet *n = get_the_active_nodelet_somehow();
ROS_INFO_STREAM_NAMED(n->getName(), "X is " << x);
}
Does a function like get_the_active_nodelet_somehow
exist?
Can you clarify what you mean with "the active nodelet"? You mean the caller of
foo(..)
?Not so much the caller of
foo
, but the nodelet / callback queue which the current callback is being run byI don't think API exists that let you do this in the way you propose.
Perhaps passing
this
as an additional arg tosome_message_callback(..)
usingboost::bind(..)
or even capturing it with a C++11 lambda could be an alternative?The problem is, then I have to pass it all the way down to
foo
- I don't want to make a huge mess of my API just to get hold of an appropriate logger object.Then I'm afraid I don't know how to do that.