ros2 / ros2cli

ROS 2 command line interface tools
Apache License 2.0
173 stars 159 forks source link

Add ros2 node get_type_description initial implementation #846

Open emersonknapp opened 1 year ago

emersonknapp commented 1 year ago

Replaces https://github.com/ros2/ros2cli/pull/817

Implements a first pass at ros2 node get_type_description. It does its best to autofill the type hash so the user doesn't have to, but given the limitations of the current API this is only possible for msg on pub/sub topics, not for srv/action. For those, the hash must be provided manually by the user, though it is not discoverable via any existing API.

Sample output:

$ ros2 node get-type-description /talker rcl_interfaces/msg/Log
Waiting for service to become available...
Requesting type hash RIHS01_e28ce254ca8abc06abf92773b74602cdbf116ed34fbaf294fb9f81da9f318eac
Sending request...
Response successful:

rcl_interfaces/msg/Log
Fields:
  stamp: FIELD_TYPE_NESTED_TYPE (builtin_interfaces/msg/Time)
  level: FIELD_TYPE_UINT8
  name: FIELD_TYPE_STRING
  msg: FIELD_TYPE_STRING
  file: FIELD_TYPE_STRING
  function: FIELD_TYPE_STRING
  line: FIELD_TYPE_UINT32

Referenced Type Descriptions:

  builtin_interfaces/msg/Time
  Fields:
    sec: FIELD_TYPE_INT32
    nanosec: FIELD_TYPE_UINT32
$ ros2 node get-type-description /talker type_description_interfaces/srv/GetTypeDescription RIHS01_69b9c19c1021405984cc60dbbb1edceb147a6538b411d812ba6afabeed962cd5
Sending request...                                                                                                                                                                               
Response successful:

type_description_interfaces/srv/GetTypeDescription
Fields:
  request_message: FIELD_TYPE_NESTED_TYPE (type_description_interfaces/srv/GetTypeDescription_Request)
  response_message: FIELD_TYPE_NESTED_TYPE (type_description_interfaces/srv/GetTypeDescription_Response)
  event_message: FIELD_TYPE_NESTED_TYPE (type_description_interfaces/srv/GetTypeDescription_Event)

Referenced Type Descriptions:

  builtin_interfaces/msg/Time
  Fields:
    sec: FIELD_TYPE_INT32
    nanosec: FIELD_TYPE_UINT32

  service_msgs/msg/ServiceEventInfo
  Fields:
    event_type: FIELD_TYPE_UINT8
    stamp: FIELD_TYPE_NESTED_TYPE (builtin_interfaces/msg/Time)
    client_gid: FIELD_TYPE_UINT8_ARRAY - capacity 16
    sequence_number: FIELD_TYPE_INT64

  type_description_interfaces/msg/Field
  Fields:
    name: FIELD_TYPE_STRING
    type: FIELD_TYPE_NESTED_TYPE (type_description_interfaces/msg/FieldType)
    default_value: FIELD_TYPE_STRING

  type_description_interfaces/msg/FieldType
  Fields:
    type_id: FIELD_TYPE_UINT8 = 0
    capacity: FIELD_TYPE_UINT64
    string_capacity: FIELD_TYPE_UINT64
    nested_type_name: FIELD_TYPE_BOUNDED_STRING - string_capacity 255

  type_description_interfaces/msg/IndividualTypeDescription
  Fields:
    type_name: FIELD_TYPE_BOUNDED_STRING - string_capacity 255
    fields: FIELD_TYPE_NESTED_TYPE_UNBOUNDED_SEQUENCE (type_description_interfaces/msg/Field)

  type_description_interfaces/msg/KeyValue
  Fields:
    key: FIELD_TYPE_STRING
    value: FIELD_TYPE_STRING

  type_description_interfaces/msg/TypeDescription
  Fields:
    type_description: FIELD_TYPE_NESTED_TYPE (type_description_interfaces/msg/IndividualTypeDescription)
    referenced_type_descriptions: FIELD_TYPE_NESTED_TYPE_UNBOUNDED_SEQUENCE (type_description_interfaces/msg/IndividualTypeDescription)

  type_description_interfaces/msg/TypeSource
  Fields:
    type_name: FIELD_TYPE_STRING
    encoding: FIELD_TYPE_STRING
    raw_file_contents: FIELD_TYPE_STRING

  type_description_interfaces/srv/GetTypeDescription_Event
  Fields:
    info: FIELD_TYPE_NESTED_TYPE (service_msgs/msg/ServiceEventInfo)
    request: FIELD_TYPE_NESTED_TYPE_BOUNDED_SEQUENCE (type_description_interfaces/srv/GetTypeDescription_Request) - capacity 1
    response: FIELD_TYPE_NESTED_TYPE_BOUNDED_SEQUENCE (type_description_interfaces/srv/GetTypeDescription_Response) - capacity 1

  type_description_interfaces/srv/GetTypeDescription_Request
  Fields:
    type_name: FIELD_TYPE_STRING
    type_hash: FIELD_TYPE_STRING
    include_type_sources: FIELD_TYPE_BOOLEAN = True

  type_description_interfaces/srv/GetTypeDescription_Response
  Fields:
    successful: FIELD_TYPE_BOOLEAN
    failure_reason: FIELD_TYPE_STRING
    type_description: FIELD_TYPE_NESTED_TYPE (type_description_interfaces/msg/TypeDescription)
    type_sources: FIELD_TYPE_NESTED_TYPE_UNBOUNDED_SEQUENCE (type_description_interfaces/msg/TypeSource)
    extra_information: FIELD_TYPE_NESTED_TYPE_UNBOUNDED_SEQUENCE (type_description_interfaces/msg/KeyValue)

I think we should move forward with putting this in, as it covers the majority use case. Further discussion follows:

  1. It's awkward that we need to get names_and_types, then use that to go to get_x_info_by_topic in order to get TopicEndpointInfo to find the hash. https://github.com/ros2/rmw/issues/356 would make this part easier and support srv/action
  2. The fact that we need to do this graph-munging to "discover" the hash for a typename seems unnecessary. Given that a specific node has a 1:1 relationship of type name and type hash, it seems like GetTypeDescription should allow for either (but not both) to be empty in the request, so that the requesting client doesn't necessarily even need to know both pieces of information. From a user point of view, it seems very natural to say "you node, give me your description for mypackage/msg/Foo". It also seems like it could come up, though less commonly, to request "you node, what is the type that has hash RIHS01_e28ce254ca8abc06abf92773b74602cdbf116ed34fbaf294fb9f81da9f318eac". The current underlying implementation in rcl assumes the hash is the more important piece of information, using it as the key to its cache, but this usage reveals that it's probably more likely we wish to fetch this information by typename, using the hash as a potential validation. HOWEVER - all that aside, with https://github.com/ros2/rmw/issues/356 the "discovery" would be much simpler and so alleviate some of my concern with this point.
emersonknapp commented 1 year ago

@clalancette could I get a reviewer assignment for this? (or @audrow @gbiggs friendly ping)