19
19
#ifndef Q_MOC_RUN
20
20
#include < QChartView>
21
21
#include < QColor>
22
+ #include < QComboBox>
22
23
#include < QGridLayout>
23
24
#include < QHeaderView>
24
25
#include < QLabel>
25
26
#include < QLineSeries>
26
27
#include < QPainter>
28
+ #include < QPushButton>
27
29
#include < QTableWidget>
28
30
#include < QVBoxLayout>
29
31
#endif
33
35
34
36
#include < diagnostic_msgs/msg/diagnostic_array.hpp>
35
37
38
+ #include < iostream>
36
39
#include < limits>
37
40
#include < string>
38
41
#include < unordered_map>
42
+ #include < utility>
43
+ #include < vector>
39
44
40
45
namespace rviz_plugins
41
46
{
@@ -62,10 +67,10 @@ struct Metric
62
67
{
63
68
auto label = new QLabel;
64
69
label->setAlignment (Qt::AlignCenter);
65
- label->setText (" metric_name " );
70
+ label->setText (QString::fromStdString (status. name ) );
66
71
labels.emplace (" metric_name" , label);
67
72
68
- header.push_back (QString::fromStdString (status. name ) );
73
+ header.push_back (" metric_name " );
69
74
}
70
75
71
76
for (const auto & [key, value] : status.values ) {
@@ -146,6 +151,8 @@ struct Metric
146
151
147
152
QTableWidget * getTable () const { return table; }
148
153
154
+ std::unordered_map<std::string, QLabel *> getLabels () const { return labels; }
155
+
149
156
private:
150
157
static std::optional<std::string> getValue (const DiagnosticStatus & status, std::string && key)
151
158
{
@@ -186,19 +193,61 @@ class MetricsVisualizePanel : public rviz_common::Panel
186
193
void onInitialize () override ;
187
194
188
195
private Q_SLOTS:
196
+ // Slot functions triggered by UI events
197
+ void onTopicChanged ();
198
+ void onSpecificMetricChanged ();
199
+ void onClearButtonClicked ();
200
+ void onTabChanged ();
189
201
190
202
private:
203
+ // ROS 2 node and subscriptions for handling metrics data
191
204
rclcpp::Node::SharedPtr raw_node_;
192
205
rclcpp::TimerBase::SharedPtr timer_;
193
- rclcpp::Subscription<DiagnosticArray>::SharedPtr sub_;
206
+ std::unordered_map<std::string, rclcpp::Subscription<DiagnosticArray>::SharedPtr> subscriptions_;
207
+
208
+ // Topics from which metrics are collected
209
+ std::vector<std::string> topics_ = {
210
+ " /diagnostic/planning_evaluator/metrics" , " /diagnostic/perception_online_evaluator/metrics" };
194
211
212
+ // Timer and metrics message callback
195
213
void onTimer ();
196
- void onMetrics (const DiagnosticArray::ConstSharedPtr msg);
214
+ void onMetrics (const DiagnosticArray::ConstSharedPtr & msg, const std::string & topic_name);
215
+
216
+ // Functions to update UI based on selected metrics
217
+ void updateViews ();
218
+ void updateSelectedMetric (const std::string & metric_name);
197
219
220
+ // UI components
198
221
QGridLayout * grid_;
222
+ QComboBox * topic_selector_;
223
+ QTabWidget * tab_widget_;
224
+
225
+ // "Specific Metrics" tab components
226
+ QComboBox * specific_metric_selector_;
227
+ QChartView * specific_metric_chart_view_;
228
+ QTableWidget * specific_metric_table_;
229
+
230
+ // Selected metrics data
231
+ std::optional<std::pair<std::string, Metric>> selected_metrics_;
199
232
233
+ // Cache for received messages by topics
234
+ std::unordered_map<std::string, DiagnosticArray::ConstSharedPtr> current_msg_map_;
235
+
236
+ // Mapping from topics to metrics widgets (tables and charts)
237
+ std::unordered_map<
238
+ std::string, std::unordered_map<std::string, std::pair<QTableWidget *, QChartView *>>>
239
+ topic_widgets_map_;
240
+
241
+ // Synchronization
200
242
std::mutex mutex_;
243
+
244
+ // Stored metrics data
201
245
std::unordered_map<std::string, Metric> metrics_;
246
+
247
+ // Utility functions for managing widget visibility based on topics
248
+ void updateWidgetVisibility (const std::string & target_topic, const bool show);
249
+ void showCurrentTopicWidgets ();
250
+ void hideInactiveTopicWidgets ();
202
251
};
203
252
} // namespace rviz_plugins
204
253
0 commit comments