Skip to content

Still can't request message details of common messages #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scottbell opened this issue Jan 6, 2023 · 3 comments · Fixed by #883
Closed

Still can't request message details of common messages #834

scottbell opened this issue Jan 6, 2023 · 3 comments · Fixed by #883
Labels

Comments

@scottbell
Copy link
Contributor

Description
Per #688, when trying to use the RosAPI to request message details I get an exception in the rosapi node. This happens with a common messages included with ROS2.

  • Library Version: 1.3.1-1jammy.20221207.042258
  • ROS Version: humble
  • Platform / OS: Ubuntu 22.04.1

Steps To Reproduce

ros2 service call /rosapi/message_details rosapi_msgs/srv/MessageDetails "{type: std_msgs/Float32}"

Expected Behavior
Return message details for the requested message type.

Actual Behavior

$ ros2 launch rosbridge_server rosbridge_websocket_launch.xml 
[INFO] [launch]: All log files can be found below /home/scott/.ros/log/2023-01-06-12-05-52-599792-rosmachine-4566
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [rosbridge_websocket-1]: process started with pid [4567]
[INFO] [rosapi_node-2]: process started with pid [4569]
[rosbridge_websocket-1] [INFO] [1673003153.749749059] [rosbridge_websocket]: Rosbridge WebSocket server started on port 9090
[rosapi_node-2] Traceback (most recent call last):
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 329, in <module>
[rosapi_node-2]     main()
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 321, in main
[rosapi_node-2]     rclpy.spin(node)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 222, in spin
[rosapi_node-2]     executor.spin_once()
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 713, in spin_once
[rosapi_node-2]     raise handler.exception()
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in __call__
[rosapi_node-2]     self._handler.send(None)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 418, in handler
[rosapi_node-2]     await call_coroutine(entity, arg)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 372, in _execute_service
[rosapi_node-2]     response = await await_or_execute(srv.callback, request, srv.srv_type.Response())
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
[rosapi_node-2]     return callback(*args)
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 228, in get_message_details
[rosapi_node-2]     dict_to_typedef(d) for d in objectutils.get_typedef_recursive(request.type)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 98, in get_typedef_recursive
[rosapi_node-2]     return _get_typedefs_recursive(type, [])
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 223, in _get_typedefs_recursive
[rosapi_node-2]     typedef = get_typedef(type)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 78, in get_typedef
[rosapi_node-2]     return _get_typedef(instance)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 164, in _get_typedef
[rosapi_node-2]     fieldtypes.append(_type_name(field_type, field_instance))
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 253, in _type_name
[rosapi_node-2]     return _type_name_from_instance(instance)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 257, in _type_name_from_instance
[rosapi_node-2]     mod = instance.__module__
[rosapi_node-2] AttributeError: 'float' object has no attribute '__module__'. Did you mean: '__mod__'?
[ERROR] [rosapi_node-2]: process has died [pid 4569, exit code 1, cmd '/opt/ros/humble/lib/rosapi/rosapi_node --ros-args -r __node:=rosapi --params-file /tmp/launch_params_2df8zmzu --params-file /tmp/launch_params_m6j5dj79 --params-file /tmp/launch_params_tg0uwis_'].

Using @GiteZz's fix, I was able to get a bit further, but now crashing asking about rcl_interfaces/msg/ParameterEvent}. E.g.,:
ros2 service call /rosapi/message_details rosapi_msgs/srv/MessageDetails "{type: rcl_interfaces/msg/ParameterEvent}"
causes:

$ ros2 launch rosbridge_server rosbridge_websocket_launch.xml 
[INFO] [launch]: All log files can be found below /home/scott/.ros/log/2023-01-06-12-11-30-370701-rosmachine-4691
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [rosbridge_websocket-1]: process started with pid [4692]
[INFO] [rosapi_node-2]: process started with pid [4694]
[rosbridge_websocket-1] [INFO] [1673003491.543589196] [rosbridge_websocket]: Rosbridge WebSocket server started on port 9090
[rosapi_node-2] Traceback (most recent call last):
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 329, in <module>
[rosapi_node-2]     main()
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 321, in main
[rosapi_node-2]     rclpy.spin(node)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 222, in spin
[rosapi_node-2]     executor.spin_once()
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 713, in spin_once
[rosapi_node-2]     raise handler.exception()
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in __call__
[rosapi_node-2]     self._handler.send(None)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 418, in handler
[rosapi_node-2]     await call_coroutine(entity, arg)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 372, in _execute_service
[rosapi_node-2]     response = await await_or_execute(srv.callback, request, srv.srv_type.Response())
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
[rosapi_node-2]     return callback(*args)
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 228, in get_message_details
[rosapi_node-2]     dict_to_typedef(d) for d in objectutils.get_typedef_recursive(request.type)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 97, in get_typedef_recursive
[rosapi_node-2]     return _get_typedefs_recursive(type, [])
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 227, in _get_typedefs_recursive
[rosapi_node-2]     return _get_subtypedefs_recursive(typedef, typesseen)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 237, in _get_subtypedefs_recursive
[rosapi_node-2]     typedefs = typedefs + _get_typedefs_recursive(fieldtype, typesseen)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 227, in _get_typedefs_recursive
[rosapi_node-2]     return _get_subtypedefs_recursive(typedef, typesseen)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 237, in _get_subtypedefs_recursive
[rosapi_node-2]     typedefs = typedefs + _get_typedefs_recursive(fieldtype, typesseen)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 227, in _get_typedefs_recursive
[rosapi_node-2]     return _get_subtypedefs_recursive(typedef, typesseen)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 237, in _get_subtypedefs_recursive
[rosapi_node-2]     typedefs = typedefs + _get_typedefs_recursive(fieldtype, typesseen)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 225, in _get_typedefs_recursive
[rosapi_node-2]     typedef = get_typedef(type)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 76, in get_typedef
[rosapi_node-2]     instance = ros_loader.get_message_instance(type)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosbridge_library/internal/ros_loader.py", line 91, in get_message_instance
[rosapi_node-2]     cls = get_message_class(typestring)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosbridge_library/internal/ros_loader.py", line 78, in get_message_class
[rosapi_node-2]     return _get_msg_class(typestring)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosbridge_library/internal/ros_loader.py", line 122, in _get_msg_class
[rosapi_node-2]     return _get_class(typestring, subname, _loaded_msgs, _msgs_lock)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosbridge_library/internal/ros_loader.py", line 163, in _get_class
[rosapi_node-2]     modname, classname = _splittype(typestring)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosbridge_library/internal/ros_loader.py", line 213, in _splittype
[rosapi_node-2]     raise InvalidTypeStringException(typestring)
[rosapi_node-2] rosbridge_library.internal.ros_loader.InvalidTypeStringException: octet is not a valid type string
[ERROR] [rosapi_node-2]: process has died [pid 4694, exit code 1, cmd '/opt/ros/humble/lib/rosapi/rosapi_node --ros-args -r __node:=rosapi --params-file /tmp/launch_params_eoskae9r --params-file /tmp/launch_params_oehzpv9e --params-file /tmp/launch_params_nq64wis7'].
@scottbell scottbell added the bug label Jan 6, 2023
@brag00n
Copy link

brag00n commented May 12, 2023

Hello, I have got the same issue using roslibpy API call. E.g.:
roslibpy.Ros.get_message_details('geometry_msgs/msg/PoseWithCovarianceStamped')
cause:

[rosapi_node-2] Traceback (most recent call last):
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 329, in <module>
[rosapi_node-2]     main()
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 321, in main
[rosapi_node-2]     rclpy.spin(node)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 222, in spin
[rosapi_node-2]     executor.spin_once()
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 713, in spin_once
[rosapi_node-2]     raise handler.exception()
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in __call__
[rosapi_node-2]     self._handler.send(None)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 418, in handler
[rosapi_node-2]     await call_coroutine(entity, arg)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 372, in _execute_service
[rosapi_node-2]     response = await await_or_execute(srv.callback, request, srv.srv_type.Response())
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
[rosapi_node-2]     return callback(*args)
[rosapi_node-2]   File "/opt/ros/humble/lib/rosapi/rosapi_node", line 228, in get_message_details
[rosapi_node-2]     dict_to_typedef(d) for d in objectutils.get_typedef_recursive(request.type)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 98, in get_typedef_recursive
[rosapi_node-2]     return _get_typedefs_recursive(type, [])
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 225, in _get_typedefs_recursive
[rosapi_node-2]     return _get_subtypedefs_recursive(typedef, typesseen)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 235, in _get_subtypedefs_recursive
[rosapi_node-2]     typedefs = typedefs + _get_typedefs_recursive(fieldtype, typesseen)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 223, in _get_typedefs_recursive
[rosapi_node-2]     typedef = get_typedef(type)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 78, in get_typedef
[rosapi_node-2]     return _get_typedef(instance)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 164, in _get_typedef
[rosapi_node-2]     fieldtypes.append(_type_name(field_type, field_instance))
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 253, in _type_name
[rosapi_node-2]     return _type_name_from_instance(instance)
[rosapi_node-2]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py", line 257, in _type_name_from_instance
[rosapi_node-2]     mod = instance.__module__
[rosapi_node-2] AttributeError: 'numpy.ndarray' object has no attribute '__module__'. Did you mean: '__mod__'?

@scottbell
Copy link
Contributor Author

scottbell commented Oct 6, 2023

@brag00n that specific error can be fixed by changing /opt/ros/humble/local/lib/python3.10/dist-packages/rosapi/objectutils.py, specifically:
the atomics array needs the float type so it doesn't try to call __module__ on it in the _type_name function. See @GiteZz's response for the full list of atomic types that should be added.

@scottbell
Copy link
Contributor Author

Note I've got a fork here:
ros2...scottbell:rosbridge_suite:ros2

that addresses the crashing. Namely, if we can't lookup a type, output an error and return None back to the client. The main issue (after adding the extra native type per @GiteZz) seems to be coming here where the code assumes the type string will be of a certain form. If the type is a sequence, the string parsing logic here fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants