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

ROS2 service only sometimes present in python

asked 2022-07-21 07:52:15 -0600

Zeckurbo gravatar image

updated 2022-07-21 08:43:37 -0600


On Ubuntu 20.4 with ros2 foxy installed, I am currently running a python script (as root), where I want to get some information from a ros2 service (/get_entity_state from gazebo, also running as root).

Normally, everything works fine, but sometimes, when I start up my script (like the client in this tutorial) , only some services are present (via node.get_service_names_and_types():


The daemon is running, and in console, all services are present, so I would have expected for this to not be possible. After some more tries, normally the services appear again, but it is not clear to me, why. Also sometimes ros2 service list (and also the topics) will be completely empty, while a call to a service is successfully done in the same console, or the console will show no services, but python does, or vice versa.

I am not a ROS expert, so maybe I am missing something here, but shouldn't the service be always available (or at least visible), if the daemon is running?

Thank you for any help

EDIT: could it be, that node.get_... only returns the nodes own findings? When I loop over the connection, normally the second try connects without any problems. Is it possible to access the daemon directly from the node?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-08-09 19:01:34 -0600

ChuiV gravatar image

To me this sounds like an RTPS discovery thing. Discovery doesn't happen instantaneously. You may want to add in something like:

client = node.create_client(Type, 'topic')
print('waiting for service to become available')
if client.wait_for_service(timeout_sec=1.0):
    print('found service')
    result =
    print('service not found')

With ros2 service call, it'll wait until the service exists prior to actually calling it (similar to above, but with an infinite timeout).

edit flag offensive delete link more

Question Tools



Asked: 2022-07-21 07:52:15 -0600

Seen: 92 times

Last updated: Aug 09 '22