From dae969b8ab80ef94d6703b1c708449aa4c9c434f Mon Sep 17 00:00:00 2001
From: bav6096 <benedikt.deike@informatik.uni-hamburg.de>
Date: Mon, 3 Jan 2022 07:05:32 +0100
Subject: [PATCH] refactoring

---
 launch/monitoring.launch  | 7 ++++---
 nodes/monitor_distance    | 7 ++-----
 nodes/monitor_test_2      | 5 +++--
 nodes/monitor_test_3      | 5 +++--
 src/monitoring/monitor.py | 5 +++--
 5 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/launch/monitoring.launch b/launch/monitoring.launch
index 05491ba..678831e 100644
--- a/launch/monitoring.launch
+++ b/launch/monitoring.launch
@@ -1,11 +1,12 @@
 <launch>
+    <!-- frequency at which all monitors publish updated values -->
+    <param name="mon_freq" value="0.1" />
+
     <!--
     <include file="$(find monitoring)/launch/translator.launch" />
-    -->
-
     <include file="$(find monitoring)/launch/monitor_distance.launch" />
-
     <include file="$(find monitoring)/launch/monitor_test_1.launch" />
+    -->
     <include file="$(find monitoring)/launch/monitor_test_2.launch" />
     <include file="$(find monitoring)/launch/monitor_test_3.launch" />
 </launch>
\ No newline at end of file
diff --git a/nodes/monitor_distance b/nodes/monitor_distance
index deeb301..7e97722 100755
--- a/nodes/monitor_distance
+++ b/nodes/monitor_distance
@@ -22,13 +22,10 @@ if __name__ == '__main__':
         rate = rospy.Rate(10)
         while not rospy.is_shutdown():
 
-            if distance > 0.8:
+            if distance > 1.0:
                 error = 0
             else:
-                if distance > 0.35:
-                    error = 0.5
-                else:
-                    error = 1.0
+                error = 1.0 - distance
 
             monitor.update_metric("kinect", "distance", distance, "meter", error)
             rate.sleep()
diff --git a/nodes/monitor_test_2 b/nodes/monitor_test_2
index 784689e..5b91092 100755
--- a/nodes/monitor_test_2
+++ b/nodes/monitor_test_2
@@ -1,17 +1,18 @@
 #!/usr/bin/env python
 
 import rospy
+
 from monitoring.monitor import Monitor
 
 
 def monitor_test_2():
     rospy.init_node("monitor_test_2")
-    monitor = Monitor(1, 0.2)
+    monitor = Monitor(1)
 
     rate = rospy.Rate(1.0)
     value = 0
     while not rospy.is_shutdown():
-        monitor.update_metric("test_domain_1", "test_label_2", 10, "unit", value)
+        monitor.update_metric("test", "test", 10, "unit", value)
         value = value + 0.1
         if value > 1.0:
             value = 0
diff --git a/nodes/monitor_test_3 b/nodes/monitor_test_3
index 5ed32c9..d643edc 100755
--- a/nodes/monitor_test_3
+++ b/nodes/monitor_test_3
@@ -1,16 +1,17 @@
 #!/usr/bin/env python
 
 import rospy
+
 from monitoring.monitor import Monitor
 
 
 def monitor_test_3():
     rospy.init_node("monitor_test_3")
-    monitor = Monitor(1, 0.2)
+    monitor = Monitor(1)
 
     rate = rospy.Rate(0.2)
     while not rospy.is_shutdown():
-        monitor.update_metric("test_domain_2", "test_label_3", 10, "unit", 1.0)
+        monitor.update_metric("a", "a", 10, "unit", 1.0)
         rate.sleep()
 
 
diff --git a/src/monitoring/monitor.py b/src/monitoring/monitor.py
index e6f7121..942fdc6 100755
--- a/src/monitoring/monitor.py
+++ b/src/monitoring/monitor.py
@@ -21,11 +21,12 @@ class Monitor:
     Furthermore, a monitor publishes messages with a
     certain frequency.
     """
-    def __init__(self, mon_mode=1, mon_freq=1.0):
+    def __init__(self, mon_mode=1):
         self.log = {}  # Logging dictionary. Is used to accomplish different publishing modes.
         self.pub = rospy.Publisher("/monitoring", Monitoring, queue_size=1)
         self.mon_mode = mon_mode
 
+        mon_freq = rospy.get_param("/mon_freq")
         if not mon_freq > 0.0:
             rospy.logwarn("The frequency at which a monitor publishes messages must be greater then 0! "
                           "Using 1 as frequency!")
@@ -37,7 +38,7 @@ class Monitor:
         self.monitoring.origin = socket.gethostname() + rospy.get_name()
 
     # At the moment the last metric update ist published over and over.
-    def publish_monitoring(self, event):
+    def publish_monitoring(self, _):
         self.pub.publish(self.monitoring)
 
     def update_metric(self, domain, label, value, unit, error):
-- 
GitLab