diff --git a/rclcpp/include/rclcpp/create_subscription.hpp b/rclcpp/include/rclcpp/create_subscription.hpp index 5b84930ff7..14613b8b6f 100644 --- a/rclcpp/include/rclcpp/create_subscription.hpp +++ b/rclcpp/include/rclcpp/create_subscription.hpp @@ -89,7 +89,7 @@ create_subscription( node_parameters, node_topics_interface, options.topic_stats_options.publish_topic, - qos); + options.topic_stats_options.qos); subscription_topic_stats = std::make_shared< rclcpp::topic_statistics::SubscriptionTopicStatistics diff --git a/rclcpp/include/rclcpp/subscription_options.hpp b/rclcpp/include/rclcpp/subscription_options.hpp index 43b9ec034c..71f90fe15d 100644 --- a/rclcpp/include/rclcpp/subscription_options.hpp +++ b/rclcpp/include/rclcpp/subscription_options.hpp @@ -77,6 +77,10 @@ struct SubscriptionOptionsBase // Topic statistics publication period in ms. Defaults to one second. // Only values greater than zero are allowed. std::chrono::milliseconds publish_period{std::chrono::seconds(1)}; + + // An optional QoS which can provide topic_statistics with a stable QoS separate from + // the subscription's current QoS settings which could be unstable. + rclcpp::QoS qos = SystemDefaultsQoS(); }; TopicStatisticsOptions topic_stats_options; diff --git a/rclcpp/test/rclcpp/test_subscription_options.cpp b/rclcpp/test/rclcpp/test_subscription_options.cpp index c4cfb6b4c4..24719a826a 100644 --- a/rclcpp/test/rclcpp/test_subscription_options.cpp +++ b/rclcpp/test/rclcpp/test_subscription_options.cpp @@ -60,14 +60,19 @@ TEST_F(TestSubscriptionOptions, topic_statistics_options_default_and_set) { EXPECT_EQ(options.topic_stats_options.state, rclcpp::TopicStatisticsState::NodeDefault); EXPECT_EQ(options.topic_stats_options.publish_topic, defaultPublishTopic); EXPECT_EQ(options.topic_stats_options.publish_period, 1s); + EXPECT_EQ( + options.topic_stats_options.qos, rclcpp::SystemDefaultsQoS()); options.topic_stats_options.state = rclcpp::TopicStatisticsState::Enable; options.topic_stats_options.publish_topic = "topic_statistics"; options.topic_stats_options.publish_period = 5min; + options.topic_stats_options.qos = rclcpp::BestAvailableQoS(); EXPECT_EQ(options.topic_stats_options.state, rclcpp::TopicStatisticsState::Enable); EXPECT_EQ(options.topic_stats_options.publish_topic, "topic_statistics"); EXPECT_EQ(options.topic_stats_options.publish_period, 5min); + EXPECT_EQ( + options.topic_stats_options.qos, rclcpp::BestAvailableQoS()); } TEST_F(TestSubscriptionOptions, topic_statistics_options_node_default_mode) {