ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

I'm assuming you mean the service callback with service function.

Basically you have to possibilities.

  1. If you really want to use the NodeHandle that is created outside the service callback, make this a member variable (if you are using a class) and just access that, or make it a global variable (if you don't have a class). No need to pass it to the service callback.
  2. You can just create a new NodeHandle in the scope of the service callback. You can have as many NodeHandles as you want. And then use this to retrieve the parameter. Again, no need to pass it in.

Thus, my suggestion would be to use 1 if you have a class (obviously, the service callback needs to be a member function of the class as well) and 2 if you don't.

(As both ways are trivial, I'll not provide example code for now.)