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

If you make sure to make the services of those nodes private (ie: advertise(..) them on a private nodehandle, or prefix the service name with the node name), then you just need to prefix the nodename to the service name when you create the service proxy as well.

Alternatively, you could start nodes in namespaces, which will automatically prefix service names (provided the service names haven't been made global (ie: start with a /).

If you make sure to make the services of those nodes private (ie: advertise(..) them on a private nodehandle, or prefix the service name with the node name), then you just need to prefix the nodename to the service name when you create the service proxy as well.

Alternatively, you could start nodes in namespaces, which will automatically prefix service names (provided the service names haven't been made global (ie: start with a /).


Edit:

Hi, Thanks for the response :) Are you suggesting something like to start the server:

s = rospy.Service(' serviceRequest = rospy.ServiceProxy('NodeName/ServiceName', NodeName_ServiceName, callback_function)

No. That doesn't make sense to me.

Note: there is nothing magical about service names, they are just strings that we use as an address or URI.

To advertise a service in rospy that is private to n0, do something like (from the Writing a Simple Service and Client tutorial):

s = rospy.Service('~/add_two_ints', AddTwoInts, handle_add_two_ints)

This should result in a /n0/add_two_ints service server. Note the ~. We could use the node name, but if a consumer of your node specifies a different name (fi in their launch file), your service won't be properly prefixed.

In your service client you'd have to know that the service server is named n0, and you can then do (again from the tutorial):

add_two_ints = rospy.ServiceProxy('/n0/add_two_ints', AddTwoInts)

If you don't want start private services, you could also use namespacing, but that will require your client to be in the same namespace as your server, or you need to provide your client with the required information (ie: the namespace).

If you make sure to make the services of those nodes private (ie: advertise(..) them on a private nodehandle, or prefix the service name with the node name), then you just need to prefix the nodename to the service name when you create the service proxy as well.

Alternatively, you could start nodes in namespaces, which will automatically prefix service names (provided the service names haven't been made global (ie: start with a /).


Edit:

Hi, Thanks for the response :) Are you suggesting something like to start the server:

s = rospy.Service(' serviceRequest = rospy.ServiceProxy('NodeName/ServiceName', NodeName_ServiceName, callback_function)

No. That doesn't make sense to me.

Note: there is nothing magical about service names, they are just strings that we use as an address or URI.

To advertise a service in rospy that is private to n0, do something like (from the Writing a Simple Service and Client tutorial):

s = rospy.Service('~/add_two_ints', AddTwoInts, handle_add_two_ints)

This should result in a /n0/add_two_ints service server. Note the ~. We could use the node name, but if a consumer user of your node specifies a different name (fi in their launch file), your service won't be properly prefixed.

In your service client you'd have to know that the service server is named n0, and you can then do (again from the tutorial):

add_two_ints = rospy.ServiceProxy('/n0/add_two_ints', AddTwoInts)

If you don't want start private services, you could also use namespacing, but that will require your client to be in the same namespace as your server, or you need to provide your client with the required information (ie: the namespace).