KrisLibrary  1.0.0
MotionPlanner.h
1 #ifndef ROBOTICS_MOTION_PLANNER_H
2 #define ROBOTICS_MOTION_PLANNER_H
3 
4 #include <KrisLibrary/graph/Tree.h>
5 #include <KrisLibrary/graph/UndirectedGraph.h>
6 #include <KrisLibrary/graph/ConnectedComponents.h>
7 #include <vector>
8 #include <list>
9 #include "CSpace.h"
10 #include "EdgePlanner.h"
11 #include "Path.h"
12 
13 class PointLocationBase;
15 
16 
25 {
26 public:
28 
30  virtual ~RoadmapPlanner();
31 
32  virtual void Cleanup();
33  virtual void GenerateConfig(Config& x);
34  virtual int AddMilestone(const Config& x);
35  virtual int TestAndAddMilestone(const Config& x);
36  virtual void ConnectEdge(int i,int j,const EdgePlannerPtr& e);
37  virtual EdgePlannerPtr TestAndConnectEdge(int i,int j);
38  virtual bool HasEdge(int i,int j) { return roadmap.FindEdge(i,j)!=NULL; }
39  virtual EdgePlannerPtr GetEdge(int i,int j) { return *roadmap.FindEdge(i,j); }
40  virtual bool AreConnected(int i,int j) { return ccs.SameComponent(i,j); }
41  virtual bool AreConnected(int i,int j) const { return ccs.SameComponent(i,j); }
42  virtual void ConnectToNeighbors(int i,Real connectionThreshold,bool ccReject=true);
43  virtual void ConnectToNearestNeighbors(int i,int k,bool ccReject=true);
44  virtual void Generate(int numSamples,Real connectionThreshold);
46  virtual void CreatePath(int i,int j,MilestonePath& path);
49  virtual Real OptimizePath(int i,const std::vector<int>& goals,ObjectiveFunctionalBase* cost,MilestonePath& path);
50 
51  CSpace* space;
52  Roadmap roadmap;
54  std::shared_ptr<PointLocationBase> pointLocator;
55 };
56 
57 
67 {
68 public:
69  struct Milestone
70  {
71  Config x;
72  int id;
73  int connectedComponent;
74  };
75 
77 
79  virtual ~TreeRoadmapPlanner();
80 
81  virtual void GenerateConfig(Config& x);
82  virtual Node* AddMilestone(const Config& x);
83  virtual Node* TestAndAddMilestone(const Config& x);
84  virtual Node* AddInfeasibleMilestone(const Config& x) { return NULL; }
85  virtual Node* Extend();
86  virtual void Cleanup();
87  virtual void ConnectToNeighbors(Node*);
88  virtual EdgePlannerPtr TryConnect(Node*,Node*);
89  virtual void DeleteSubtree(Node* n);
90  //helpers
91  //default implementation uses pointLocator
92  virtual Node* ClosestMilestone(const Config& x);
93  virtual int ClosestMilestoneIndex(const Config& x);
94  //default implementation uses O(n) search
95  virtual Node* ClosestMilestoneInComponent(int component,const Config& x);
96  virtual Node* ClosestMilestoneInSubtree(Node* node,const Config& x);
97  Node* Extend(Node* n,const Config& x);
98  Node* TryExtend(Node* n,const Config& x);
99  void AttachChild(Node* p, Node* c, const EdgePlannerPtr& e); //c will become a child of p
100  Node* SplitEdge(Node* p,Node* n,Real u);
102  void CreatePath(Node* a, Node* b, MilestonePath& path);
107  virtual Real OptimizePath(Node* a,const std::vector<Node*>& goals,ObjectiveFunctionalBase* cost,MilestonePath& path);
108 
109  CSpace* space;
110  std::vector<Node*> connectedComponents;
111  Real connectionThreshold;
112 
113  //temporary
114  std::vector<Vector> milestoneConfigs;
115  std::vector<Node*> milestones;
116  std::shared_ptr<PointLocationBase> pointLocator;
117  Config x;
118 };
119 
120 
130 {
131 public:
133  virtual void GenerateConfig(Config& x);
134  virtual Node* AddMilestone(const Config& x);
135  virtual void Cleanup();
136 
137  //overrideable
138  virtual Node* SelectMilestone(const std::vector<Node*>& milestones);
139 
141  Real delta;
143  std::vector<Real> weights;
144 };
145 
154 {
155 public:
156  RRTPlanner(CSpace*s);
157  virtual Node* Extend();
158 
159  Real delta;
160 };
161 
172 {
173 public:
176  void Init(const Config& start, const Config& goal);
178  bool Plan();
180  void CreatePath(MilestonePath&) const;
181 };
182 
183 /*
184 class VisibilityPRM : public RandomizedPlanner
185 {
186 public:
187  VisibilityPRM(CSpace*s);
188  //may return NULL for rejected config
189  virtual Node* AddMilestone(const Config& x);
190  virtual Node* AddInfeasibleMilestone(const Config& x) { return NULL; }
191  virtual Node* Extend();
192  virtual Node* CanConnectComponent(int i,const Config& x);
193 };
194 */
195 
196 #endif
Definition: ConnectedComponents.h:9
A base class to be used for tree-based roadmap planners.
Definition: MotionPlanner.h:66
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
A sequence of locally planned paths between milestones.
Definition: planning/Path.h:18
A uniform abstract interface to point location data structures. The point locator operators in-place ...
Definition: PointLocation.h:14
virtual void CreatePath(int i, int j, MilestonePath &path)
Creates the shortest path from i to j. These MUST be in the same connected component.
Definition: MotionPlanner.cpp:216
A tree-based randomized planner that extends the roadmap by sampling the neighborhood of existing sam...
Definition: MotionPlanner.h:129
A tree graph structure, represented directly at the node level.
Definition: Tree.h:25
A base roadmap planner class.
Definition: MotionPlanner.h:24
Definition: MotionPlanner.h:69
Real delta
Neighborhood distance.
Definition: MotionPlanner.h:141
A single-query RRT (Rapidly-Exploring Random Tree) planner.
Definition: MotionPlanner.h:171
std::vector< Real > weights
Node selection weights.
Definition: MotionPlanner.h:143
virtual Real OptimizePath(int i, const std::vector< int > &goals, ObjectiveFunctionalBase *cost, MilestonePath &path)
Definition: MotionPlanner.cpp:267
A basic RRT (Rapidly-Exploring Random Tree) planner.
Definition: MotionPlanner.h:153
A base class for objective functionals of the form J[x,u] = sum_0^N-1 L(xi,ui) dt + Phi(xN) ...
Definition: Objective.h:18