diff --git a/include/RRT.hpp b/include/RRT.hpp index 70c728d..85e1b19 100644 --- a/include/RRT.hpp +++ b/include/RRT.hpp @@ -17,7 +17,10 @@ namespace rrt Utils::Point startPoint; Utils::Point endPoint; double stepLength; + double obstacleradius; std::deque > pathPoints; + std::vector > finalPath; + std::vector > ObstaclePoints; int maxIterations; std::vector< std::pair< Utils::Point, Utils::Point > > tree; std::vector< std::pair< Utils::Point, Utils::Point > > tree1; @@ -35,7 +38,7 @@ namespace rrt } virtual bool plan(); - virtual std::deque > getPointsOnPath(); + virtual std::vector > getPointsOnPath(); virtual void setEndPoints(Utils::Point start, Utils::Point end); virtual void setCheckPointFunction(bool (*f)(Utils::Point)); @@ -44,6 +47,7 @@ namespace rrt virtual void setHalfDimensions(double x,double y); virtual void setBiasParameter(unsigned int); virtual void setMaxIterations(int); + virtual void setObstacleRadius(int); //TODO : To be implemented in the derived classes // virtual void interpolate(); // virtual void fitVelocityProfile(); @@ -51,15 +55,16 @@ namespace rrt private: bool (*userCheck)(Utils::Point); - bool checkPoint(Utils::Point pt); + bool checkPoint(Utils::Point, Utils::Point); Utils::Point generatePoint(); Utils::Point generateBiasedPoint(int); - void growTree(Utils::Point); + void growTree(std::pair,int>,Utils::Point); std::pair, int> findClosestNode(Utils::Point); Utils::Point getParent(Utils::Point); std::pair ,Utils::Point > treeComplete(int*); void generatePath(Utils::Point first,Utils::Point last); double dist(Utils::Point a,Utils::Point b); + bool obstacle_here(int, int); }; } diff --git a/include/RRTConnect_implementation.hpp b/include/RRTConnect_implementation.hpp index fb15906..f9ffa4b 100644 --- a/include/RRTConnect_implementation.hpp +++ b/include/RRTConnect_implementation.hpp @@ -25,9 +25,24 @@ namespace rrt } template - std::deque > RRT::getPointsOnPath() + std::vector > RRT::getPointsOnPath() { - return pathPoints; + Utils::Point parent = pathPoints[0]; + finalPath.push_back(parent); + for (int i=1; i now = pathPoints[1]; + if(checkPoint(parent,now)!=true) + { + parent = pathPoints[i-1]; + i--; + if (i!=0) + finalPath.push_back(parent); + } + + } + finalPath.push_back(pathPoints[pathPoints.size()-1]); + return finalPath; } template @@ -42,6 +57,12 @@ namespace rrt maxIterations=value; } + template + void RRT::setObstacleRadius(int value) + { + obstacleradius=value; + } + template bool RRT:: plan() { @@ -50,9 +71,10 @@ namespace rrt int check=0; tree1.push_back(std::pair< Utils::Point, Utils::Point > (startPoint,startPoint)); tree2.push_back(std::pair< Utils::Point, Utils::Point > (endPoint,endPoint)); + std::pair < Utils::Point , int > both; while( check < maxIterations) { - //std::cout<<"In Planning Loop"< next; int flag[]={0}; std::pair , Utils::Point > mid = treeComplete(flag); @@ -68,24 +90,29 @@ namespace rrt } else if(count%biasParameter==0) { - //std::cout<<"Adding Next Biased Point to tree!!"<, Utils::Point > (next,parent)); else tree1.push_back( std::pair< Utils::Point, Utils::Point > (next,parent)); - //std::cout<<"Tree grown"< - bool RRT::checkPoint(Utils::Point next) + bool RRT::obstacle_here(int x, int y) { - return userCheck(next); + for (int i=0;i pratham; + pratham.x = x; pratham.y = y; + Utils::Point dwitiya; + dwitiya.x = ObstaclePoints[i].x; dwitiya.y = ObstaclePoints[i].y; + if (dist(pratham,dwitiya) + bool RRT::checkPoint(Utils::Point parent, Utils::Point next) + { + int x1=parent.x, x2=next.x, y1=parent.y,y2=next.y; + float x=x1, count; + try + { + // std::cout<<"\nIn try "; + // std::cout<1) count=1; + if (count<-1) count=-1; + if (x20 and x>=x2) || (count<0 and x<=x2)) + { + // std::cout<<"Return true from try\n"; + return true; + } + else + { + // std::cout<<"\nm is "<0 and y>=y2) || (count<0 and y<=y2)) + { + // std::cout<<"Return true from catch\n"; + return true; + } + if (obstacle_here(x,y)) + { + // std::cout<<"Return false from catch\n"; + return false; + } + } + } } template diff --git a/include/RRT_implementation.hpp b/include/RRT_implementation.hpp index 5e9bbd9..62423b3 100644 --- a/include/RRT_implementation.hpp +++ b/include/RRT_implementation.hpp @@ -25,9 +25,24 @@ namespace rrt } template - std::deque > RRT::getPointsOnPath() + std::vector > RRT::getPointsOnPath() { - return pathPoints; + Utils::Point parent = pathPoints[0]; + finalPath.push_back(parent); + for (int i=1; i now = pathPoints[1]; + if(checkPoint(parent,now)!=true) + { + parent = pathPoints[i-1]; + i--; + if (i!=0) + finalPath.push_back(parent); + } + + } + finalPath.push_back(pathPoints[pathPoints.size()-1]); + return finalPath; } template @@ -42,6 +57,12 @@ namespace rrt maxIterations=value; } + template + void RRT::setObstacleRadius(int value) + { + obstacleradius=value; + } + template bool RRT:: plan() { @@ -54,11 +75,14 @@ namespace rrt Utils::Point next; int arr[]={1}; std::pair ,Utils::Point > mid = treeComplete(arr); + std::pair ,int > both; + // Utils::Point both; if(mid.first!=mid.second) { std::cout<<"Tree complete!!"<, Utils::Point > (next,parent)); + tree.push_back( std::pair< Utils::Point, Utils::Point > (next,parent.first)); //std::cout<<"Tree grown"< - bool RRT::checkPoint(Utils::Point next) + bool RRT::obstacle_here(int x, int y) { - return userCheck(next); + for (int i=0;i pratham; + pratham.x = x; pratham.y = y; + Utils::Point dwitiya; + dwitiya.x = ObstaclePoints[i].x; dwitiya.y = ObstaclePoints[i].y; + if (dist(pratham,dwitiya) + bool RRT::checkPoint(Utils::Point parent, Utils::Point next) + { + int x1=parent.x, x2=next.x, y1=parent.y,y2=next.y; + float x=x1, count; + try + { + // std::cout<<"\nIn try "; + // std::cout<1) count=1; + if (count<-1) count=-1; + if (x20 and x>=x2) || (count<0 and x<=x2)) + { + // std::cout<<"Return true from try\n"; + return true; + } + else + { + // std::cout<<"\nm is "<0 and y>=y2) || (count<0 and y<=y2)) + { + // std::cout<<"Return true from catch\n"; + return true; + } + if (obstacle_here(x,y)) + { + // std::cout<<"Return false from catch\n"; + return false; + } + } + } } template diff --git a/src/main.cpp b/src/main.cpp index bc9d7da..07472ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,9 +30,10 @@ int main() test.setBiasParameter(100); test.setOrigin(origin); test.setMaxIterations(10000); + test.setObstacleRadius(50); test.plan(); cout<<"#################################################"< > path=test.getPointsOnPath(); + vector > path=test.getPointsOnPath(); for(int i=0;i > path=test.getPointsOnPath(); + vector > path=test.getPointsOnPath(); for(int i=0;i