costmap.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef NAV_CORE2_COSTMAP_H
36 #define NAV_CORE2_COSTMAP_H
37 
38 #include <nav_grid/nav_grid.h>
39 #include <nav_core2/common.h>
40 #include <nav_core2/bounds.h>
41 #include <boost/thread.hpp>
42 #include <memory>
43 #include <string>
44 
45 namespace nav_core2
46 {
47 
48 class Costmap : public nav_grid::NavGrid<unsigned char>
49 {
50 public:
51  static const unsigned char NO_INFORMATION = 255;
52  static const unsigned char LETHAL_OBSTACLE = 254;
53  static const unsigned char INSCRIBED_INFLATED_OBSTACLE = 253;
54  static const unsigned char FREE_SPACE = 0;
55 
56  using Ptr = std::shared_ptr<Costmap>;
57 
61  virtual ~Costmap() {}
62 
73  virtual void initialize(const ros::NodeHandle& parent, const std::string& name, TFListenerPtr tf) {}
74 
75  inline unsigned char getCost(const unsigned int x, const unsigned int y)
76  {
77  return getValue(x, y);
78  }
79 
80  inline unsigned char getCost(const nav_grid::Index& index)
81  {
82  return getValue(index.x, index.y);
83  }
84 
85  inline void setCost(const unsigned int x, const unsigned int y, const unsigned char cost)
86  {
87  setValue(x, y, cost);
88  }
89 
90  inline void setCost(const nav_grid::Index& index, const unsigned char cost)
91  {
92  setValue(index, cost);
93  }
94 
102  virtual void update() {}
103 
104  using mutex_t = boost::recursive_mutex;
108  virtual mutex_t* getMutex() = 0;
109 
113  virtual bool canTrackChanges() { return false; }
114 
138  virtual UIntBounds getChangeBounds(const std::string& ns)
139  {
140  if (!canTrackChanges())
141  {
142  throw std::runtime_error("You called 'getChangeBounds()' on a derived Costmap type that is not capable of "
143  "tracking changes (i.e. canTrackChanges() returns false). You shouldn't do that.");
144  }
145  else
146  {
147  throw std::runtime_error("You called 'getChangeBounds()' on a derived Costmap type that is capable of tracking "
148  "changes but has not properly implemented this function. You should yell at the author "
149  "of the derived Costmap.");
150  }
151  return UIntBounds();
152  }
153 };
154 } // namespace nav_core2
155 
156 #endif // NAV_CORE2_COSTMAP_H
virtual void setValue(const unsigned int x, const unsigned int y, const T &value)=0
static const unsigned char INSCRIBED_INFLATED_OBSTACLE
Definition: costmap.h:53
void setCost(const nav_grid::Index &index, const unsigned char cost)
Definition: costmap.h:90
void setCost(const unsigned int x, const unsigned int y, const unsigned char cost)
Definition: costmap.h:85
virtual T getValue(const unsigned int x, const unsigned int y) const =0
virtual UIntBounds getChangeBounds(const std::string &ns)
If canTrackChanges, get the bounding box for how much of the costmap has changed. ...
Definition: costmap.h:138
static const unsigned char NO_INFORMATION
Definition: costmap.h:51
unsigned char getCost(const unsigned int x, const unsigned int y)
Definition: costmap.h:75
unsigned char getCost(const nav_grid::Index &index)
Definition: costmap.h:80
boost::recursive_mutex mutex_t
Definition: costmap.h:104
virtual bool canTrackChanges()
Flag to indicate whether this costmap is able to track how much has changed.
Definition: costmap.h:113
virtual void initialize(const ros::NodeHandle &parent, const std::string &name, TFListenerPtr tf)
Initialization function for the Costmap.
Definition: costmap.h:73
std::shared_ptr< Costmap > Ptr
Definition: costmap.h:56
static const unsigned char LETHAL_OBSTACLE
Definition: costmap.h:52
std::shared_ptr< tf::TransformListener > TFListenerPtr
Definition: common.h:40
static const unsigned char FREE_SPACE
Definition: costmap.h:54
virtual void update()
Update the values in the costmap.
Definition: costmap.h:102
virtual mutex_t * getMutex()=0
Accessor for boost mutex.
virtual ~Costmap()
Virtual Destructor.
Definition: costmap.h:61


nav_core2
Author(s):
autogenerated on Sun Jan 10 2021 04:08:27