Skip to content

Commit ce4423c

Browse files
authored
Update comments in quality_of_service_demo_cpp message_lost_talker and message_lost_listener (#458)
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent 962bcf9 commit ce4423c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

quality_of_service_demo/rclcpp/src/message_lost_listener.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MessageLostListener : public rclcpp::Node
2828
explicit MessageLostListener(const rclcpp::NodeOptions & options)
2929
: Node("MessageLostListener", options)
3030
{
31+
// Callback that will be used when a message is received.
3132
auto callback =
3233
[this](const sensor_msgs::msg::Image::SharedPtr msg) -> void
3334
{
@@ -38,11 +39,9 @@ class MessageLostListener : public rclcpp::Node
3839
"I heard an image. Message single trip latency: [%f]",
3940
diff.seconds());
4041
};
41-
// Create a subscription to the topic which can be matched with one or more compatible ROS
42-
// publishers.
43-
// Note that not all publishers on the same topic with the same type will be compatible:
44-
// they must have compatible Quality of Service policies.
4542
rclcpp::SubscriptionOptions sub_opts;
43+
// Update the subscription options, so an event handler that will report the number of lost
44+
// messages is created together with the subscription.
4645
sub_opts.event_callbacks.message_lost_callback =
4746
[logger = this->get_logger()](rclcpp::QOSMessageLostInfo & info)
4847
{
@@ -52,6 +51,8 @@ class MessageLostListener : public rclcpp::Node
5251
info.total_count_change << " \n>\tTotal number of messages lost: " <<
5352
info.total_count);
5453
};
54+
// Create the subscription. This will also create an event handler based on the above
55+
// subscription options.
5556
sub_ = create_subscription<sensor_msgs::msg::Image>(
5657
"message_lost_chatter", 1, callback, sub_opts);
5758
}

quality_of_service_demo/rclcpp/src/message_lost_talker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class MessageLostTalker : public rclcpp::Node
8282
message_size_ *= 1024uL;
8383
}
8484
}
85+
// Timer callback
8586
auto publish_message =
8687
[this]() -> void
8788
{
@@ -97,6 +98,7 @@ class MessageLostTalker : public rclcpp::Node
9798

9899
pub_->publish(msg_);
99100
};
101+
// Create a publisher
100102
pub_ = this->create_publisher<sensor_msgs::msg::Image>("message_lost_chatter", 1);
101103

102104
// Use a timer to schedule periodic message publishing.

0 commit comments

Comments
 (0)