Can wait_for_service bring up a service?

asked 2018-12-12 03:53:27 -0500

bliss2006 gravatar image

I wonder if rosservice list should show the service which is later used by rospy.wait_for_service? According to the test below, it is not necessary. Does rospy.wait_for_service brings up a service if it is not run yet?

Longer explanation: I augmented pr2_controller_manager with listing the services before and after:

def load_controller(name):
    service_list = rosservice.get_service_list()
    print('/pr2_controller_manager/load_controller ' + str('/pr2_controller_manager/list_controller_types' in service_list))
    rospy.wait_for_service('pr2_controller_manager/load_controller')
    s = rospy.ServiceProxy('pr2_controller_manager/load_controller', LoadController)
    resp = s.call(LoadControllerRequest(name))
    service_list = rosservice.get_service_list()
    print('/pr2_controller_manager/load_controller ' + str('/pr2_controller_manager/list_controller_types' in service_list))
    if resp.ok:
        print "Loaded", name
        return True
    else:
        print "Error when loading", name
        return False

Output:

/pr2_controller_manager/load_controller False
...
/pr2_controller_manager/load_controller True

A followup question: I implement my own controller manager in a similar way, however, the code freezes at rospy.wait_for_service(), which means that service cannot be brought up. How can I debug it?

edit retag flag offensive close merge delete

Comments

1

Not a full answer, but: no, wait_for_service(..) does not bring up anything. It just waits. Potentially infinitely long, until a service server gets registered with the master.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-12 04:30:49 -0500 )edit

Ok, so another node starts the service while wait_for_service(...) waits for it, right?

bliss2006 gravatar image bliss2006  ( 2018-12-12 05:06:06 -0500 )edit
3

Unless the node that is waiting for the service server also supplies the service, then yes, another node must start the service server.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-12 05:07:53 -0500 )edit