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

ROS2 service only sometimes present in python

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

Zeckurbo gravatar image

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

Hello,

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():

'/position_handler/describe_parameters', 
'/position_handler/get_parameter_types', 
'/position_handler/get_parameters', 
'/position_handler/list_parameters', 
'/position_handler/set_parameters', 
'/position_handler/set_parameters_atomically', 
'/robot_state_publisher/describe_parameters', 
'/robot_state_publisher/get_parameter_types', 
'/robot_state_publisher/get_parameters', 
'/robot_state_publisher/list_parameters', 
'/robot_state_publisher/set_parameters', 
'/robot_state_publisher/set_parameters_atomically', 
'/rqt_gui_py_node_28169/describe_parameters', 
'/rqt_gui_py_node_28169/get_parameter_types', 
'/rqt_gui_py_node_28169/get_parameters', 
'/rqt_gui_py_node_28169/list_parameters', 
'/rqt_gui_py_node_28169/set_parameters', 
'/rqt_gui_py_node_28169/set_parameters_atomically'

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
1

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

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 = client.call(Type())
else:
    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

2 followers

Stats

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

Seen: 168 times

Last updated: Aug 09 '22