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

Distinguish Services from different nodes with same name

asked 2017-09-11 00:12:37 -0500

amarbanerjee23 gravatar image

Hi, I wish to create 2 rosnodes with some services having same name. E.g. rosnode N1 has services S1,S2,S4 and rosnode N2 has services S2,S3,S5. The reason to have services of same name is because they for a part of a generic description. However, I am not able to find a solution which can help me call the service from a specific node like N1.S2 and N2.S2. I am using python as my programming environment.

Also is it possible to get the proxy object of one node into another ?Like proxyForN1 = someRosCode.getProxyForNode('N1') The call the service of that node from the proxy like proxyForN1 .callService('S2') ?

It would be great if anyone could help out here !! Cheers !!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-09-11 01:14:28 -0500

gvdhoorn gravatar image

updated 2017-09-11 02:11:07 -0500

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 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).

edit flag offensive delete link more

Comments

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) ??

amarbanerjee23 gravatar image amarbanerjee23  ( 2017-09-11 01:22:57 -0500 )edit

If not, could you please give a small example ?? :) Cheers !!

amarbanerjee23 gravatar image amarbanerjee23  ( 2017-09-11 01:26:40 -0500 )edit

Note btw that hard-coding node names like this is not very flexible and will most likely make re-use of your nodes outside this narrow use-case more difficult than it could/should be.

gvdhoorn gravatar image gvdhoorn  ( 2017-09-11 02:09:38 -0500 )edit

Hi @gvdhoorn, The suggested solution works completely fine. I see your point you said above, but for now my problem will be solved !! Thanks a lot man !! Cheers !!

amarbanerjee23 gravatar image amarbanerjee23  ( 2017-09-12 03:36:32 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-09-11 00:12:37 -0500

Seen: 1,358 times

Last updated: Sep 11 '17