# Interfaces Source: https://docs.ros.org/en/iron/Concepts/Basic/About-Interfaces.html Version: iron * [Concepts](../../Concepts.html) * [Basic Concepts](../Basic.html) * Interfaces * [Edit on GitHub](https://github.com/ros2/ros2_documentation/blob/iron/source/Concepts/Basic/About-Interfaces.rst) --- **Warning You're reading the documentation for a version of ROS 2 that has reached its EOL (end-of-life), and is no longer officially supported. If you want up-to-date information, please have a look at [Kilted](../../../kilted/Concepts/Basic/About-Interfaces.html).** Table of Contents * [Background](#background) * [Messages](#messages) + [Fields](#fields) - [Field types](#field-types) - [Field names](#field-names) - [Field default value](#field-default-value) + [Constants](#constants) * [Services](#services) * [Actions](#actions) ## [Background](#id1)[](#background "Link to this heading") ROS applications typically communicate through interfaces of one of three types: [topics](About-Topics.html), [services](About-Services.html), or [actions](About-Actions.html). ROS 2 uses a simplified description language, the interface definition language (IDL), to describe these interfaces. This description makes it easy for ROS tools to automatically generate source code for the interface type in several target languages. In this document we will describe the supported types: * msg: `.msg` files are simple text files that describe the fields of a ROS message. They are used to generate source code for messages in different languages. * srv: `.srv` files describe a service. They are composed of two parts: a request and a response. The request and response are message declarations. * action: `.action` files describe actions. They are composed of three parts: a goal, a result, and feedback. Each part is a message declaration itself. ## [Messages](#id2)[](#messages "Link to this heading") Messages are a way for a ROS 2 node to send data on the network to other ROS nodes, with no response expected. For instance, if a ROS 2 node reads temperature data from a sensor, it can then publish that data on the ROS 2 network using a `Temperature` message. Other nodes on the ROS 2 network can subscribe to that data and receive the `Temperature` message. Messages are described and defined in `.msg` files in the `msg/` directory of a ROS package. `.msg` files are composed of two parts: fields and constants. ### [Fields](#id3)[](#fields "Link to this heading") Each field consists of a type and a name, separated by a space, i.e: ```None fieldtype1 fieldname1 fieldtype2 fieldname2 fieldtype3 fieldname3 ``` For example: ```None int32 my_int string my_string ``` #### [Field types](#id4)[](#field-types "Link to this heading") Field types can be: * a built-in-type * names of Message descriptions defined on their own, such as “geometry\_msgs/PoseStamped” *Built-in-types currently supported:* | Type name | [C++](https://design.ros2.org/articles/generated_interfaces_cpp.html) | [Python](https://design.ros2.org/articles/generated_interfaces_python.html) | [DDS type](https://design.ros2.org/articles/mapping_dds_types.html) | | --- | --- | --- | --- | | bool | bool | builtins.bool | boolean | | byte | uint8\_t | builtins.bytes\* | octet | | char | char | builtins.int\* | char | | float32 | float | builtins.float\* | float | | float64 | double | builtins.float\* | double | | int8 | int8\_t | builtins.int\* | octet | | uint8 | uint8\_t | builtins.int\* | octet | | int16 | int16\_t | builtins.int\* | short | | uint16 | uint16\_t | builtins.int\* | unsigned short | | int32 | int32\_t | builtins.int\* | long | | uint32 | uint32\_t | builtins.int\* | unsigned long | | int64 | int64\_t | builtins.int\* | long long | | uint64 | uint64\_t | builtins.int\* | unsigned long long | | string | std::string | builtins.str | string | | wstring | std::u16string | builtins.str | wstring | *Every built-in-type can be used to define arrays:* | Type name | [C++](https://design.ros2.org/articles/generated_interfaces_cpp.html) | [Python](https://design.ros2.org/articles/generated_interfaces_python.html) | [DDS type](https://design.ros2.org/articles/mapping_dds_types.html) | | --- | --- | --- | --- | | static array | std::array | builtins.list\* | T[N] | | unbounded dynamic array | std::vector | builtins.list | sequence | | bounded dynamic array | custom\_class | builtins.list\* | sequence | | bounded string | std::string | builtins.str\* | string | All types that are more permissive than their ROS definition enforce the ROS constraints in range and length by software. *Example of message definition using arrays and bounded types:* ```None int32[] unbounded_integer_array int32[5] five_integers_array int32[<=5] up_to_five_integers_array string string_of_unbounded_size string<=10 up_to_ten_characters_string string[<=5] up_to_five_unbounded_strings string<=10[] unbounded_array_of_strings_up_to_ten_characters_each string<=10[<=5] up_to_five_strings_up_to_ten_characters_each ``` #### [Field names](#id5)[](#field-names "Link to this heading") Field names must be lowercase alphanumeric characters with underscores for separating words. They must start with an alphabetic character, and they must not end with an underscore or have two consecutive underscores. #### [Field default value](#id6)[](#field-default-value "Link to this heading") Default values can be set to any field in the message type. Currently default values are not supported for string arrays and complex types (i.e. types not present in the built-in-types table above; that applies to all nested messages). Defining a default value is done by adding a third element to the field definition line, i.e: ```None fieldtype fieldname fielddefaultvalue ``` For example: ```None uint8 x 42 int16 y -2000 string full_name "John Doe" int32[] samples [-200, -100, 0, 100, 200] ``` Note * string values must be defined in single `'` or double `"` quotes * currently string values are not escaped ### [Constants](#id7)[](#constants "Link to this heading") Each constant definition is like a field description with a default value, except that this value can never be changed programatically. This value assignment is indicated by use of an equal ‘=’ sign, e.g. ```None constanttype CONSTANTNAME=constantvalue ``` For example: ```None int32 X=123 int32 Y=-123 string FOO="foo" string EXAMPLE='bar' ``` Note Constants names have to be UPPERCASE ## [Services](#id8)[](#services "Link to this heading") Services are a request/response communication, where the client (requester) is waiting for the server (responder) to make a short computation and return a result. Services are described and defined in `.srv` files in the `srv/` directory of a ROS package. A service description file consists of a request and a response msg type, separated by `---`. Any two `.msg` files concatenated with a `---` are a legal service description. Here is a very simple example of a service that takes in a string and returns a string: ```None string str --- string str ``` We can of course get much more complicated (if you want to refer to a message from the same package you must not mention the package name): ```None # request constants int8 FOO=1 int8 BAR=2 # request fields int8 foobar another_pkg/AnotherMessage msg --- # response constants uint32 SECRET=123456 # response fields another_pkg/YetAnotherMessage val CustomMessageDefinedInThisPackage value uint32 an_integer ``` You cannot embed another service inside of a service. ## [Actions](#id9)[](#actions "Link to this heading") Actions are a long-running request/response communication, where the action client (requester) is waiting for the action server (the responder) to take some action and return a result. In contrast to services, actions can be long-running (many seconds or minutes), provide feedback while they are happening, and can be interrupted. Action definitions have the following form: ```None --- --- ``` Like services, the request fields are before and the response fields are after the first triple-dash (`---`), respectively. There is also a third set of fields after the second triple-dash, which is the fields to be sent when sending feedback. There can be arbitrary numbers of request fields (including zero), arbitrary numbers of response fields (including zero), and arbitrary numbers of feedback fields (including zero). The ``, ``, and `` follow all of the same rules as the `` for a message. The ``, ``, and `` follow all of the same rules as the `` for a message. For instance, the `Fibonacci` action definition contains the following: ```None int32 order --- int32[] sequence --- int32[] sequence ``` This is an action definition where the action client is sending a single `int32` field representing the number of Fibonacci steps to take, and expecting the action server to produce an array of `int32` containing the complete steps. Along the way, the action server may also provide an intermediate array of `int32` containing the steps accomplished up until a certain point. [Previous](About-Discovery.html "Discovery") [Next](About-Topics.html "Topics") --- © Copyright 2026, Open Robotics. Built with [Sphinx](https://www.sphinx-doc.org/) using a [theme](https://github.com/readthedocs/sphinx_rtd_theme) provided by [Read the Docs](https://readthedocs.org).