@@ -50,7 +50,7 @@ PerceptionOnlineEvaluatorNode::PerceptionOnlineEvaluatorNode(
50
50
51
51
objects_sub_ = create_subscription<PredictedObjects>(
52
52
" ~/input/objects" , 1 , std::bind (&PerceptionOnlineEvaluatorNode::onObjects, this , _1));
53
- metrics_pub_ = create_publisher<DiagnosticArray >(" ~/metrics" , 1 );
53
+ metrics_pub_ = create_publisher<tier4_metric_msgs::msg::MetricArray >(" ~/metrics" , 1 );
54
54
pub_marker_ = create_publisher<MarkerArray>(" ~/markers" , 10 );
55
55
56
56
tf_buffer_ = std::make_unique<tf2_ros::Buffer>(this ->get_clock ());
@@ -65,7 +65,8 @@ PerceptionOnlineEvaluatorNode::PerceptionOnlineEvaluatorNode(
65
65
66
66
void PerceptionOnlineEvaluatorNode::publishMetrics ()
67
67
{
68
- DiagnosticArray metrics_msg;
68
+ // DiagnosticArray metrics_msg;
69
+ tier4_metric_msgs::msg::MetricArray metrics_msg;
69
70
70
71
// calculate metrics
71
72
for (const Metric & metric : parameters_->metrics ) {
@@ -80,60 +81,55 @@ void PerceptionOnlineEvaluatorNode::publishMetrics()
80
81
for (const auto & [metric, value] : arg) {
81
82
if constexpr (std::is_same_v<T, MetricStatMap>) {
82
83
if (value.count () > 0 ) {
83
- metrics_msg. status . emplace_back ( generateDiagnosticStatus ( metric, value) );
84
+ toMetricMsg ( metric, value, metrics_msg );
84
85
}
85
86
} else if constexpr (std::is_same_v<T, MetricValueMap>) {
86
- metrics_msg. status . emplace_back ( generateDiagnosticStatus ( metric, value) );
87
+ toMetricMsg ( metric, value, metrics_msg );
87
88
}
88
89
}
89
90
},
90
91
metric_result.value ());
91
92
}
92
93
93
94
// publish metrics
94
- if (!metrics_msg.status .empty ()) {
95
- metrics_msg.header . stamp = now ();
95
+ if (!metrics_msg.metric_array .empty ()) {
96
+ metrics_msg.stamp = now ();
96
97
metrics_pub_->publish (metrics_msg);
97
98
}
98
99
publishDebugMarker ();
99
100
}
100
101
101
- DiagnosticStatus PerceptionOnlineEvaluatorNode::generateDiagnosticStatus (
102
- const std::string metric, const Accumulator<double > & metric_stat) const
102
+ void PerceptionOnlineEvaluatorNode::toMetricMsg (
103
+ const std::string & metric, const Accumulator<double > & metric_stat,
104
+ tier4_metric_msgs::msg::MetricArray & metrics_msg) const
103
105
{
104
- DiagnosticStatus status;
105
-
106
- status. level = status. OK ;
107
- status. name = metric;
108
-
109
- diagnostic_msgs::msg::KeyValue key_value;
110
- key_value. key = " min " ;
111
- key_value. value = std::to_string (metric_stat. min ());
112
- status. values . push_back (key_value);
113
- key_value. key = " max " ;
114
- key_value. value = std::to_string (metric_stat.max ());
115
- status. values . push_back (key_value);
116
- key_value. key = " mean" ;
117
- key_value. value = std::to_string (metric_stat. mean ());
118
- status. values . push_back (key_value);
119
-
120
- return status ;
106
+ // min value
107
+ metrics_msg. metric_array . emplace_back (tier4_metric_msgs::build<tier4_metric_msgs::msg::Metric>()
108
+ . name (metric + " /min " )
109
+ . unit ( " " )
110
+ . value ( std::to_string (metric_stat. min ())));
111
+
112
+ // max value
113
+ metrics_msg. metric_array . emplace_back (tier4_metric_msgs::build<tier4_metric_msgs::msg::Metric>()
114
+ . name (metric + " /max " )
115
+ . unit ( " " )
116
+ . value ( std::to_string (metric_stat.max ()) ));
117
+
118
+ // mean value
119
+ metrics_msg. metric_array . emplace_back (tier4_metric_msgs::build<tier4_metric_msgs::msg::Metric>()
120
+ . name (metric + " /mean " )
121
+ . unit ( " " )
122
+ . value ( std::to_string (metric_stat. mean ()))) ;
121
123
}
122
124
123
- DiagnosticStatus PerceptionOnlineEvaluatorNode::generateDiagnosticStatus (
124
- const std::string & metric, const double value) const
125
+ void PerceptionOnlineEvaluatorNode::toMetricMsg (
126
+ const std::string & metric, const double metric_value,
127
+ tier4_metric_msgs::msg::MetricArray & metrics_msg) const
125
128
{
126
- DiagnosticStatus status;
127
-
128
- status.level = status.OK ;
129
- status.name = metric;
130
-
131
- diagnostic_msgs::msg::KeyValue key_value;
132
- key_value.key = " metric_value" ;
133
- key_value.value = std::to_string (value);
134
- status.values .push_back (key_value);
135
-
136
- return status;
129
+ metrics_msg.metric_array .emplace_back (tier4_metric_msgs::build<tier4_metric_msgs::msg::Metric>()
130
+ .name (metric + " /metric_value" )
131
+ .unit (" " )
132
+ .value (std::to_string (metric_value)));
137
133
}
138
134
139
135
void PerceptionOnlineEvaluatorNode::onObjects (const PredictedObjects::ConstSharedPtr objects_msg)
0 commit comments