diff --git a/include/RRTConnect_implementation.hpp b/include/RRTConnect_implementation.hpp index 0e8f6b9..f9ffa4b 100644 --- a/include/RRTConnect_implementation.hpp +++ b/include/RRTConnect_implementation.hpp @@ -29,7 +29,6 @@ namespace rrt { Utils::Point parent = pathPoints[0]; finalPath.push_back(parent); - int start=0; for (int i=1; i now = pathPoints[1]; @@ -249,7 +248,6 @@ namespace rrt template 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 diff --git a/include/RRT_implementation.hpp b/include/RRT_implementation.hpp index a07b128..62423b3 100644 --- a/include/RRT_implementation.hpp +++ b/include/RRT_implementation.hpp @@ -27,6 +27,21 @@ namespace rrt template std::vector > RRT::getPointsOnPath() { + 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; } @@ -80,7 +95,7 @@ namespace rrt do{ next= generateBiasedPoint(1); both= findClosestNode(next); - }while(checkPoint(next, next)!=true); + }while(checkPoint(both.first, next)!=true); //std::cout<<" : "< - bool RRT::checkPoint(Utils::Point first, 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 @@ -215,12 +306,12 @@ namespace rrt void RRT::generatePath(Utils::Point first,Utils::Point last) { Utils::Point cur=last; - finalPath.push_back(cur); + pathPoints.push_back(cur); while(cur!=first || cur!=startPoint) { Utils::Point parent= getParent(cur); //std::cout<<"current : "< > path=test.getPointsOnPath();