Skip to content

Commit

Permalink
ignore rate calculate when last time is zero
Browse files Browse the repository at this point in the history
first time when self.get_last_printed_tn is zero, the rate value is not correct, just ignore when last time is zero.

Signed-off-by: Chris Ye <[email protected]>
  • Loading branch information
yechun1 committed Sep 1, 2018
1 parent d19461a commit 062e814
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ros2topic/ros2topic/verb/hz.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,13 @@ def get_hz(self, topic=None):
"""
if not self.get_times(topic=topic):
return
elif self.get_last_printed_tn(topic=topic) == 0:
self.set_last_printed_tn(self.get_msg_tn(topic=topic), topic=topic)
return
elif self.get_msg_tn(topic=topic) < self.get_last_printed_tn(topic=topic) + 1:
return
with self.lock:
# frequency
# Get frequency every one minute
n = len(self.get_times(topic=topic))
mean = sum(self.get_times(topic=topic)) / n
rate = 1. / mean if mean > 0. else 0
Expand Down

0 comments on commit 062e814

Please sign in to comment.