Skip to content

Commit

Permalink
Expose 'best available' QoS policies (#928)
Browse files Browse the repository at this point in the history
* Expose 'best available' QoS policies

If users set certain a QoS policy to 'best available', then the middleware will query the graph
for endpoint info before creating a subscription or publisher.
A QoS policy will be selected such that is matches the majority of endpoints while maintaining
the highest level of service possible.

Connects to ros2/rmw#320

* Add BEST_AVAILABLE to QoSPresetProfiles enum

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed May 3, 2022
1 parent 2db2d35 commit 3b598ba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions rclpy/rclpy/qos.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class ReliabilityPolicy(QoSPolicyEnum):
RELIABLE = 1
BEST_EFFORT = 2
UNKNOWN = 3
BEST_AVAILABLE = 4


# Alias with the old name, for retrocompatibility
Expand All @@ -386,6 +387,7 @@ class DurabilityPolicy(QoSPolicyEnum):
TRANSIENT_LOCAL = 1
VOLATILE = 2
UNKNOWN = 3
BEST_AVAILABLE = 4


# Alias with the old name, for retrocompatibility
Expand All @@ -409,11 +411,24 @@ class LivelinessPolicy(QoSPolicyEnum):
AUTOMATIC = 1
MANUAL_BY_TOPIC = 3
UNKNOWN = 4
BEST_AVAILABLE = 5


# Alias with the old name, for retrocompatibility
QoSLivelinessPolicy = LivelinessPolicy

# Deadline policy to match the majority of endpoints while being as strict as possible
# See `RMW_QOS_DEADLINE_BEST_AVAILABLE` in rmw/types.h for more info.
DeadlineBestAvailable = Duration(nanoseconds=_rclpy.RMW_QOS_DEADLINE_BEST_AVAILABLE)

# Liveliness lease duraiton policy to match the majority of endpoints while being as strict as
# possible
# See `RMW_QOS_LIVELINESS_LEASE_DURATION_BEST_AVAILABLE` in rmw/types.h for more info.
LivelinessLeaseDurationeBestAvailable = Duration(
nanoseconds=_rclpy.RMW_QOS_LIVELINESS_LEASE_DURATION_BEST_AVAILABLE
)


# The details of the following profiles can be found at
# 1. ROS QoS principles:
# https://design.ros2.org/articles/qos.html
Expand All @@ -440,6 +455,14 @@ class LivelinessPolicy(QoSPolicyEnum):
#: parameters.
qos_profile_parameter_events = QoSProfile(**_rclpy.rmw_qos_profile_t.predefined(
'qos_profile_parameter_events').to_dict())
#: Match majority of endpoints currently available while maintaining the highest level of service.
#: Policies are chosen at the time of creating a subscription or publisher.
#: The middleware is not expected to update policies after creating a subscription or
#: publisher, even if one or more policies are incompatible with newly discovered endpoints.
#: Therefore, this profile should be used with care since non-deterministic behavior
#: can occur due to races with discovery.
qos_profile_best_available = QoSProfile(**_rclpy.rmw_qos_profile_t.predefined(
'qos_profile_best_available').to_dict())

# Separate rcl_action profile defined at
# ros2/rcl : rcl/rcl_action/include/rcl_action/default_qos.h
Expand All @@ -457,6 +480,7 @@ class QoSPresetProfiles(Enum):
PARAMETERS = qos_profile_parameters
PARAMETER_EVENTS = qos_profile_parameter_events
ACTION_STATUS_DEFAULT = qos_profile_action_status_default
BEST_AVAILABLE = qos_profile_best_available

"""Noted that the following are duplicated from QoSPolicyEnum.
Expand Down
4 changes: 4 additions & 0 deletions rclpy/src/rclpy/_rclpy_pybind11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ PYBIND11_MODULE(_rclpy_pybind11, m) {

m.attr("RCL_DEFAULT_DOMAIN_ID") = py::int_(RCL_DEFAULT_DOMAIN_ID);
m.attr("RMW_DURATION_INFINITE") = py::int_(rmw_time_total_nsec(RMW_DURATION_INFINITE));
m.attr("RMW_QOS_DEADLINE_BEST_AVAILABLE") = py::int_(
rmw_time_total_nsec(RMW_QOS_DEADLINE_BEST_AVAILABLE));
m.attr("RMW_QOS_LIVELINESS_LEASE_DURATION_BEST_AVAILABLE") = py::int_(
rmw_time_total_nsec(RMW_QOS_LIVELINESS_LEASE_DURATION_BEST_AVAILABLE));

py::enum_<rcl_clock_change_t>(m, "ClockChange")
.value(
Expand Down
3 changes: 3 additions & 0 deletions rclpy/src/rclpy/qos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ predefined_qos_profile_from_name(const char * qos_profile_name)
if (0 == strcmp(qos_profile_name, "qos_profile_parameter_events")) {
return rmw_qos_profile_parameter_events;
}
if (0 == strcmp(qos_profile_name, "qos_profile_best_available")) {
return rmw_qos_profile_best_available;
}

std::string error_text = "Requested unknown rmw_qos_profile: ";
error_text += qos_profile_name;
Expand Down

0 comments on commit 3b598ba

Please sign in to comment.