34 #include "costmap_queue/costmap_queue.hpp"
41 namespace costmap_queue
45 :
MapBasedQueue(), costmap_(costmap), max_distance_(-1), manhattan_(manhattan),
46 cached_max_distance_(-1)
54 if (seen_.size() != size_x * size_y) {
55 seen_.resize(size_x * size_y);
57 std::fill(seen_.begin(), seen_.end(),
false);
64 unsigned int index = costmap_.
getIndex(x, y);
69 unsigned int index,
unsigned int cur_x,
unsigned int cur_y,
70 unsigned int src_x,
unsigned int src_y)
72 if (seen_[index]) {
return;}
77 CellData data(distance, index, cur_x, cur_y, src_x, src_y);
90 unsigned int index = current_cell.index_;
91 unsigned int mx = current_cell.x_;
92 unsigned int my = current_cell.y_;
93 unsigned int sx = current_cell.src_x_;
94 unsigned int sy = current_cell.src_y_;
104 if (mx < size_x - 1) {
116 if (max_distance_ == -1) {
119 if (max_distance_ == cached_max_distance_) {
return;}
120 cached_distances_.clear();
122 cached_distances_.resize(max_distance_ + 2);
124 for (
unsigned int i = 0; i < cached_distances_.size(); ++i) {
125 cached_distances_[i].resize(max_distance_ + 2);
126 for (
unsigned int j = 0; j < cached_distances_[i].size(); ++j) {
128 cached_distances_[i][j] = i + j;
130 cached_distances_[i][j] = hypot(i, j);
134 cached_max_distance_ = max_distance_;
Storage for cell information used during queue expansion.
double distanceLookup(const unsigned int cur_x, const unsigned int cur_y, const unsigned int src_x, const unsigned int src_y)
Lookup pre-computed distances.
void enqueueCell(unsigned int x, unsigned int y)
Add a cell the queue.
CellData getNextCell()
Get the next cell to examine, and enqueue its neighbors as needed.
void reset() override
Clear the queue.
void computeCache()
Compute the cached distances.
CostmapQueue(nav2_costmap_2d::Costmap2D &costmap, bool manhattan=false)
constructor
virtual bool validCellToQueue(const CellData &)
Check to see if we should add this cell to the queue. Always true unless overridden.
Templatized interface for a priority queue.
virtual void reset()
Clear the queue.
CellData & front()
Return the item at the front of the queue.
void enqueue(const double priority, CellData item)
Add a new item to the queue with a set priority.
void pop()
Remove (and destroy) the item at the front of the queue.
A 2D costmap provides a mapping between points in the world and their associated "costs".
unsigned int getIndex(unsigned int mx, unsigned int my) const
Given two map coordinates... compute the associated index.
unsigned int getSizeInCellsX() const
Accessor for the x size of the costmap in cells.
unsigned int getSizeInCellsY() const
Accessor for the y size of the costmap in cells.