From a6bdd093582b2545443d37b82d4f442a61f0f8c9 Mon Sep 17 00:00:00 2001 From: Thomas Bonnefille Date: Mon, 6 Nov 2023 22:02:02 +0100 Subject: [PATCH] Change the type of the buffer array As the lidar sends distance with the type float, we have to store those datas in an array of float. The conversion from float to int return zeros which messed up the median filter. Signed-off-by: Thomas Bonnefille --- src/cluster_detector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cluster_detector.cpp b/src/cluster_detector.cpp index ab24b58..8f7b276 100644 --- a/src/cluster_detector.cpp +++ b/src/cluster_detector.cpp @@ -18,7 +18,7 @@ void ClusterDetector::scan_callback(const sensor_msgs::msg::LaserScan msg){ return; } - int val_list[2*NB_MEDIAN+1]; + float val_list[2*NB_MEDIAN+1]; int i,add, access_index, buffer_index; float buffer_val; for (i = 0; ipoints[i].cluster_id=-1;} @@ -29,7 +29,7 @@ void ClusterDetector::scan_callback(const sensor_msgs::msg::LaserScan msg){ for (add = -NB_MEDIAN; add <= NB_MEDIAN; add++){ access_index = i + add; if (access_index < 0){access_index+=NB_POINT_SCAN;} - if (access_index >= NB_POINT_SCAN){access_index-=NB_POINT_SCAN;} + else if (access_index >= NB_POINT_SCAN){access_index-=NB_POINT_SCAN;} val_list[NB_MEDIAN+add] = (msg.ranges[access_index] < 10) ? msg.ranges[access_index] : 30; }