@@ -36,6 +36,7 @@ namespace interfaces
3636
3737/* *
3838 * @brief Create a SubscriptionOptions object with Nav2's QoS profiles and options
39+ * @param topic_name Name of topic
3940 * @param allow_parameter_qos_overrides Whether to allow QoS overrides for this subscription
4041 * @param callback_group_ptr Pointer to the callback group to use for this subscription
4142 * @param qos_message_lost_callback Callback for when a QoS message is lost
@@ -47,6 +48,7 @@ namespace interfaces
4748 * @return A nav2::SubscriptionOptions object with the specified configurations
4849 */
4950inline rclcpp::SubscriptionOptions createSubscriptionOptions (
51+ const std::string & topic_name,
5052 const bool allow_parameter_qos_overrides = true ,
5153 const rclcpp::CallbackGroup::SharedPtr callback_group_ptr = nullptr ,
5254 rclcpp::QOSMessageLostCallbackType qos_message_lost_callback = nullptr ,
@@ -67,19 +69,56 @@ inline rclcpp::SubscriptionOptions createSubscriptionOptions(
6769 // Set the callback group to use for this subscription, if given
6870 options.callback_group = callback_group_ptr;
6971
70- // Set the event callbacks
72+ // ROS 2 default logs this already
73+ options.event_callbacks .incompatible_qos_callback = requested_incompatible_qos_callback;
74+ options.event_callbacks .incompatible_type_callback = incompatible_qos_type_callback;
75+
76+ // Set the event callbacks if given, else log
77+ if (qos_message_lost_callback) {
78+ options.event_callbacks .message_lost_callback =
79+ qos_message_lost_callback;
80+ } else {
81+ options.event_callbacks .message_lost_callback =
82+ [topic_name](rclcpp::QOSMessageLostInfo & info) {
83+ RCLCPP_WARN (
84+ rclcpp::get_logger (" nav2::interfaces" ),
85+ " [%lu] Message was dropped on topic [%s] due to queue size or network constraints." ,
86+ info.total_count_change ,
87+ topic_name.c_str ());
88+ };
89+ }
90+
91+ if (subscription_matched_callback) {
92+ options.event_callbacks .matched_callback = subscription_matched_callback;
93+ } else {
94+ options.event_callbacks .matched_callback =
95+ [topic_name](rclcpp::MatchedInfo & status) {
96+ if (status.current_count_change > 0 ) {
97+ RCLCPP_DEBUG (
98+ rclcpp::get_logger (" nav2::interfaces" ),
99+ " Connected: %d new publisher(s) to [%s]. Total active: %zu." ,
100+ status.current_count_change ,
101+ topic_name.c_str (),
102+ status.current_count );
103+ } else if (status.current_count_change < 0 ) {
104+ RCLCPP_DEBUG (
105+ rclcpp::get_logger (" nav2::interfaces" ),
106+ " Disconnected: %d publisher(s) from [%s]. Total active: %zu." ,
107+ -status.current_count_change ,
108+ topic_name.c_str (),
109+ status.current_count );
110+ }
111+ };
112+ }
113+
71114 options.event_callbacks .deadline_callback = qos_deadline_requested_callback;
72115 options.event_callbacks .liveliness_callback = qos_liveliness_changed_callback;
73- options.event_callbacks .incompatible_qos_callback =
74- requested_incompatible_qos_callback;
75- options.event_callbacks .message_lost_callback = qos_message_lost_callback;
76- options.event_callbacks .incompatible_type_callback = incompatible_qos_type_callback;
77- options.event_callbacks .matched_callback = subscription_matched_callback;
78116 return options;
79117}
80118
81119/* *
82120 * @brief Create a PublisherOptions object with Nav2's QoS profiles and options
121+ * @param topic_name Name of topic
83122 * @param allow_parameter_qos_overrides Whether to allow QoS overrides for this publisher
84123 * @param callback_group_ptr Pointer to the callback group to use for this publisher
85124 * @param publisher_matched_callback Callback when a publisher is matched with a subscriber
@@ -90,6 +129,7 @@ inline rclcpp::SubscriptionOptions createSubscriptionOptions(
90129 * @return A rclcpp::PublisherOptions object with the specified configurations
91130 */
92131inline rclcpp::PublisherOptions createPublisherOptions (
132+ const std::string & topic_name,
93133 const bool allow_parameter_qos_overrides = true ,
94134 const rclcpp::CallbackGroup::SharedPtr callback_group_ptr = nullptr ,
95135 rclcpp::PublisherMatchedCallbackType publisher_matched_callback = nullptr ,
@@ -109,12 +149,36 @@ inline rclcpp::PublisherOptions createPublisherOptions(
109149 // Set the callback group to use for this publisher, if given
110150 options.callback_group = callback_group_ptr;
111151
112- // Set the event callbacks
113- options.event_callbacks .deadline_callback = qos_deadline_offered_callback;
114- options.event_callbacks .liveliness_callback = qos_liveliness_lost_callback;
152+ // ROS 2 default logs this already
115153 options.event_callbacks .incompatible_qos_callback = offered_incompatible_qos_cb;
116154 options.event_callbacks .incompatible_type_callback = incompatible_qos_type_callback;
117- options.event_callbacks .matched_callback = publisher_matched_callback;
155+
156+ // Set the event callbacks, else log
157+ if (publisher_matched_callback) {
158+ options.event_callbacks .matched_callback = publisher_matched_callback;
159+ } else {
160+ options.event_callbacks .matched_callback =
161+ [topic_name](rclcpp::MatchedInfo & status) {
162+ if (status.current_count_change > 0 ) {
163+ RCLCPP_DEBUG (
164+ rclcpp::get_logger (" nav2::interfaces" ),
165+ " Connected: %d new subscriber(s) to [%s]. Total active: %zu." ,
166+ status.current_count_change ,
167+ topic_name.c_str (),
168+ status.current_count );
169+ } else if (status.current_count_change < 0 ) {
170+ RCLCPP_DEBUG (
171+ rclcpp::get_logger (" nav2::interfaces" ),
172+ " Disconnected: %d subscriber(s) from [%s]. Total active: %zu." ,
173+ -status.current_count_change ,
174+ topic_name.c_str (),
175+ status.current_count );
176+ }
177+ };
178+ }
179+
180+ options.event_callbacks .deadline_callback = qos_deadline_offered_callback;
181+ options.event_callbacks .liveliness_callback = qos_liveliness_lost_callback;
118182 return options;
119183}
120184
@@ -136,7 +200,7 @@ typename nav2::Subscription<MessageT>::SharedPtr create_subscription(
136200 const rclcpp::CallbackGroup::SharedPtr & callback_group = nullptr)
137201{
138202 bool allow_parameter_qos_overrides = nav2::declare_or_get_parameter (
139- node, " allow_parameter_qos_overrides" , false );
203+ node, " allow_parameter_qos_overrides" , true );
140204
141205 auto params_interface = node->get_node_parameters_interface ();
142206 auto topics_interface = node->get_node_topics_interface ();
@@ -146,7 +210,7 @@ typename nav2::Subscription<MessageT>::SharedPtr create_subscription(
146210 topic_name,
147211 qos,
148212 std::forward<CallbackT>(callback),
149- createSubscriptionOptions (allow_parameter_qos_overrides, callback_group));
213+ createSubscriptionOptions (topic_name, allow_parameter_qos_overrides, callback_group));
150214}
151215
152216/* *
@@ -165,13 +229,13 @@ typename nav2::Publisher<MessageT>::SharedPtr create_publisher(
165229 const rclcpp::CallbackGroup::SharedPtr & callback_group = nullptr)
166230{
167231 bool allow_parameter_qos_overrides = nav2::declare_or_get_parameter (
168- node, " allow_parameter_qos_overrides" , false );
232+ node, " allow_parameter_qos_overrides" , true );
169233 using PublisherT = nav2::Publisher<MessageT>;
170234 auto pub = rclcpp::create_publisher<MessageT, std::allocator<void >, PublisherT>(
171235 *node,
172236 topic_name,
173237 qos,
174- createPublisherOptions (allow_parameter_qos_overrides, callback_group));
238+ createPublisherOptions (topic_name, allow_parameter_qos_overrides, callback_group));
175239 return pub;
176240}
177241
0 commit comments