Skip to content
Snippets Groups Projects
Commit dae969b8 authored by bav6096's avatar bav6096
Browse files

refactoring

parent fe96cf7f
No related branches found
No related tags found
No related merge requests found
<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
......@@ -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()
......
#!/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
......
#!/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()
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment