From 5076eb18a7c92dea05eaa368bea3f3a2072a4444 Mon Sep 17 00:00:00 2001 From: Christian Henkel <6976069+ct2034@users.noreply.github.com> Date: Wed, 26 Jun 2024 17:28:39 +0200 Subject: [PATCH] NTP monitor improvements (#342) (#350) * NTP monitor improvements * commit to run tests again * bring back double callback * remove whiteline --------- Co-authored-by: Angsa Deployment Team (cherry picked from commit 7efb71ad5118f6b7d57d32d8e6b93ce4aa53e41e) Co-authored-by: Tony Najjar --- .../diagnostic_common_diagnostics/ntp_monitor.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/diagnostic_common_diagnostics/diagnostic_common_diagnostics/ntp_monitor.py b/diagnostic_common_diagnostics/diagnostic_common_diagnostics/ntp_monitor.py index 8671ddb5..461d17bd 100755 --- a/diagnostic_common_diagnostics/diagnostic_common_diagnostics/ntp_monitor.py +++ b/diagnostic_common_diagnostics/diagnostic_common_diagnostics/ntp_monitor.py @@ -50,6 +50,8 @@ def __init__(self, ntp_hostname, ntp_port, offset=500, self_offset=500, do_self_test=True): """Initialize the NTPMonitor.""" super().__init__(__class__.__name__) + self.declare_parameter('frequency', 10.0) + frequency = self.get_parameter('frequency').get_parameter_value().double_value self.ntp_hostname = ntp_hostname self.ntp_port = ntp_port @@ -85,8 +87,8 @@ def __init__(self, ntp_hostname, ntp_port, offset=500, self_offset=500, # we need to periodically republish this self.current_msg = None - self.pubtimer = self.create_timer(0.1, self.pubCB) - self.checktimer = self.create_timer(0.1, self.checkCB) + self.pubtimer = self.create_timer(1/frequency, self.pubCB) + self.checktimer = self.create_timer(1/frequency, self.checkCB) def pubCB(self): with self.mutex: @@ -95,6 +97,7 @@ def pubCB(self): def checkCB(self): new_msg = DIAG.DiagnosticArray() + new_msg.header.stamp = self.get_clock().now().to_msg() st = self.ntp_diag(self.stat) if st is not None: @@ -159,7 +162,7 @@ def add_kv(stat_values, key, value): def ntp_monitor_main(argv=sys.argv[1:]): # filter out ROS args - argv = [a for a in argv if not a.startswith('__') and not a == '--ros-args' and not a == '-r'] + argv = argv[:argv.index('--ros-args')] if '--ros-args' in argv else argv import argparse parser = argparse.ArgumentParser()