From c280a0a019bb6301c5a1561d24895a0d3f411804 Mon Sep 17 00:00:00 2001 From: duongtd Date: Tue, 20 Oct 2026 14:28:14 +0700 Subject: [PATCH] feat(sensor_gateway): feed DepthCameraObstacleLayer through its own LayerType robot_costmap_2d now has LayerType::DEPTH_CAMERA_LAYER for DepthCameraObstacleLayer. The gateway pushes PointCloud2 and DepthCameraData to that type as well as to VOXEL_LAYER; LaserScan and PointCloud stay VOXEL_LAYER only. Needs the robot_costmap_2d commit that adds the enum value. --- include/move_base2/io/sensor_gateway.h | 2 ++ src/io/sensor_gateway.cpp | 9 +++++++++ test/sensor_gateway_test.cpp | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/move_base2/io/sensor_gateway.h b/include/move_base2/io/sensor_gateway.h index d2753d1..aabd7cb 100644 --- a/include/move_base2/io/sensor_gateway.h +++ b/include/move_base2/io/sensor_gateway.h @@ -112,6 +112,8 @@ 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. * - **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..5c8a5fd 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, @@ -356,6 +361,10 @@ 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 e282ffd..ebd74e9 100644 --- a/test/sensor_gateway_test.cpp +++ b/test/sensor_gateway_test.cpp @@ -220,6 +220,28 @@ TEST(SensorGateway, ObstacleDataGoesOnlyToVoxelLayers) EXPECT_EQ(inflation->count(), 0U); } +TEST(SensorGateway, DepthCameraLayerGetsPointCloud2AndDepthOnly) +{ + // DepthCameraObstacleLayer has its own LayerType: it must get the camera cloud and the depth + // image (as ConstPtr), and nothing 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(), 2U); + 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(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