From 2113fae72ba6ee342fc0702b41d3e3ce53cf4ab5 Mon Sep 17 00:00:00 2001
From: Taekjin LEE <technolojin@gmail.com>
Date: Thu, 14 Nov 2024 11:34:31 +0900
Subject: [PATCH] fix: ground segmentation recheck condition relax (#1641)

* fix: relax recheck threshold

* fix: bug fix for an average process

* chore: update recheck threshold for ground cluster classification
---
 .../ground_segmentation/src/scan_ground_filter_nodelet.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp b/perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp
index 34573b564fa36..ff7c8b7ee3fdf 100644
--- a/perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp
+++ b/perception/ground_segmentation/src/scan_ground_filter_nodelet.cpp
@@ -257,8 +257,8 @@ void ScanGroundFilterComponent::checkContinuousGndGrid(
     gnd_buff_z_mean += it->avg_height;
   }
 
-  gnd_buff_radius /= static_cast<float>(gnd_grid_buffer_size_ - 1);
-  gnd_buff_z_mean /= static_cast<float>(gnd_grid_buffer_size_ - 1);
+  gnd_buff_radius /= static_cast<float>(gnd_grid_buffer_size_);
+  gnd_buff_z_mean /= static_cast<float>(gnd_grid_buffer_size_);
 
   float tmp_delta_mean_z = gnd_grids_list.back().avg_height - gnd_buff_z_mean;
   float tmp_delta_radius = gnd_grids_list.back().radius - gnd_buff_radius;
@@ -404,7 +404,8 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan(
       // move to new grid
       if (p->grid_id > prev_p->grid_id && ground_cluster.getAverageRadius() > 0.0) {
         // check if the prev grid have ground point cloud
-        if (use_recheck_ground_cluster_) {
+        const bool is_recheck_area = ground_cluster.getAverageRadius() > grid_mode_switch_radius_;
+        if (use_recheck_ground_cluster_ && is_recheck_area) {
           recheckGroundCluster(
             ground_cluster, non_ground_height_threshold_, use_lowest_point_, out_no_ground_indices);
         }