feat(depth): DepthCameraObstacleLayer gets its own LayerType

The plugin reported VOXEL_LAYER only because SensorGateway feeds sensor data
to that type. It is its own layer, so LayerType gains DEPTH_CAMERA_LAYER
(appended last: the values of the existing types do not move) and the plugin
returns it. move_base2's SensorGateway delivers PointCloud2 and
DepthCameraData to the new type in the matching commit; without that commit
the layer receives nothing.

matchSize() is overridden as well: CostmapLayer::matchSize() rebuilds the own
grid with the default value, so the stored columns are re-marked under the
layer mutex right away and the whole layer is queued for the next merge.
This commit is contained in:
2026-10-20 14:28:14 +07:00
parent a5f548f0d7
commit 40dc70e758
5 changed files with 47 additions and 7 deletions

View File

@@ -461,8 +461,9 @@ cần quan sát. Không tăng `max_obstacle_height` vượt khỏi voxel grid m
### 5.6. DepthCameraObstacleLayer
Port thuật toán của `costmap_depth_camera` (noetic). Layer nhận `PointCloud2` đã lọc của từng
depth camera và giữ các điểm vật cản 3D trong frame global của costmap. Lưới riêng của layer
Port thuật toán của `costmap_depth_camera` (noetic). Layer có loại riêng `LayerType::DEPTH_CAMERA_LAYER`:
`SensorGateway` của `move_base2` đẩy `PointCloud2` và `DepthCameraData` vào nó (không đẩy `LaserScan`).
Layer nhận `PointCloud2` đã lọc của từng depth camera và giữ các điểm vật cản 3D trong frame global của costmap. Lưới riêng của layer
phản chiếu các điểm đó theo từng ô (cột có điểm là `LETHAL`, cột mất điểm cuối cùng thành
`FREE_SPACE`), rồi được gộp lên master như `ObstacleLayer` (`combination_method`). Mỗi chu kỳ:

View File

@@ -17,8 +17,8 @@
* reset() kept its global-mode points, B9).
* Host adaptations: data arrives through handleImpl() and a cloud is processed in
* updateBounds() once TF at its stamp exists (the role of the tf2_ros::MessageFilter);
* getType() is VOXEL_LAYER, the only type SensorGateway feeds sensor data to; no ROS
* publishers or dynamic_reconfigure; `sensor_frame_is_optical` builds the frustum in a Z-forward
* getType() is its own DEPTH_CAMERA_LAYER, which SensorGateway feeds PointCloud2 and
* DepthCameraData; no ROS publishers or dynamic_reconfigure; `sensor_frame_is_optical` builds the frustum in a Z-forward
* optical frame; markings that leave the rolling window are dropped (B6).
*********************************************************************/
#ifndef ROBOT_COSTMAP_2D_DEPTH_CAMERA_OBSTACLE_LAYER_H_
@@ -110,12 +110,15 @@ public:
*/
void clearArea(int start_x, int start_y, int end_x, int end_y, bool invert_area = false) override;
/// SensorGateway only delivers obstacle data to VOXEL_LAYER plugins.
/// Own type: SensorGateway delivers PointCloud2 and DepthCameraData to it, not LaserScan.
LayerType getType() const override
{
return LayerType::VOXEL_LAYER;
return LayerType::DEPTH_CAMERA_LAYER;
}
/// Resizes the own grid to the master and re-marks the stored columns right away.
void matchSize() override;
/// Number of stored (column, height) points, for tests and the stats log.
std::size_t storedPoints() const;

View File

@@ -56,7 +56,10 @@ enum class LayerType
DIRECTIONAL_LAYER,
PREFERRED_LAYER,
UNPREFERRED_LAYER,
VOXEL_LAYER
VOXEL_LAYER,
/// DepthCameraObstacleLayer. Appended last so the values above keep their numbers; the host's
/// SensorGateway feeds it PointCloud2 and DepthCameraData.
DEPTH_CAMERA_LAYER
};
class LayeredCostmap;

View File

@@ -908,6 +908,24 @@ void DepthCameraObstacleLayer::reset()
activate();
}
void DepthCameraObstacleLayer::matchSize()
{
// The master was resized (or this is onInitialize): CostmapLayer::matchSize() rebuilds the own
// grid with default_value_, so put the stored columns back now instead of waiting a cycle, and
// ask the next update to merge the whole layer.
boost::unique_lock<mutex_t> lock(*getMutex());
CostmapLayer::matchSize();
for (const auto& column : pc_3d_map_global_)
{
unsigned int mx, my;
if (columnCell(column.first, mx, my))
setCost(mx, my, LETHAL_OBSTACLE);
}
if (!pc_3d_map_global_.empty())
addExtraBounds(getOriginX(), getOriginY(), getOriginX() + getSizeInMetersX(),
getOriginY() + getSizeInMetersY());
}
void DepthCameraObstacleLayer::clearArea(int start_x, int start_y, int end_x, int end_y, bool invert_area)
{
boost::unique_lock<mutex_t> lock(*getMutex());

View File

@@ -406,6 +406,21 @@ TEST_F(DepthCameraFootprintTest, FootprintClearingErasesThePointsUnderTheRobot)
EXPECT_NE(master(), LETHAL_OBSTACLE);
}
TEST_F(DepthCameraLayerTest, HasItsOwnLayerType)
{
EXPECT_EQ(layer.getType(), LayerType::DEPTH_CAMERA_LAYER);
EXPECT_NE(layer.getType(), LayerType::VOXEL_LAYER);
}
TEST_F(DepthCameraLayerTest, MatchSizeKeepsAndReMarksTheStoredPoints)
{
frame(object());
ASSERT_EQ(master(), LETHAL_OBSTACLE);
layer.matchSize(); // rebuilds the own grid from scratch
EXPECT_EQ(layer.storedPoints(), 9u);
EXPECT_EQ(master(), LETHAL_OBSTACLE); // re-marked without waiting for an update
}
TEST(DepthCameraLayerConfig, RejectsUnportedModeAndOutOfRangeValues)
{
tf3::BufferCore tf;