这是costmap_2d的最后一个重要的类了。InflationLayer
本身不存储map数据,所以所谓的地图层的概念,仅仅指的是一种对地图的操作,并不是数据层面的地图。
首先来看一个数据结构,知道有这个东西就行了:
class CellData
{
public:
CellData(double d, double i, unsigned int x, unsigned int y, unsigned int sx, unsigned int sy) :
distance_(d), index_(i), x_(x), y_(y), src_x_(sx), src_y_(sy)
{
}
double distance_;//
unsigned int index_;//this cell在map的一维索引
unsigned int x_, y_;//this cell在map的x,y二维索引
unsigned int src_x_, src_y_;//this cell距离最近的障碍物点,这个障碍物cell的x,y二维索引
};
//对应的class CellData的比较操作,用于priority queue操作
inline bool operator<(const CellData &a, const CellData &b)
{
return a.distance_ > b.distance_;
}
函数onInitialize
配置了动态参数服务的回调函数,然后在最后一行调用了matchSize
:
void InflationLayer::matchSize()
{
boost::unique_lock < boost::recursive_mutex > lock(*inflation_access_);
costmap_2d::Costmap2D* costmap = layered_costmap_->getCostmap();
resolution_ = costmap->getResolution();
cell_inflation_radius_ = cellDistance(inflation_radius_);
computeCaches();//这个函数通过cell_inflation_radius_计算了两个buffer,这两个二维buffer直接存储了[i,j]的distance 和cost
unsigned int size_x = costmap->getSizeInCellsX(), size_y = costmap->getSizeInCellsY();
if (seen_)
delete