Can I detect the currently active nodelet?

asked 2018-03-27 19:04:56 -0500

updated 2018-03-28 12:41:30 -0500

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?

edit retag flag offensive close merge delete

Comments

Can you clarify what you mean with "the active nodelet"? You mean the caller of foo(..)?

gvdhoorn gravatar image gvdhoorn  ( 2018-03-28 02:40:21 -0500 )edit

Not so much the caller of foo, but the nodelet / callback queue which the current callback is being run by

eric-wieser gravatar image eric-wieser  ( 2018-03-28 12:41:03 -0500 )edit

I don't think API exists that let you do this in the way you propose.

Perhaps passing this as an additional arg to some_message_callback(..) using boost::bind(..) or even capturing it with a C++11 lambda could be an alternative?

gvdhoorn gravatar image gvdhoorn  ( 2018-03-28 13:22:57 -0500 )edit

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.

eric-wieser gravatar image eric-wieser  ( 2018-03-28 13:52:50 -0500 )edit

Then I'm afraid I don't know how to do that.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-28 14:17:12 -0500 )edit