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

Revision history [back]

click to hide/show revision 1
initial version

The rospy.Service docs show that there isn't a parameter to the service constructor that allows it to pass arguments to the callback.

However, it's relatively easy to do this with a lambda:

def my_hanlder(request, name):
    rp.logwarn(name + "has received the request: " + request)

providers = [
    rp.Service(
        name+'my_service',
        MyServiceType,
        lambda msg: my_handler(msg, name))
    for name in "Alice Bob Carl David".split()]

(my apologies if there's a small syntax error in there; I don't use lambda very often)