Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 618aa1f

Browse files
authoredJan 29, 2024
Merge branch 'main' into chore/radar_object_clustering_param
2 parents b3772fd + e67ab70 commit 618aa1f

File tree

99 files changed

+3246
-1230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+3246
-1230
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<library path="tier4_metrics_rviz_plugin">
2+
<class type="rviz_plugins::MetricsVisualizePanel" base_class_type="rviz_common::Panel">
3+
<description>MetricsVisualizePanel</description>
4+
</class>
5+
</library>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2024 TIER IV, Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
#include "metrics_visualize_panel.hpp"
17+
18+
#include <rviz_common/display_context.hpp>
19+
20+
#include <X11/Xlib.h>
21+
22+
#include <algorithm>
23+
#include <optional>
24+
#include <string>
25+
#include <vector>
26+
27+
namespace rviz_plugins
28+
{
29+
MetricsVisualizePanel::MetricsVisualizePanel(QWidget * parent)
30+
: rviz_common::Panel(parent), grid_(new QGridLayout())
31+
{
32+
setLayout(grid_);
33+
}
34+
35+
void MetricsVisualizePanel::onInitialize()
36+
{
37+
using std::placeholders::_1;
38+
39+
raw_node_ = this->getDisplayContext()->getRosNodeAbstraction().lock()->get_raw_node();
40+
41+
sub_ = raw_node_->create_subscription<DiagnosticArray>(
42+
"/diagnostic/planning_evaluator/metrics", rclcpp::QoS{1},
43+
std::bind(&MetricsVisualizePanel::onMetrics, this, _1));
44+
45+
const auto period = std::chrono::milliseconds(static_cast<int64_t>(1e3 / 10));
46+
timer_ = raw_node_->create_wall_timer(period, [&]() { onTimer(); });
47+
}
48+
49+
void MetricsVisualizePanel::onTimer()
50+
{
51+
std::lock_guard<std::mutex> message_lock(mutex_);
52+
53+
for (auto & [name, metric] : metrics_) {
54+
metric.updateGraph();
55+
metric.updateTable();
56+
}
57+
}
58+
59+
void MetricsVisualizePanel::onMetrics(const DiagnosticArray::ConstSharedPtr msg)
60+
{
61+
std::lock_guard<std::mutex> message_lock(mutex_);
62+
63+
const auto time = msg->header.stamp.sec + msg->header.stamp.nanosec * 1e-9;
64+
65+
constexpr size_t GRAPH_COL_SIZE = 5;
66+
for (size_t i = 0; i < msg->status.size(); ++i) {
67+
const auto & status = msg->status.at(i);
68+
69+
if (metrics_.count(status.name) == 0) {
70+
auto metric = Metric(status);
71+
metrics_.emplace(status.name, metric);
72+
grid_->addWidget(metric.getTable(), i / GRAPH_COL_SIZE * 2, i % GRAPH_COL_SIZE);
73+
grid_->setRowStretch(i / GRAPH_COL_SIZE * 2, false);
74+
grid_->addWidget(metric.getChartView(), i / GRAPH_COL_SIZE * 2 + 1, i % GRAPH_COL_SIZE);
75+
grid_->setRowStretch(i / GRAPH_COL_SIZE * 2 + 1, true);
76+
grid_->setColumnStretch(i % GRAPH_COL_SIZE, true);
77+
}
78+
79+
metrics_.at(status.name).updateData(time, status);
80+
}
81+
}
82+
83+
} // namespace rviz_plugins
84+
85+
#include <pluginlib/class_list_macros.hpp>
86+
PLUGINLIB_EXPORT_CLASS(rviz_plugins::MetricsVisualizePanel, rviz_common::Panel)
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.