Skip to content

[ros2topic] pub frequency lower then expect  #140

@yechun1

Description

@yechun1

publish msg period as 1 minutes, but actually the result is lower then expect.

$ ros2 topic pub /image sensor_msgs/Image -r 10 -p 10
actually period: 1.004s.

$ ros2 topic pub /image sensor_msgs/Image -r 100 -p 100
actually period: 1.040s.

$ ros2 topic pub /image sensor_msgs/Image -r 1000 -p 1000
actually period: 1.387s.

reference debug code:

diff --git a/ros2topic/ros2topic/verb/pub.py b/ros2topic/ros2topic/verb/pub.py
index e07bdeb..431877d 100644
--- a/ros2topic/ros2topic/verb/pub.py
+++ b/ros2topic/ros2topic/verb/pub.py
@@ -101,9 +101,13 @@ def publisher(

     print('publisher: beginning loop')
     count = 0
+    prev = time.time()
     while rclpy.ok():
         count += 1
         if print_nth and count % print_nth == 0:
+            interval = time.time() - prev
+            print('interval:%s' %interval)
+            prev = time.time()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions