13
13
// limitations under the License.
14
14
15
15
#include " autoware/euclidean_cluster/voxel_grid_based_euclidean_cluster.hpp"
16
+ #include < rclcpp/node.hpp>
16
17
17
18
#include < pcl/kdtree/kdtree.h>
18
19
#include < pcl/segmentation/extract_clusters.h>
@@ -41,6 +42,35 @@ VoxelGridBasedEuclideanCluster::VoxelGridBasedEuclideanCluster(
41
42
min_points_number_per_voxel_(min_points_number_per_voxel)
42
43
{
43
44
}
45
+
46
+ // After processing all clusters, publish a summary of diagnostics.
47
+ void VoxelGridBasedEuclideanCluster::publishDiagnosticsSummary (
48
+ const std::vector<std::string> & warnings,
49
+ const sensor_msgs::msg::PointCloud2::ConstSharedPtr & pointcloud_msg)
50
+ {
51
+ if (!diagnostics_interface_ptr_) {
52
+ return ;
53
+ }
54
+ diagnostics_interface_ptr_->clear ();
55
+
56
+ std::stringstream summary;
57
+ if (!warnings.empty ()) {
58
+ summary << warnings.size () << " clusters skipped because cluster size exceeds the maximum allowed "
59
+ << max_cluster_size_ << " \n " ;
60
+ for (const auto & warn : warnings) {
61
+ summary << " - " << warn << " \n " ;
62
+ }
63
+ diagnostics_interface_ptr_->add_key_value (" is_cluster_data_size_within_range" , false );
64
+ } else {
65
+ diagnostics_interface_ptr_->add_key_value (" is_cluster_data_size_within_range" , true );
66
+ }
67
+ diagnostics_interface_ptr_->update_level_and_message (
68
+ warnings.empty () ? diagnostic_msgs::msg::DiagnosticStatus::OK : diagnostic_msgs::msg::DiagnosticStatus::WARN,
69
+ summary.str ());
70
+ diagnostics_interface_ptr_->publish (pointcloud_msg->header .stamp );
71
+ }
72
+
73
+
44
74
// TODO(badai-nguyen): remove this function when field copying also implemented for
45
75
// euclidean_cluster.cpp
46
76
bool VoxelGridBasedEuclideanCluster::cluster (
@@ -136,12 +166,25 @@ bool VoxelGridBasedEuclideanCluster::cluster(
136
166
137
167
// build output and check cluster size
138
168
{
169
+ // At the start, create a container to collect warnings.
170
+ std::vector<std::string> warning_messages;
139
171
for (size_t i = 0 ; i < temporary_clusters.size (); ++i) {
140
172
auto & i_cluster_data_size = clusters_data_size.at (i);
141
- if (!(min_cluster_size_ <= static_cast <int >(i_cluster_data_size / point_step) &&
142
- static_cast <int >(i_cluster_data_size / point_step) <= max_cluster_size_)) {
173
+ int cluster_size = static_cast <int >(i_cluster_data_size / point_step);
174
+ if (cluster_size < min_cluster_size_) {
175
+ // Cluster size is below the minimum threshold; skip without messaging.
176
+ continue ;
177
+ }
178
+ if (cluster_size > max_cluster_size_ /10 ) {
179
+ // Cluster size exceeds the maximum threshold; log a warning.
180
+ warning_messages.push_back (" Cluster " + std::to_string (i) + " (" + std::to_string (cluster_size) + " )." );
143
181
continue ;
144
182
}
183
+
184
+ // if (!(min_cluster_size_ <= static_cast<int>(i_cluster_data_size / point_step) &&
185
+ // static_cast<int>(i_cluster_data_size / point_step) <= max_cluster_size_)) {
186
+ // continue;
187
+ // }
145
188
const auto & cluster = temporary_clusters.at (i);
146
189
tier4_perception_msgs::msg::DetectedObjectWithFeature feature_object;
147
190
feature_object.feature .cluster = cluster;
@@ -164,6 +207,9 @@ bool VoxelGridBasedEuclideanCluster::cluster(
164
207
objects.feature_objects .push_back (feature_object);
165
208
}
166
209
objects.header = pointcloud_msg->header ;
210
+
211
+ publishDiagnosticsSummary (warning_messages, pointcloud_msg);
212
+
167
213
}
168
214
169
215
return true ;
0 commit comments