KrisLibrary  1.0.0
EdgePlanner.h
1 #ifndef ROBOTICS_EDGE_PLANNER_H
2 #define ROBOTICS_EDGE_PLANNER_H
3 
4 #include "CSpace.h"
5 #include "Interpolator.h"
6 #include <memory>
7 #include <list>
8 #include <queue>
9 
49 class EdgePlanner : public Interpolator
50 {
51 public:
52  EdgePlanner() {}
53  virtual ~EdgePlanner() {}
54  virtual bool IsVisible() =0;
55  virtual CSpace* Space() const =0;
56  virtual std::shared_ptr<EdgePlanner> Copy() const=0;
57  virtual std::shared_ptr<EdgePlanner> ReverseCopy() const=0;
58 
59  //for incremental planners
60  virtual bool IsIncremental() const { return false; }
61  virtual Real Priority() const { abort(); return 0; }
62  virtual bool Plan() { abort(); return false; }
63  virtual bool Done() const { abort(); return false; }
64  virtual bool Failed() const { abort(); return false; }
65 };
66 
67 typedef std::shared_ptr<EdgePlanner> EdgePlannerPtr;
68 
73 class EdgeChecker : public EdgePlanner
74 {
75 public:
76  EdgeChecker(CSpace* space,const InterpolatorPtr& path);
77  EdgeChecker(CSpace* space,const Config& a,const Config& b);
78  virtual ~EdgeChecker() {}
79  virtual void Eval(Real u,Config& x) const { path->Eval(u,x); }
80  virtual Real Length() const { return path->Length(); }
81  virtual const Config& Start() const { return path->Start(); }
82  virtual const Config& End() const { return path->End(); }
83  virtual CSpace* Space() const { return space; }
84 
85  CSpace* space;
86  InterpolatorPtr path;
87 };
88 
89 typedef std::shared_ptr<EdgeChecker> EdgeCheckerPtr;
90 
91 
96 {
97 public:
98  EpsilonEdgeChecker(CSpace* space,const InterpolatorPtr& path,Real epsilon);
99  EpsilonEdgeChecker(CSpace* space,const Config& a,const Config& b,Real epsilon);
100  virtual bool IsVisible();
101  virtual EdgePlannerPtr Copy() const;
102  virtual EdgePlannerPtr ReverseCopy() const;
103  virtual bool IsIncremental() const { return true; }
104  virtual Real Priority() const;
105  virtual bool Plan();
106  virtual bool Done() const;
107  virtual bool Failed() const;
108 
109  Real epsilon;
110 
111 protected:
112  bool foundInfeasible;
113  Real dist;
114  int depth;
115  int segs;
116  Config m;
117 };
118 
124 {
125 public:
126  ObstacleDistanceEdgeChecker(CSpace* space,const InterpolatorPtr& path);
127  ObstacleDistanceEdgeChecker(CSpace* space,const Config& a, const Config& b);
128  virtual bool IsVisible();
129  virtual EdgePlannerPtr Copy() const;
130  virtual EdgePlannerPtr ReverseCopy() const;
131 
132  bool CheckVisibility(Real ua,Real ub,const Config& a,const Config& b,Real da,Real db);
133 };
134 
144 {
145 public:
146  BisectionEpsilonEdgePlanner(CSpace* space,const Config& a,const Config& b,Real epsilon);
147  virtual ~BisectionEpsilonEdgePlanner() {}
148  virtual bool IsVisible();
149  virtual void Eval(Real u,Config& x) const;
150  virtual Real Length() const;
151  virtual const Config& Start() const;
152  virtual const Config& End() const;
153  virtual CSpace* Space() const { return space; }
154  virtual EdgePlannerPtr Copy() const;
155  virtual EdgePlannerPtr ReverseCopy() const;
156  virtual bool IsIncremental() const { return true; }
157  virtual Real Priority() const;
158  virtual bool Plan();
159  virtual bool Done() const;
160  virtual bool Failed() const;
161  //on failure, returns the segment last checked
162  bool Plan(Config*& pre,Config*& post);
163 
164  const std::list<Config>& GetPath() const { return path; }
165  const Config& InfeasibleConfig() const { return x; }
166 
167 protected:
168  BisectionEpsilonEdgePlanner(CSpace* space,Real epsilon);
169 
170  CSpace* space;
171  std::list<Config> path;
172  Real epsilon;
173 
174  struct Segment
175  {
176  inline bool operator < (const Segment& s) const { return length<s.length; }
177 
178  std::list<Config>::iterator prev;
179  Real length;
180  };
181 
182  std::priority_queue<Segment,std::vector<Segment> > q;
183  Config x;
184 };
185 
186 
188 inline EdgePlannerPtr IsVisible(CSpace* w,const Config& a,const Config& b)
189 {
190  EdgePlannerPtr e=w->LocalPlanner(a,b);
191  if(e->IsVisible()) return e;
192  return EdgePlannerPtr();
193 }
194 
195 #endif
Edge checker that divides the path until epsilon resolution is reached.
Definition: EdgePlanner.h:95
Vector Config
an alias for Vector
Definition: RobotKinematics3D.h:14
Motion planning configuration space base class. The configuration space implements an interpolation s...
Definition: CSpace.h:39
Abstract base class for an edge planner / edge checker (i.e., local planner).
Definition: EdgePlanner.h:49
An EdgePlanner that just checks a given interpolator or straight line path between two configurations...
Definition: EdgePlanner.h:73
Edge checker that divides the path until the segment distance is below CSpace.ObstacleDistance() ...
Definition: EdgePlanner.h:123
Definition: EdgePlanner.h:174
A base class for all 1D interpolators.
Definition: Interpolator.h:10
Definition: EdgePlanner.h:143