refactor(depth): DepthCameraObstacleLayer follows the CostmapLayer contract
The port wrote LETHAL straight into the master from its stored 3D points and left its own grid empty, as costmap_depth_camera does. Everything CostmapLayer offers on top of the own grid therefore missed the layer: clearArea() (the ClearCostmapRecovery path), reset() (Costmap2DROBOT::resetLayers()), footprint clearing and combination_method all acted on an empty grid, and the next cycle wrote the ghosts back. Cleared cells also stayed on the master until another layer's bounds covered them (the source's B7). The stored points stay the source of truth; the clearing and marking algorithm is unchanged. The own grid now mirrors them cell by cell, the way VoxelLayer keeps a voxel grid next to its 2D grid: - marking sets the column's cell LETHAL, the last point of a column leaving sets it FREE_SPACE, and both touch the bounds, so a cleared cell leaves the master in the same cycle (clear_touches_bounds is gone, always on); - updateCosts() only merges the own grid with combination_method, like ObstacleLayer; combination_method other than 0/1 now means "no effect"; - reset() drops the stored points and buffered observations; - clearArea() follows CostmapLayer::clearArea(): invert_area false clears outside the box and keeps the inside, true clears the inside; - footprint clearing erases the stored columns under the robot; - markings that leave the window are dropped in updateBounds() (B6), and a column whose cell went missing is re-marked; - the layer mutex guards the point map, since ClearCostmapRecovery and resetLayers() reach it from other threads (recursive mutex, held by the recovery around clearArea()). Tests: the two clear_touches_bounds cases become one bounded-update case, and clearArea (both directions), reset and footprint clearing get their own.
This commit is contained in:
@@ -3,17 +3,23 @@
|
||||
* https://github.com/tsengapola/costmap_depth_camera, noetic branch 59b7737,
|
||||
* onto robot_costmap_2d (boost::dll, robot::NodeHandle, tf3).
|
||||
*
|
||||
* The algorithm is kept as in the source on purpose, so that it can be compared
|
||||
* A/B against VoxelLayer on the same robot. Only what the host forces is changed:
|
||||
* - data arrives through handleImpl() instead of a ROS subscriber, and the cloud
|
||||
* is processed in updateBounds() once TF at its stamp exists (the role of the
|
||||
* tf2_ros::MessageFilter in the source);
|
||||
* - getType() is VOXEL_LAYER, the only type SensorGateway feeds sensor data to;
|
||||
* - no debug publishers and no dynamic_reconfigure (no ROS inside the core);
|
||||
* - `sensor_frame_is_optical` builds the frustum in a Z-forward optical frame,
|
||||
* because this robot's TF has no X-forward camera_link;
|
||||
* - B6: markings that left the rolling window are dropped instead of kept forever.
|
||||
* `clear_touches_bounds` (B7) is an optional fix, off by default as in the source.
|
||||
* The clearing and marking algorithm is the source's (kd-tree "seen again" test inside the
|
||||
* frustums, Euclidean clusters away from the frustum faces). How the result reaches the costmap
|
||||
* follows the CostmapLayer contract of ObstacleLayer/VoxelLayer instead of the source, which
|
||||
* wrote LETHAL straight into the master and left its own grid empty:
|
||||
* - the stored 3D points (pc_3d_map_global_) stay the source of truth, and this layer's own
|
||||
* grid mirrors them cell by cell: a column with points is LETHAL, a column that loses its
|
||||
* last point becomes FREE_SPACE, and every such change touches the update bounds, so a
|
||||
* cleared cell leaves the master in the same cycle (the source's B7);
|
||||
* - updateCosts() only merges the own grid (combination_method), like ObstacleLayer;
|
||||
* - reset(), clearArea() and footprint clearing also erase the stored points, so
|
||||
* Costmap2DROBOT::resetLayers() and ClearCostmapRecovery work on this layer (the source's
|
||||
* 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
|
||||
* optical frame; markings that leave the rolling window are dropped (B6).
|
||||
*********************************************************************/
|
||||
#ifndef ROBOT_COSTMAP_2D_DEPTH_CAMERA_OBSTACLE_LAYER_H_
|
||||
#define ROBOT_COSTMAP_2D_DEPTH_CAMERA_OBSTACLE_LAYER_H_
|
||||
@@ -92,8 +98,18 @@ public:
|
||||
void updateCosts(Costmap2D& master_grid, int min_i, int min_j, int max_i, int max_j) override;
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
/// Drops the stored points and the buffered observations as well as the own grid.
|
||||
void reset() override;
|
||||
|
||||
/**
|
||||
* @brief Same contract as CostmapLayer::clearArea(), applied to the stored points too.
|
||||
*
|
||||
* Cells strictly inside (start, end) are kept and the rest is cleared when invert_area is
|
||||
* false; invert_area true clears the inside instead. Called by ClearCostmapRecovery with the
|
||||
* layer mutex held (recursive).
|
||||
*/
|
||||
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.
|
||||
LayerType getType() const override
|
||||
{
|
||||
@@ -155,6 +171,14 @@ private:
|
||||
void updateFootprint(double robot_x, double robot_y, double robot_yaw, double* min_x,
|
||||
double* min_y, double* max_x, double* max_y);
|
||||
bool isValid(int mx, int my) const;
|
||||
/// Own-grid cell of a stored column; false when it is outside the window or on its edge.
|
||||
bool columnCell(const std::pair<int, int>& column, unsigned int& mx, unsigned int& my) const;
|
||||
/// Drops columns that left the window (B6), frees edge cells, re-marks cells a column lost.
|
||||
void dropColumnsOutsideWindow(double* min_x, double* min_y, double* max_x, double* max_y);
|
||||
/// The column became empty: erase it, free its own-grid cell and touch the bounds.
|
||||
std::map<std::pair<int, int>, std::map<int, float>>::iterator eraseColumn(
|
||||
std::map<std::pair<int, int>, std::map<int, float>>::iterator it, double* min_x, double* min_y,
|
||||
double* max_x, double* max_y);
|
||||
void logStats();
|
||||
|
||||
// (int)(x / res) toward zero and back to the cell corner, exactly as the source stores points.
|
||||
@@ -191,7 +215,6 @@ private:
|
||||
double marking_height_above_ground_ = -100.0;
|
||||
|
||||
// Additions of this port.
|
||||
bool clear_touches_bounds_ = false; ///< B7 fix: a cleared point also resets its master cell
|
||||
bool debug_stats_ = true; ///< debug/stats: periodic counters log
|
||||
double debug_stats_period_ = 5.0; ///< [s]
|
||||
|
||||
@@ -205,6 +228,7 @@ private:
|
||||
std::size_t cloud_points = 0;
|
||||
std::size_t marked = 0;
|
||||
std::size_t cleared = 0;
|
||||
std::size_t footprint_cleared = 0; ///< columns erased under the robot footprint
|
||||
std::size_t cleared_all_frames = 0;
|
||||
std::size_t bypassed_frames = 0;
|
||||
std::size_t tf_waits = 0;
|
||||
|
||||
Reference in New Issue
Block a user