rosbag2_helper.hpp
Go to the documentation of this file.
1 #ifndef ROSBAG2_HELPER_HPP
2 #define ROSBAG2_HELPER_HPP
3 
4 #include <string>
5 #include <vector>
6 #include <rclcpp/rclcpp.hpp>
7 
8 namespace PJ
9 {
10 
11 inline rclcpp::QoS adapt_request_to_offers(
12  const std::string & topic_name, const std::vector<rclcpp::TopicEndpointInfo> & endpoints)
13 {
14  rclcpp::QoS request_qos = rclcpp::SystemDefaultsQoS();
15  request_qos.best_effort().durability_volatile();
16 
17  if (endpoints.empty()) {
18  return request_qos;
19  }
20  size_t num_endpoints = endpoints.size();
21  size_t reliability_reliable_endpoints_count = 0;
22  size_t durability_transient_local_endpoints_count = 0;
23  for (const auto & endpoint : endpoints) {
24  const auto & profile = endpoint.qos_profile().get_rmw_qos_profile();
25  if (profile.reliability == RMW_QOS_POLICY_RELIABILITY_RELIABLE) {
26  reliability_reliable_endpoints_count++;
27  }
28  if (profile.durability == RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL) {
29  durability_transient_local_endpoints_count++;
30  }
31  }
32 
33  // We set policies in order as defined in rmw_qos_profile_t
34  // Policy: history, depth
35  // History does not affect compatibility
36 
37  // Policy: reliability
38  if (reliability_reliable_endpoints_count == num_endpoints) {
39  request_qos.reliable();
40  } else {
41  if (reliability_reliable_endpoints_count > 0) {
42  ROSBAG2_TRANSPORT_LOG_WARN_STREAM( topic_name <<
43  ": some, but not all, publishers on topic "
44  "are offering RMW_QOS_POLICY_RELIABILITY_RELIABLE. "
45  "Falling back to RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT "
46  "as it will connect to all publishers. "
47  "Some messages from Reliable publishers could be dropped.");
48  }
49  request_qos.best_effort();
50  }
51 
52  // Policy: durability
53  // If all publishers offer transient_local, we can request it and receive latched messages
54  if (durability_transient_local_endpoints_count == num_endpoints) {
55  request_qos.transient_local();
56  } else {
57  if (durability_transient_local_endpoints_count > 0) {
58  ROSBAG2_TRANSPORT_LOG_WARN_STREAM(topic_name <<
59  ": some, but not all, publishers on topic "
60  "are offering RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL. "
61  "Falling back to RMW_QOS_POLICY_DURABILITY_VOLATILE "
62  "as it will connect to all publishers. "
63  "Previously-published latched messages will not be retrieved.");
64  }
65  request_qos.durability_volatile();
66  }
67  // Policy: deadline
68  // Deadline does not affect delivery of messages,
69  // and we do not record Deadline"Missed events.
70  // We can always use unspecified deadline, which will be compatible with all publishers.
71 
72  // Policy: lifespan
73  // Lifespan does not affect compatibiliy
74 
75  // Policy: liveliness, liveliness_lease_duration
76  // Liveliness does not affect delivery of messages,
77  // and we do not record LivelinessChanged events.
78  // We can always use unspecified liveliness, which will be compatible with all publishers.
79  return request_qos;
80 }
81 
82 }
83 
84 #endif // ROSBAG2_HELPER_HPP
rclcpp::QoS adapt_request_to_offers(const std::string &topic_name, const std::vector< rclcpp::TopicEndpointInfo > &endpoints)


plotjuggler_ros
Author(s): Davide Faconti
autogenerated on Fri Jun 23 2023 02:28:03