Inconsistency of topic hz command

asked 2019-12-09 07:17:25 -0500

tlaci gravatar image

updated 2019-12-09 07:49:26 -0500


I observed a strange behaviour when using ros2 topic hz command. It seems to me that ros2 topic hz command gives lower frequency results than the actual frame rate when publishing images. (tried with various frame rates).

I have the following nodes:
- Camera node pusblishing 1920x1200 images of two cameras with 25 fps (c++) - subscribing node to analyze incoming data (modified c++ subscriber_member_function of the tutorial code)

auto ts = this->now();  
msg->header.stamp = ts;  
RCLCPP_INFO(this->get_logger(), "I hear message at: %.3lf", (double) msg->header.stamp.sec + (double) msg->header.stamp.nanosec/1e9);

I started ros2 topic hz, the subscriber node and the camera node to observe frame rates and i got the following results:

Publisher (camera) node:

AVG: 25.0866 sec, STD DEV: 0.00035 sec

Subscriber node

AVG: 25.0103 sec, STD DEV: 0.0019 sec

ros2 topic hz

AVG: 24.553 sec, STD DEV: 0.0063 sec

ros2 topic hz always gives a lower results. Strangely, when not starting the subcriber node ros2 topic quickly drops to 21-22Hz which makes me feel ros2 topic hz command is untrustworthy.

Can someone give me an explanation to this observation? In this ticket it was mentioned that topic hz command uses python api which caused problems lately I wonder if it has something to do with my problem too.

edit retag flag offensive close merge delete