diff --git a/README.md b/README.md index 092ed6d..5bed9ce 100644 --- a/README.md +++ b/README.md @@ -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ỳ: diff --git a/include/robot_costmap_2d/depth_camera_obstacle_layer.h b/include/robot_costmap_2d/depth_camera_obstacle_layer.h index e989f4d..b09cfb8 100644 --- a/include/robot_costmap_2d/depth_camera_obstacle_layer.h +++ b/include/robot_costmap_2d/depth_camera_obstacle_layer.h @@ -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; diff --git a/include/robot_costmap_2d/layer.h b/include/robot_costmap_2d/layer.h index 066aded..ea4a8d9 100755 --- a/include/robot_costmap_2d/layer.h +++ b/include/robot_costmap_2d/layer.h @@ -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; diff --git a/plugins/depth_camera_obstacle_layer.cpp b/plugins/depth_camera_obstacle_layer.cpp index 27f6730..7537f7f 100644 --- a/plugins/depth_camera_obstacle_layer.cpp +++ b/plugins/depth_camera_obstacle_layer.cpp @@ -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 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 lock(*getMutex()); diff --git a/test/depth_camera_obstacle_layer_test.cpp b/test/depth_camera_obstacle_layer_test.cpp index 27114aa..0c44713 100644 --- a/test/depth_camera_obstacle_layer_test.cpp +++ b/test/depth_camera_obstacle_layer_test.cpp @@ -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;