diff --git a/MotionPlanning/Planner/BiRrt.cpp b/MotionPlanning/Planner/BiRrt.cpp index aa8463b3d084a8d84e1c74f98c160f84edb6673c..e2e4d3537115ef703fbdc76ae5e75ca152c3552c 100644 --- a/MotionPlanning/Planner/BiRrt.cpp +++ b/MotionPlanning/Planner/BiRrt.cpp @@ -219,6 +219,15 @@ namespace Saba cycles++; switched = !switched; + clock_t currentClock = clock(); + + long diffClock = (long)(((float)(currentClock - startClock) / (float)CLOCKS_PER_SEC) * 1000.0); + if(diffClock > planningTimeout) + { + std::cout << "Encountered timeout of " << planningTimeout << " ms - aborting"; + return false; + } + } while (!stopSearch && cycles < maxCycles && !found); diff --git a/MotionPlanning/Planner/GraspIkRrt.cpp b/MotionPlanning/Planner/GraspIkRrt.cpp index 70e52661b0bdeb1f5f5d8145dd6636ef00bb515a..a8dab459a459d23e5755a3ee384cf259589430e5 100644 --- a/MotionPlanning/Planner/GraspIkRrt.cpp +++ b/MotionPlanning/Planner/GraspIkRrt.cpp @@ -228,6 +228,14 @@ namespace Saba } cycles++; + clock_t currentClock = clock(); + + long diffClock = (long)(((float)(currentClock - startClock) / (float)CLOCKS_PER_SEC) * 1000.0); + if(diffClock > planningTimeout) + { + std::cout << "Encountered timeout of " << planningTimeout << " ms - aborting"; + return false; + } } while (!stopSearch && cycles < maxCycles && !found); diff --git a/MotionPlanning/Planner/MotionPlanner.cpp b/MotionPlanning/Planner/MotionPlanner.cpp index 98ff9cf904dc79fa04ad3b8eb7285d750880c942..1ab96485ab94440e15ba758190c3d73775caafa3 100644 --- a/MotionPlanning/Planner/MotionPlanner.cpp +++ b/MotionPlanning/Planner/MotionPlanner.cpp @@ -22,6 +22,7 @@ namespace Saba planningTime = 0.0f; + planningTimeout = std::numeric_limits<float>::max(); stopSearch = false; maxCycles = 50000; // stop if cycles are exceeded @@ -168,6 +169,11 @@ namespace Saba return true; } + void MotionPlanner::setPlanningTimeout(float timeoutMs) + { + this->planningTimeout = timeoutMs; + } + void MotionPlanner::setMaxCycles(unsigned int mc) { maxCycles = mc; diff --git a/MotionPlanning/Planner/MotionPlanner.h b/MotionPlanning/Planner/MotionPlanner.h index 5d921a56618dcfd03ada833c2a02344c0895c47f..68c9359720b88a238c6a10e0f362dd4e5b4eb5a3 100644 --- a/MotionPlanning/Planner/MotionPlanner.h +++ b/MotionPlanning/Planner/MotionPlanner.h @@ -133,6 +133,8 @@ namespace Saba //! returns true, when start and goal config have been set virtual bool isInitialized(); + void setPlanningTimeout(float timeoutMs); + protected: //! create the solution @@ -155,6 +157,7 @@ namespace Saba std::string name; //!< Name of this planner (standard: "Motion Planner") float planningTime; //! Planning time in milliseconds + float planningTimeout; //! Timeout after which the planning aboits }; } diff --git a/MotionPlanning/Planner/Rrt.cpp b/MotionPlanning/Planner/Rrt.cpp index ad4dfc5d88709431ecaf3a862adc8f7943171be1..6c6eeb968527591129cfecc683afe767b0fd3a7f 100644 --- a/MotionPlanning/Planner/Rrt.cpp +++ b/MotionPlanning/Planner/Rrt.cpp @@ -186,6 +186,14 @@ namespace Saba } cycles++; + clock_t currentClock = clock(); + + long diffClock = (long)(((float)(currentClock - startClock) / (float)CLOCKS_PER_SEC) * 1000.0); + if(diffClock > planningTimeout) + { + std::cout << "Encountered timeout of " << planningTimeout << " ms - aborting"; + return false; + } } while (!stopSearch && cycles < maxCycles && !found);