This package contains a dynamic ROS 2 subscriber node that calculates the frequency (Hz) of incoming messages for any given topic. The topic name and message type can be specified via command-line parameters when launching the node.
Ensure that you have a working ROS 2 environment installed. The package is compatible with ROS 2 distributions such as Humble, Iron, or Jazzy. The package depends on the following ROS 2 packages:
rclcpp
sensor_msgs
std_msgs
-
Navigate to your ROS 2 workspace:
cd ~/ros2_ws/src
-
Clone the repository:
git clone https://github.com/SamerKhshiboun/dynamic_subscriber_node
-
Build the package using
colcon
:cd ~/ros2_ws colcon build
-
Source the workspace after building:
source install/setup.bash
The node subscribes to a specified topic and calculates the frequency of incoming messages. You can provide the topic name and message type through command-line arguments.
You can run the node using the ros2 run
command, passing the topic_name
and topic_type
parameters.
ros2 run dynamic_subscriber_node dynamic_subscriber_node --ros-args -p topic_name:=<topic_name> -p topic_type:=<topic_type>
topic_name
: The ROS 2 topic to which the node should subscribe.topic_type
: The message type of the topic (e.g.,sensor_msgs/msg/Image
orsensor_msgs/msg/CompressedImage
).
Here are some examples of running the node with different topics and message types:
For subscribing to the depth image topic:
ros2 run dynamic_subscriber_node dynamic_subscriber_node --ros-args -p topic_name:=/camera/camera/depth/image_rect_raw -p topic_type:=sensor_msgs/msg/Image
For subscribing to the compressed depth image topic:
ros2 run dynamic_subscriber_node dynamic_subscriber_node --ros-args -p topic_name:=/camera/camera/depth/image_rect_raw/compressedDepth -p topic_type:=sensor_msgs/msg/CompressedImage
For subscribing to the raw color image topic:
ros2 run dynamic_subscriber_node dynamic_subscriber_node --ros-args -p topic_name:=/camera/camera/color/image_raw -p topic_type:=sensor_msgs/msg/Image
For subscribing to the compressed color image topic:
ros2 run dynamic_subscriber_node dynamic_subscriber_node --ros-args -p topic_name:=/camera/camera/color/image_raw/compressed -p topic_type:=sensor_msgs/msg/CompressedImage
If you want to run the node using Best-Effort Quality of Service (QoS), you can pass the qos_reliability
parameter:
ros2 run dynamic_subscriber_node dynamic_subscriber_node --ros-args -p topic_name:=/camera/camera/color/image_raw -p topic_type:=sensor_msgs/msg/Image -p qos_reliability:=best_effort
qos_reliability
: Specify the reliability QoS policy. Valid values arereliable
(default) andbest_effort
.
If you need to handle additional message types or further customize the node, you can edit the source file (src/dynamic_subscriber_node.cpp
). Ensure that any additional message types are linked in the CMakeLists.txt
and package.xml
.