Skip to content

Commit 1b369ac

Browse files
committed
change logic for UI adaptor to still work with NITROS
1 parent 6fefc75 commit 1b369ac

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

greenwave_monitor/greenwave_monitor/ui_adaptor.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def __init__(self, node: Node, monitor_node_name: str = 'greenwave_monitor'):
104104
self.node = node
105105
self.monitor_node_name = monitor_node_name
106106
self.data_lock = threading.Lock()
107-
# Use a plain dict so lookups don't create entries implicitly (which broke add/remove)
108107
self.ui_diagnostics: Dict[str, UiDiagnosticData] = {}
109108
# { topic_name : (expected_hz, tolerance) }
110109
self.expected_frequencies: Dict[str, tuple[float, float]] = {}
@@ -135,14 +134,39 @@ def _setup_ros_components(self):
135134
set_freq_service_name
136135
)
137136

137+
def _extract_topic_name(self, diagnostic_name: str) -> str:
138+
"""
139+
Extract topic name from diagnostic status name.
140+
141+
Handles both formats:
142+
- NITROS: node_name + namespace + "/" + topic (e.g., "my_node/ns/camera/image")
143+
- Greenwave: topic_name only (e.g., "/ns/camera/image")
144+
145+
This is a temporary hack until NITROS migrates to message_diagnostics.hpp.
146+
"""
147+
# If the name starts with '/', it's already just a topic name (Greenwave format)
148+
if diagnostic_name.startswith('/'):
149+
return diagnostic_name
150+
151+
# NITROS format: node_name + namespace + "/" + topic_name
152+
# Node names cannot contain '/', so the first '/' marks where namespace+topic begins
153+
idx = diagnostic_name.find('/')
154+
if idx >= 0:
155+
return diagnostic_name[idx:]
156+
157+
# Fallback: return as-is if no '/' found
158+
return diagnostic_name
159+
138160
def _on_diagnostics(self, msg: DiagnosticArray):
139161
"""Process incoming diagnostic messages."""
140162
with self.data_lock:
141163
# Update diagnostics
142164
for status in msg.status:
143165
ui_data = UiDiagnosticData.from_status(status)
144166
ui_data.last_update = time.time()
145-
self.ui_diagnostics[status.name] = ui_data
167+
# Normalize the topic name to handle both NITROS and Greenwave formats
168+
topic_name = self._extract_topic_name(status.name)
169+
self.ui_diagnostics[topic_name] = ui_data
146170

147171
def toggle_topic_monitoring(self, topic_name: str):
148172
"""Toggle monitoring for a topic."""
@@ -235,7 +259,6 @@ def set_expected_frequency(self,
235259
def get_topic_diagnostics(self, topic_name: str) -> UiDiagnosticData:
236260
"""Get diagnostic data for a topic. Returns default values if topic not found."""
237261
with self.data_lock:
238-
# Do not create entries for non-monitored topics
239262
return self.ui_diagnostics.get(topic_name, UiDiagnosticData())
240263

241264
def get_expected_frequency(self, topic_name: str) -> tuple[float, float]:

greenwave_monitor/include/message_diagnostics.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ struct MessageDiagnosticsConfig
6060
// enable basic diagnostics for all topics, triggered by an environment variable
6161
bool enable_all_topic_diagnostics{false};
6262

63-
// Rate (Hz) at which to publish diagnostics to a ROS topic
64-
// float diagnostics_publish_rate{1.0};
65-
6663
// Window size of the mean filter in terms of number of messages received
6764
int filter_window_size{300};
6865

0 commit comments

Comments
 (0)