From d3a9208b65767653443c87ca113572cb3119b2bf Mon Sep 17 00:00:00 2001 From: duongtd Date: Wed, 21 Oct 2026 13:35:57 +0700 Subject: [PATCH] fix(sensor_gateway): stop sending DepthCameraData to DepthCameraObstacleLayer DepthCameraObstacleLayer only uses the camera PointCloud2 and ignored the depth image it was sent. DEPTH_CAMERA_LAYER now gets PointCloud2 only; the VOXEL_LAYER dispatch and the addDepthCameraData API are unchanged. --- include/move_base2/io/sensor_gateway.h | 5 +++-- src/io/sensor_gateway.cpp | 4 ---- test/sensor_gateway_test.cpp | 11 +++++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/move_base2/io/sensor_gateway.h b/include/move_base2/io/sensor_gateway.h index aabd7cb..3c3df6e 100644 --- a/include/move_base2/io/sensor_gateway.h +++ b/include/move_base2/io/sensor_gateway.h @@ -112,8 +112,9 @@ struct SensorGatewayStats * * ## Khác biệt có chủ đích so với `move_base` cũ * - * - **`DEPTH_CAMERA_LAYER` nhận `PointCloud2` và `DepthCameraData`** (không nhận `LaserScan`, - * `PointCloud`), song song với `VOXEL_LAYER`: `DepthCameraObstacleLayer` có loại riêng. + * - **`DEPTH_CAMERA_LAYER` chỉ nhận `PointCloud2`** (không nhận `LaserScan`, `PointCloud`, + * `DepthCameraData`), song song với `VOXEL_LAYER`: `DepthCameraObstacleLayer` có loại riêng và + * chỉ dùng cloud đã lọc của camera. * - **Lọc layer chỉ theo `getType()`.** Bản cũ dùng `getType() == type || getName() == name`. Vế * tên là code chết trong thực tế (tên layer là `obstacles`/`inflation`, tên sensor là * `/b_scan`/`/map` — hai tập không giao nhau) nhưng lại là một cái bẫy: đặt tên một layer trùng diff --git a/src/io/sensor_gateway.cpp b/src/io/sensor_gateway.cpp index 5c8a5fd..6cf7475 100644 --- a/src/io/sensor_gateway.cpp +++ b/src/io/sensor_gateway.cpp @@ -361,10 +361,6 @@ void SensorGateway::pushDepthCameraData(const std::string& topic, // rơi im lặng qua mọi nhánh của handleImpl. dispatchTo(local_costmap_, data, robot_costmap_2d::LayerType::VOXEL_LAYER, topic, stats_); dispatchTo(global_costmap_, data, robot_costmap_2d::LayerType::VOXEL_LAYER, topic, stats_); - // The depth image goes to DepthCameraObstacleLayer too (unused today, needed by depth-image - // clearing); LaserScan and PointCloud do not. - dispatchTo(local_costmap_, data, robot_costmap_2d::LayerType::DEPTH_CAMERA_LAYER, topic, stats_); - dispatchTo(global_costmap_, data, robot_costmap_2d::LayerType::DEPTH_CAMERA_LAYER, topic, stats_); } } // namespace move_base2 diff --git a/test/sensor_gateway_test.cpp b/test/sensor_gateway_test.cpp index ebd74e9..79b4766 100644 --- a/test/sensor_gateway_test.cpp +++ b/test/sensor_gateway_test.cpp @@ -220,10 +220,10 @@ TEST(SensorGateway, ObstacleDataGoesOnlyToVoxelLayers) EXPECT_EQ(inflation->count(), 0U); } -TEST(SensorGateway, DepthCameraLayerGetsPointCloud2AndDepthOnly) +TEST(SensorGateway, DepthCameraLayerGetsPointCloud2Only) { - // DepthCameraObstacleLayer has its own LayerType: it must get the camera cloud and the depth - // image (as ConstPtr), and nothing meant for the lidar layers. + // DepthCameraObstacleLayer has its own LayerType: it must get the camera cloud, and neither the + // depth image (it does not use it) nor anything meant for the lidar layers. Bench bench; SpyPtr depth_layer = bench.addLocal(LayerType::DEPTH_CAMERA_LAYER, "depth_obstacles"); SpyPtr global_depth = bench.addGlobal(LayerType::DEPTH_CAMERA_LAYER, "depth_obstacles"); @@ -235,10 +235,9 @@ TEST(SensorGateway, DepthCameraLayerGetsPointCloud2AndDepthOnly) bench.gateway().pushPointCloud2("/camera/depth/points_proc", robot_sensor_msgs::PointCloud2()); bench.gateway().pushDepthCameraData("/camera/depth/data", makeDepth()); - ASSERT_EQ(depth_layer->count(), 2U); + ASSERT_EQ(depth_layer->count(), 1U); EXPECT_TRUE(*depth_layer->records()[0].type == typeid(robot_sensor_msgs::PointCloud2)); - EXPECT_TRUE(*depth_layer->records()[1].type == typeid(robot_sensor_msgs::DepthCameraData::ConstPtr)); - EXPECT_EQ(global_depth->count(), 2U); + EXPECT_EQ(global_depth->count(), 1U); EXPECT_EQ(voxel->count(), 4U); // the voxel layers keep getting everything, as before }