Skip to content

Commit 2ad56ec

Browse files
Fix topic statistics tutorial for Kilted (#5495)
Signed-off-by: avanmalleghem <[email protected]>
1 parent 03b0a23 commit 2ad56ec

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

source/Tutorials/Advanced/Topic-Statistics-Tutorial/Topic-Statistics-Tutorial.rst

+9-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Enabling topic statistics (C++)
1818
Background
1919
----------
2020

21-
This is a short tutorial on how to enable topic statistics in ROS 2 and view the published statistics output using command line tools (:doc:`ros2topic <../../Beginner-CLI-Tools/Understanding-ROS2-Topics/Understanding-ROS2-Topics>`).
21+
This is a short tutorial on how to enable topic statistics in ROS 2 and view the published statistics output using command line tools (:doc:`ros2 topic <../../Beginner-CLI-Tools/Understanding-ROS2-Topics/Understanding-ROS2-Topics>`).
2222

2323
ROS 2 provides the integrated measurement of statistics for messages received by any subscription,
2424
called Topic Statistics.
@@ -95,7 +95,7 @@ Open the file using your preferred text editor.
9595
// configure the topic name (default '/statistics')
9696
// options.topic_stats_options.publish_topic = "/topic_statistics"
9797

98-
auto callback = [this](std_msgs::msg::String::SharedPtr msg) {
98+
auto callback = [this](const std_msgs::msg::String & msg) {
9999
this->topic_callback(msg);
100100
};
101101

@@ -104,9 +104,9 @@ Open the file using your preferred text editor.
104104
}
105105

106106
private:
107-
void topic_callback(const std_msgs::msg::String::ConstSharedPtr msg) const
107+
void topic_callback(const std_msgs::msg::String & msg) const
108108
{
109-
RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
109+
RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg.data.c_str());
110110
}
111111
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
112112
};
@@ -253,15 +253,15 @@ The terminal should start publishing statistics messages every 10 seconds, becau
253253
nanosec: 930797670
254254
statistics:
255255
- data_type: 1
256-
data: .nan
256+
data: 0.5522003000000001
257257
- data_type: 3
258-
data: .nan
258+
data: 0.756992
259259
- data_type: 2
260-
data: .nan
260+
data: 0.269039
261261
- data_type: 5
262-
data: 0.0
262+
data: 20.0
263263
- data_type: 4
264-
data: .nan
264+
data: 0.16441001797065166
265265
---
266266
measurement_source_name: minimal_subscriber_with_topic_statistics
267267
metrics_source: message_period
@@ -300,10 +300,6 @@ data_type value statistics
300300

301301
Here we see the two currently possible calculated statistics for the ``std_msgs::msg::String`` message published
302302
to ``/topic`` by the ``minimal_publisher``.
303-
Because the ``std_msgs::msg::String`` does not have a message header, the ``message_age`` calculation cannot be performed,
304-
so NaNs are returned.
305-
However, the ``message_period`` can be calculated and we see the statistics populated
306-
in the message above.
307303

308304
Summary
309305
-------

0 commit comments

Comments
 (0)