From ea7f9659b839afee975f6134a200993fd96750fb Mon Sep 17 00:00:00 2001 From: duongtd Date: Wed, 21 Oct 2026 14:21:53 +0700 Subject: [PATCH] feat(sensor_gateway): feed DepthCameraObstacleLayer through its own LayerType robot_costmap_2d has LayerType::DEPTH_CAMERA_LAYER for DepthCameraObstacleLayer. The gateway now pushes PointCloud2 to that type as well as to VOXEL_LAYER, in both the local and the global costmap. LaserScan, PointCloud and DepthCameraData stay VOXEL_LAYER only: the layer marks and clears from the filtered camera cloud and does not use the depth image. Needs robot_costmap_2d main 64974d4 or later (the enum value). Squashed from feature/depth-camera-layer-type (c280a0a..d3a9208). --- include/move_base2/io/sensor_gateway.h | 3 +++ src/io/sensor_gateway.cpp | 5 +++++ test/sensor_gateway_test.cpp | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/include/move_base2/io/sensor_gateway.h b/include/move_base2/io/sensor_gateway.h index d2753d1..3c3df6e 100644 --- a/include/move_base2/io/sensor_gateway.h +++ b/include/move_base2/io/sensor_gateway.h @@ -112,6 +112,9 @@ struct SensorGatewayStats * * ## Khác biệt có chủ đích so với `move_base` cũ * + * - **`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 5784edb..6cf7475 100644 --- a/src/io/sensor_gateway.cpp +++ b/src/io/sensor_gateway.cpp @@ -44,6 +44,8 @@ const char* toString(robot_costmap_2d::LayerType type) return "PreferredLayer"; case robot_costmap_2d::LayerType::UNPREFERRED_LAYER: return "UnpreferredLayer"; + case robot_costmap_2d::LayerType::DEPTH_CAMERA_LAYER: + return "DepthCameraObstacleLayer"; case robot_costmap_2d::LayerType::UNKNOWN: break; } @@ -331,6 +333,9 @@ void SensorGateway::pushPointCloud2(const std::string& name, ScopedSection timer(telemetry_, section_cloud_); dispatchTo(local_costmap_, cloud, robot_costmap_2d::LayerType::VOXEL_LAYER, name, stats_); dispatchTo(global_costmap_, cloud, robot_costmap_2d::LayerType::VOXEL_LAYER, name, stats_); + // DepthCameraObstacleLayer has its own type and marks from the camera's PointCloud2. + dispatchTo(local_costmap_, cloud, robot_costmap_2d::LayerType::DEPTH_CAMERA_LAYER, name, stats_); + dispatchTo(global_costmap_, cloud, robot_costmap_2d::LayerType::DEPTH_CAMERA_LAYER, name, stats_); } void SensorGateway::pushDepthCameraData(const std::string& topic, diff --git a/test/sensor_gateway_test.cpp b/test/sensor_gateway_test.cpp index e282ffd..79b4766 100644 --- a/test/sensor_gateway_test.cpp +++ b/test/sensor_gateway_test.cpp @@ -220,6 +220,27 @@ TEST(SensorGateway, ObstacleDataGoesOnlyToVoxelLayers) EXPECT_EQ(inflation->count(), 0U); } +TEST(SensorGateway, DepthCameraLayerGetsPointCloud2Only) +{ + // 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"); + SpyPtr voxel = bench.addLocal(LayerType::VOXEL_LAYER, "lidar_obstacles"); + bench.attach(); + + bench.gateway().pushLaserScan("/f_scan", makeScan()); + bench.gateway().pushPointCloud("/pc", robot_sensor_msgs::PointCloud()); + bench.gateway().pushPointCloud2("/camera/depth/points_proc", robot_sensor_msgs::PointCloud2()); + bench.gateway().pushDepthCameraData("/camera/depth/data", makeDepth()); + + ASSERT_EQ(depth_layer->count(), 1U); + EXPECT_TRUE(*depth_layer->records()[0].type == typeid(robot_sensor_msgs::PointCloud2)); + EXPECT_EQ(global_depth->count(), 1U); + EXPECT_EQ(voxel->count(), 4U); // the voxel layers keep getting everything, as before +} + TEST(SensorGateway, LayerNamedAfterATopicDoesNotReceiveTheSample) { // Hồi quy cho C5. Bản `move_base` cũ lọc bằng