costmap_queue.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2017, Locus Robotics
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 #ifndef COSTMAP_QUEUE_COSTMAP_QUEUE_H
00036 #define COSTMAP_QUEUE_COSTMAP_QUEUE_H
00037 
00038 #include <nav_core2/costmap.h>
00039 #include <costmap_queue/map_based_queue.h>
00040 #include <nav_grid/vector_nav_grid.h>
00041 #include <algorithm>
00042 #include <limits>
00043 #include <vector>
00044 
00045 namespace costmap_queue
00046 {
00051 class CellData
00052 {
00053 public:
00062   CellData(const double d, const unsigned int x, const unsigned int y, const unsigned int sx, const unsigned int sy) :
00063     distance_(d), x_(x), y_(y), src_x_(sx), src_y_(sy)
00064   {
00065   }
00066 
00070   CellData() :
00071     distance_(std::numeric_limits<double>::max()), x_(0), y_(0), src_x_(0), src_y_(0)
00072   {
00073   }
00074 
00075   double distance_;
00076   unsigned int x_, y_;
00077   unsigned int src_x_, src_y_;
00078 };
00079 
00099 class CostmapQueue : public MapBasedQueue<CellData>
00100 {
00101 public:
00107   explicit CostmapQueue(nav_core2::Costmap& costmap, bool manhattan = false);
00108 
00112   void reset() override;
00113 
00119   void enqueueCell(unsigned int x, unsigned int y);
00120 
00127   CellData getNextCell();
00128 
00132   virtual int getMaxDistance() const { return std::max(costmap_.getWidth(), costmap_.getHeight()); }
00133 
00139   virtual bool validCellToQueue(const CellData& cell) { return true; }
00140 
00144   using Ptr = std::shared_ptr<CostmapQueue>;
00145 protected:
00149   void enqueueCell(unsigned int cur_x, unsigned int cur_y, unsigned int src_x, unsigned int src_y);
00150 
00154   void computeCache();
00155 
00156   nav_core2::Costmap& costmap_;
00157 
00158   // This really should be VectorNavGrid<bool>, but since
00159   // vector<bool> is wacky, it would result in compile errors.
00160   nav_grid::VectorNavGrid<unsigned char> seen_;
00161   bool manhattan_;
00162 protected:
00177   inline double distanceLookup(const unsigned int cur_x, const unsigned int cur_y,
00178                                const unsigned int src_x, const unsigned int src_y)
00179   {
00180     unsigned int dx = std::abs(static_cast<int>(cur_x) - static_cast<int>(src_x));
00181     unsigned int dy = std::abs(static_cast<int>(cur_y) - static_cast<int>(src_y));
00182     return cached_distances_[dx][dy];
00183   }
00184   std::vector<std::vector<double> > cached_distances_;
00185   int cached_max_distance_;
00186 };
00187 }  // namespace costmap_queue
00188 
00189 #endif  // COSTMAP_QUEUE_COSTMAP_QUEUE_H


costmap_queue
Author(s):
autogenerated on Wed Jun 26 2019 20:09:33