fix(costmap_2d): draw StaticLayer-family layers correctly in rolling costmaps
In a rolling (local) costmap the StaticLayer extent is in map_frame_, so the bounds it reported did not cover the moving master window and zone layers (forbidden, preferred, unpreferred, critical) were not redrawn as the robot moved. - StaticLayer::updateBounds: when the costmap is rolling, expand the bounds to the whole master window every cycle. - StaticLayer::updateCosts: skip when disabled; the transformed path uses the master grid passed in and the same merge policy as the aligned path. - CostmapLayer::mergeCost: one merge rule for aligned and transformed grids. NO_INFORMATION in the layer keeps the master cell; CRITICAL_SPACE always wins; PREFERRED/UNPREFERRED only below INSCRIBED_INFLATED_OBSTACLE; otherwise max. updateWithMax and updateWithOverwrite keep their previous results. - CriticalLayer::updateCosts delegates to StaticLayer::updateCosts, so it is rolling-aware too. - Test: rolling_static_layer_test, 7 cases. Tests on dev: rolling_static_layer_test 7/7, test_costmap 9/9, costmap_common_root_test 4/4 (rooted and flat). directional_layer_test InvalidMaxDeviationThrows still fails: it checks directional_layer.cpp initialization, which this change does not touch.
This commit is contained in:
@@ -425,6 +425,18 @@ void StaticLayer::updateBounds(double robot_x, double robot_y, double robot_yaw,
|
||||
|
||||
useExtraBounds(min_x, min_y, max_x, max_y);
|
||||
|
||||
if (layered_costmap_->isRolling())
|
||||
{
|
||||
// The layer extent is in map_frame_; redraw the moving window in the master frame.
|
||||
const Costmap2D& master = *layered_costmap_->getCostmap();
|
||||
*min_x = std::min(*min_x, master.getOriginX());
|
||||
*min_y = std::min(*min_y, master.getOriginY());
|
||||
*max_x = std::max(*max_x, master.getOriginX() + master.getSizeInCellsX() * master.getResolution());
|
||||
*max_y = std::max(*max_y, master.getOriginY() + master.getSizeInCellsY() * master.getResolution());
|
||||
has_updated_data_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
double wx, wy;
|
||||
|
||||
mapToWorld(x_, y_, wx, wy);
|
||||
@@ -440,7 +452,7 @@ void StaticLayer::updateBounds(double robot_x, double robot_y, double robot_yaw,
|
||||
|
||||
void StaticLayer::updateCosts(robot_costmap_2d::Costmap2D& master_grid, int min_i, int min_j, int max_i, int max_j)
|
||||
{
|
||||
if (!map_received_)
|
||||
if (!map_received_ || !enabled_)
|
||||
return;
|
||||
|
||||
if (!layered_costmap_->isRolling())
|
||||
@@ -478,17 +490,14 @@ void StaticLayer::updateCosts(robot_costmap_2d::Costmap2D& master_grid, int min_
|
||||
for (unsigned int j = min_j; j < max_j; ++j)
|
||||
{
|
||||
// Convert master_grid coordinates (i,j) into global_frame_(wx,wy) coordinates
|
||||
layered_costmap_->getCostmap()->mapToWorld(i, j, wx, wy);
|
||||
master_grid.mapToWorld(i, j, wx, wy);
|
||||
// Transform from global_frame_ to map_frame_
|
||||
tf3::Vector3 p(wx, wy, 0);
|
||||
p = tf3_transform*p;
|
||||
// Set master_grid with cell from map
|
||||
if (worldToMap(p.x(), p.y(), mx, my))
|
||||
{
|
||||
if (!use_maximum_)
|
||||
master_grid.setCost(i, j, getCost(mx, my));
|
||||
else
|
||||
master_grid.setCost(i, j, std::max(getCost(mx, my), master_grid.getCost(i, j)));
|
||||
master_grid.setCost(i, j, mergeCost(master_grid.getCost(i, j), getCost(mx, my), use_maximum_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user