@@ -68,43 +68,41 @@ ompl::base::Cost ompl::geometric::AORRTC::bestCost() const
6868void ompl::geometric::AORRTC::setup ()
6969{
7070 Planner::setup ();
71- init_planner = std::make_shared<ompl::geometric::RRTConnect>(si_);
72- init_planner->setProblemDefinition (pdef_);
73- init_planner->setName (" Initial RRTConnect" );
74- init_planner->setRange (getRange ());
75- init_planner->setIntermediateStates (getIntermediateStates ());
7671
7772 aox_planner = std::make_shared<ompl::geometric::AOXRRTConnect>(si_);
7873 aox_planner->setProblemDefinition (pdef_);
7974 aox_planner->setName (" AOXRRTConnect" );
8075 aox_planner->setRange (getRange ());
8176 aox_planner->setIntermediateStates (getIntermediateStates ());
8277
83- init_planner->setup ();
8478 aox_planner->setup ();
8579
8680 psk_ = std::make_shared<PathSimplifier>(si_);
87-
8881 initCost_ = std::numeric_limits<double >::infinity ();
82+ solve_status = base::PlannerStatus::TIMEOUT;
83+ }
8984
85+ // Reset our planner to begin a new search
86+ void ompl::geometric::AORRTC::reset (bool solvedProblem)
87+ {
88+ aox_planner->clearQuery ();
89+ aox_planner->setFoundPath (nullptr );
90+ aox_planner->reset (solvedProblem);
9091 solve_status = base::PlannerStatus::TIMEOUT;
91- aox_solve_status = base::PlannerStatus::TIMEOUT;
9292}
9393
9494void ompl::geometric::AORRTC::setProblemDefinition (const base::ProblemDefinitionPtr &pdef)
9595{
9696 pdef_ = pdef;
9797
98- if (init_planner != nullptr )
98+ if (aox_planner != nullptr )
9999 {
100- init_planner->setProblemDefinition (pdef);
101100 aox_planner->setProblemDefinition (pdef);
102101 }
103102}
104103
105104void ompl::geometric::AORRTC::freeMemory ()
106105{
107- init_planner->clear ();
108106 aox_planner->clear ();
109107}
110108
@@ -126,21 +124,21 @@ ompl::base::PlannerStatus ompl::geometric::AORRTC::solve(const base::PlannerTerm
126124{
127125 do
128126 {
127+ // If we already have a solution (and therefore a reasonable cost range)
129128 if (pdef_->hasExactSolution ())
130129 {
130+ // Inform the planner about our cost bound
131131 aox_planner->setPathCost (bestCost_.value ());
132+
133+ // Try to solve the planning problem
134+ solve_status = aox_planner->solve (ptc);
132135
133- OMPL_INFORM (" %s: Best cost is %.5f" , getName ().c_str (), bestCost_);
134- aox_solve_status = aox_planner->solve (ptc);
135-
136- if (aox_solve_status != base::PlannerStatus::EXACT_SOLUTION)
137- {
138- OMPL_INFORM (" %s: Restarted before finding a solution" , getName ().c_str ());
139- }
140- else
136+ if (solve_status == base::PlannerStatus::EXACT_SOLUTION)
141137 {
138+ // If we found a solution, extract it and update our path
142139 const base::PathPtr path = aox_planner->getFoundPath ();
143140
141+ // Update our best path if our new path is better
144142 if (path->length () < bestCost_.value ())
145143 {
146144 bestPath_ = path;
@@ -149,34 +147,29 @@ ompl::base::PlannerStatus ompl::geometric::AORRTC::solve(const base::PlannerTerm
149147 pdef_->addSolutionPath (bestPath_, false , 0.0 , getName ());
150148 }
151149
150+ // Simplify our solution
152151 simplifySolution (path, ptc);
153- OMPL_INFORM (" %s: AOX search simplified to cost %.5f" , getName ().c_str (), path->length ());
154152
153+ // Again, update our best path if our new (simplified) path is better
155154 if (path->length () < bestCost_.value ())
156155 {
156+ OMPL_INFORM (" %s: AOX search simplified to cost %.5f" , getName ().c_str (), path->length ());
157+
157158 bestPath_ = path;
158159 bestCost_ = ompl::base::Cost (path->length ());
159160
160161 pdef_->addSolutionPath (bestPath_, false , 0.0 , getName ());
161162 }
162-
163- aox_planner->clearQuery ();
164- aox_planner->setProblemDefinition (pdef_);
165- }
166-
167- aox_planner->setFoundPath (nullptr );
168- aox_solve_status = base::PlannerStatus::TIMEOUT;
163+ }
169164 }
170165
166+ // Find an initial solution
171167 else
172168 {
173- solve_status = init_planner ->solve (ptc);
169+ solve_status = aox_planner ->solve (ptc);
174170
175- if (solve_status != base::PlannerStatus::EXACT_SOLUTION)
176- {
177- OMPL_INFORM (" %s: Initial search restarted before finding a solution" , getName ().c_str ());
178- }
179- else
171+ // If we found a solution, extract it and update our path
172+ if (solve_status == base::PlannerStatus::EXACT_SOLUTION)
180173 {
181174 initCost_ = pdef_->getSolutionPath ()->length ();
182175 bestPath_ = pdef_->getSolutionPath ();
@@ -192,19 +185,48 @@ ompl::base::PlannerStatus ompl::geometric::AORRTC::solve(const base::PlannerTerm
192185 pdef_->addSolutionPath (bestPath_, false , 0.0 , getName ());
193186 }
194187 }
188+
189+ // If we ran into errors, exit early
190+ if (solve_status == base::PlannerStatus::UNRECOGNIZED_GOAL_TYPE ||
191+ solve_status == base::PlannerStatus::INVALID_START ||
192+ solve_status == base::PlannerStatus::INVALID_GOAL)
193+ {
194+ return solve_status;
195+ }
196+
197+ // If we found a solution, we can reset our planner
198+ if (solve_status == base::PlannerStatus::EXACT_SOLUTION)
199+ {
200+ reset (true );
201+ }
202+
203+ // If we didn't find a solution on this iteration of solve, reset our planner.
204+ // (PDT visualize calls solve for each iteration of the search,
205+ // so we need to check if our planner actually needs to reset)
206+ else if (aox_planner->internalResetCondition ())
207+ {
208+ OMPL_INFORM (" %s: Restarted before finding a solution" , getName ().c_str ());
209+ reset (false );
210+ }
211+
212+ // Something has surely gone wrong if you have found a zero-length path
213+ if (bestCost_.value () == 0 )
214+ {
215+ OMPL_ERROR (" %s: Zero-length path found. May have a common start/goal." , getName ().c_str ());
216+ return base::PlannerStatus::INVALID_GOAL;
217+ }
195218 } while (!ptc);
196219
197- return solve_status;
220+ // Now that we're done, return whether or not we timed out
221+ if (pdef_->hasExactSolution ())
222+ {
223+ return base::PlannerStatus::EXACT_SOLUTION;
224+ } else {
225+ return base::PlannerStatus::TIMEOUT;
226+ }
198227}
199228
200229void ompl::geometric::AORRTC::getPlannerData (base::PlannerData &data) const
201230{
202- if (pdef_->hasExactSolution ())
203- {
204- aox_planner->getPlannerData (data);
205- }
206- else
207- {
208- init_planner->getPlannerData (data);
209- }
231+ aox_planner->getPlannerData (data);
210232}
0 commit comments