Skip to content

Commit

Permalink
Adding QoS to subscription options (#2323)
Browse files Browse the repository at this point in the history
* Adding QoS to subscription options

Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
  • Loading branch information
CursedRock17 authored Dec 1, 2023
1 parent 26f6efa commit a19ad21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rclcpp/include/rclcpp/create_subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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>(
Expand Down
4 changes: 4 additions & 0 deletions rclcpp/include/rclcpp/subscription_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions rclcpp/test/rclcpp/test_subscription_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ 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) {
Expand Down

0 comments on commit a19ad21

Please sign in to comment.