Quality of Service (QoS) policies in ROS 2 are settings that allow developers to specify the reliability, durability, and other communication parameters for data transmission between nodes. These policies are crucial for ensuring that the data exchange between ROS 2 entities is suited to the needs of a particular application, especially in complex or real-time environments where the handling of data streams must be predictable and efficient.
ROS 2, built on top of the DDS (Data Distribution Service) standard, inherits its sophisticated QoS settings, enabling fine-grained control over various aspects of message communication. Let's examine some of the key QoS policies available in ROS 2:
-
History and Depth: Determines how messages are stored until they are taken by a subscriber:
- Keep Last: Only a specified number of messages (depth) are stored. Old messages are discarded if the queue is full.
- Keep All: All messages are stored until they are taken by a subscriber, potentially leading to unbounded memory use if the subscriber is slow or inactive.
-
Reliability: Specifies the guarantee of message delivery:
- Reliable: The middleware ensures delivery of all messages, potentially retrying sending messages until they are successfully received.
- Best Effort: The middleware attempts to deliver messages, but there is no guarantee of delivery. Messages may be lost if the network is congested or subscribers are too slow.
-
Durability: Determines the persistence of messages with respect to late-joining subscribers:
- Volatile: Messages are not saved for future subscribers; only "live" messages are received.
- Transient Local: Messages are stored on the publisher side and delivered to any future subscribers as they connect.
-
Deadline: Allows specifying a maximum duration within which a message should be delivered:
- If the duration is exceeded, an event is generated to notify the application of the missed deadline.
-
Liveliness: Defines how the system determines whether an entity (publisher or subscriber) is "alive":
- Settings can determine the mechanism (automatic, manual by participant, or manual by topic), and the lease duration after which an entity is considered not alive if no signals have been received.
-
Lifespan: Determines the maximum duration messages should be retained:
- Messages are considered expired if not taken by a subscriber within this timeframe and may be discarded.
These QoS settings can be thought of as contracts between publishers and subscribers. For effective communication, the QoS settings of publishers and subscribers need to be compatible, although exact matches are not always required (depending on the specific policies).
In summary, QoS policies in ROS 2 offer a powerful mechanism to tailor the communication between nodes according to the requirements of different use cases, from real-time control systems where message timing is critical, to data analysis tasks where completeness and reliability of data might be the top priority. Proper understanding and application of QoS policies can significantly enhance the robustness, efficiency, and effectiveness of ROS 2 applications.