Skip to content

Commit 34e400a

Browse files
committed
use duration to compute the delay
Signed-off-by: Chris Ye <chris.ye@intel.com>
1 parent 0e79d06 commit 34e400a

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

ros2topic/ros2topic/verb/delay.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
from rclpy.expand_topic_name import expand_topic_name
4444
from rclpy.qos import qos_profile_sensor_data
45+
from rclpy.time import Time
4546
from rclpy.validate_full_topic_name import validate_full_topic_name
4647
from ros2cli.node.direct import DirectNode
4748
from ros2topic.api import get_topic_names_and_types
@@ -114,12 +115,9 @@ def callback_delay(self, msg):
114115
self.msg_tn = curr
115116
self.delays = []
116117
else:
117-
curr_sec = curr_rostime.to_msg().sec
118-
curr_nanosec = curr_rostime.to_msg().nanosec
119-
120-
delay = ((curr_sec + curr_nanosec * 1e-9) -
121-
(msg.header.stamp.sec + msg.header.stamp.nanosec * 1e-9))
122-
self.delays.append(delay)
118+
# store the duration nanoseconds in self.delays
119+
duration = (curr_rostime - Time.from_msg(msg.header.stamp))
120+
self.delays.append(duration.nanoseconds)
123121
self.msg_tn = curr
124122

125123
if len(self.delays) > self.window_size:
@@ -158,8 +156,9 @@ def print_delay(self):
158156
print('no new messages')
159157
return
160158
delay, min_delta, max_delta, std_dev, window = ret
159+
# convert nanoseconds to seconds when print
161160
print('average delay: %.3f\n\tmin: %.3fs max: %.3fs std dev: %.5fs window: %s'
162-
% (delay, min_delta, max_delta, std_dev, window))
161+
% (delay * 1e-9, min_delta * 1e-9, max_delta * 1e-9, std_dev * 1e-9, window))
163162

164163

165164
def _rostopic_delay(node, topic, window_size=-1):

0 commit comments

Comments
 (0)