MIRA
AbstractMetricPlanner.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Redistribution and modification of this code is strictly prohibited.
9  *
10  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
11  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
12  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
13  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
19  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
20  */
21 
30 #ifndef _MIRA_PILOT_ABSTRACTMETRICPLANNER_H_
31 #define _MIRA_PILOT_ABSTRACTMETRICPLANNER_H_
32 
33 #include <fw/Framework.h>
34 
35 #include <geometry/Polygon.h>
36 #include <maps/CostMap.h>
37 #include <maps/OccupancyGrid.h>
38 
39 #include <boost/shared_ptr.hpp>
40 
41 namespace mira { namespace pilot {
42 
44 
48 class AbstractMetricPlanner : public Object, public Authority
49 {
51 public:
52 
53  typedef std::vector<Point2f> Carrot;
54 
55 public:
56 
59 
60 public:
61 
62  void initialize(Authority* parent);
63 
64 protected:
65 
70  virtual void initialize() {}
71 
72 public:
73 
75  virtual Point2f getGradient(const Point2f& worldPos) const = 0;
76 
81  void update(const maps::CostMap& map);
82 
84  virtual void update(const maps::CostMap& map, const maps::DirtyRegions& dirty) = 0;
85 
87  virtual void setOnewayMap(const maps::OccupancyGrid& onewayMap) = 0;
88 
93  virtual double infinity() const = 0;
94 
101  virtual double getValue(const Point2f& worldPos, bool ignoreDoubleBuffer = false) const = 0;
102 
107  virtual double getValueFiltered(const Point2f& worldPos, bool ignoreDoubleBuffer = false) const = 0;
108 
114  virtual Carrot getCarrot(const Point2f& pos, int maxCount, float maxDistance = 1e10f) const = 0;
115 
121  virtual Pose2 getCurrentGoal(const Point2f& pos) const = 0;
122 
123 public:
124 
131  virtual Point2i world2map(const Point2f& p) const = 0;
132 
138  virtual Point2f map2world(const Point2i& p) const = 0;
139 
141  virtual float getCellSize() const = 0;
142 
144  virtual Rect2f getRegion() const = 0;
145 
147  virtual Rect2i getMapRegion() const = 0;
148 
150  virtual Duration getAccumulatedPlanningTime() const = 0;
151 
152 public:
153 
158  virtual void setRobotPosition(const Point2f& robotPos) {}
159 
171  virtual void setGoal(const Point2f& goal, float radius,
172  bool clearDoubleBuffer = true, bool prepareNew = true) = 0;
173 
180  virtual void setGoal(const Polygon2i& polygon, int radius = 1,
181  bool clearDoubleBuffer = true, bool prepareNew = true) = 0;
182 
186  virtual void setGoal(const Polygon2f& polygon, float radius = 0.1f,
187  bool clearDoubleBuffer = true, bool prepareNew = true) = 0;
188 
198  typedef std::function<float(int x, int y, float r)> CostFn;
199 
205  virtual void setGoal(const Polygon2i& polygon, int radius, CostFn& costFn,
206  bool clearDoubleBuffer = true, bool prepareNew = true) = 0;
207 
211  virtual void setGoal(const Polygon2f& polygon, float radius, CostFn& costFn,
212  bool clearDoubleBuffer = true, bool prepareNew = true) = 0;
213 
219  virtual bool hasValidGoal() const = 0;
220 
221 public:
222 
242  virtual void plan(const Point2f& pos, Duration plantime) = 0;
243 
248  virtual bool havePlan() const = 0;
249 
255  virtual bool havePlanSinceUpdate() const = 0;
256 
258  virtual Time lastValidPlan() const = 0;
259 
264  virtual bool haveWork() const = 0;
265 
270  virtual void planTime(Duration plantime) = 0;
271 
277  virtual void planSteps(int steps) = 0;
278 
283  virtual void planStep() = 0;
284 
286  virtual void resetPlanningTimeout() = 0;
287 
294  virtual maps::CostMap getNavFunction(bool ignoreDoubleBuffer = false) const = 0;
295 
296 public:
297 
299  virtual maps::GridMap<uint8,3> dumpNavStatus(bool useDoubleBuffer = false,
300  bool costsInGoalRegion = true) = 0;
301 
304 
305 public:
306 
308  enum Status
309  {
317  };
318 
320  virtual Status getStatus(const Point2f& p) const = 0;
321 };
322 
324 
325 typedef boost::shared_ptr<AbstractMetricPlanner> AbstractMetricPlannerPtr;
326 
327 }}
328 
329 #endif
virtual double getValue(const Point2f &worldPos, bool ignoreDoubleBuffer=false) const =0
Returns the cost value at position (in world coordinates) in the planner map.
virtual maps::CostMap getNavFunction(bool ignoreDoubleBuffer=false) const =0
Creates a deep copy of the navigation function that contains the accumulated costs from each cell to ...
virtual maps::GridMap< uint8, 3 > showNavFunctionNearGoal()=0
Create high-res image of navigation function in goal area (for user presentation, debugging)...
std::function< float(int x, int y, float r)> CostFn
Type declaration for a cost function to be used with setGoal(const Polygon2i, ...) or setGoal(const P...
Definition: AbstractMetricPlanner.h:198
virtual Pose2 getCurrentGoal(const Point2f &pos) const =0
Return the current goal point.
virtual Duration getAccumulatedPlanningTime() const =0
Get accumulated planning time since goal was set.
virtual void planTime(Duration plantime)=0
Low level planning interface.
Definition: AbstractMetricPlanner.h:311
Definition: AbstractMetricPlanner.h:315
virtual void plan(const Point2f &pos, Duration plantime)=0
High level planning interface.
virtual void initialize()
Called in initialize(parent).
Definition: AbstractMetricPlanner.h:70
virtual Point2f getGradient(const Point2f &worldPos) const =0
Returns the gradient for a position in world coordinates.
virtual void planStep()=0
Low level planning interface.
Interface for metric planners like Dijkstra and E*.
Definition: AbstractMetricPlanner.h:48
virtual Rect2i getMapRegion() const =0
Get planner map area (map coordinates)
Definition: AbstractMetricPlanner.h:314
std::vector< Point2f > Carrot
Definition: AbstractMetricPlanner.h:53
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
virtual void setGoal(const Point2f &goal, float radius, bool clearDoubleBuffer=true, bool prepareNew=true)=0
virtual double infinity() const =0
Returns the value that is returned by getValue() when cost values are not yet computed or are infinit...
virtual void setRobotPosition(const Point2f &robotPos)
Set the current robot position in planner (world position) Base implementation is empty...
Definition: AbstractMetricPlanner.h:158
virtual void resetPlanningTimeout()=0
Reset initial last plan time that is used for timeout.
boost::geometry::model::ring< Point2i > Polygon2i
virtual void setOnewayMap(const maps::OccupancyGrid &onewayMap)=0
Set a map describing oneway road restrictions.
Definition: AbstractMetricPlanner.h:312
virtual bool haveWork() const =0
Low level planning interface.
virtual void planSteps(int steps)=0
Low level planning interface.
virtual bool havePlanSinceUpdate() const =0
Returns if we have or have had a valid path to the set goal, after the cost map was updated...
virtual Point2f map2world(const Point2i &p) const =0
Convert a given point to world coordinates.
std::list< Rect2i > DirtyRegions
virtual bool havePlan() const =0
Returns if we have or have had a valid path to the set goal.
virtual double getValueFiltered(const Point2f &worldPos, bool ignoreDoubleBuffer=false) const =0
Returns the interpolated cost value at position (in world coordinates) in the planner map...
Definition: AbstractMetricPlanner.h:316
void update(const maps::CostMap &map)
Update the planning context with the current costmap (entire area).
virtual ~AbstractMetricPlanner()
Definition: AbstractMetricPlanner.h:58
virtual float getCellSize() const =0
Get planner map cell size.
virtual bool hasValidGoal() const =0
Check if the internal planner has a goal.
boost::geometry::model::ring< Point2f > Polygon2f
virtual Rect2f getRegion() const =0
Get planner map area (world coordinates)
Status
Planner status of a fixed position (planner map cell)
Definition: AbstractMetricPlanner.h:308
boost::shared_ptr< AbstractMetricPlanner > AbstractMetricPlannerPtr
Definition: AbstractMetricPlanner.h:325
virtual Time lastValidPlan() const =0
Return last time a valid plan existed.
Definition: AbstractMetricPlanner.h:310
Status::StatusMode getStatus() const
virtual Carrot getCarrot(const Point2f &pos, int maxCount, float maxDistance=1e10f) const =0
Return the optimal path to the goal, starting at pos.
Definition: AbstractMetricPlanner.h:313
virtual Point2i world2map(const Point2f &p) const =0
Convert a given point to integer map coordinates.
virtual maps::GridMap< uint8, 3 > dumpNavStatus(bool useDoubleBuffer=false, bool costsInGoalRegion=true)=0
Create a color image of the navigation function (for user presentation, debugging).