@@ -246,30 +246,37 @@ void Task::compute() {
246246 stages ()->pimpl ()->runCompute ();
247247}
248248
249- bool Task::plan (size_t max_solutions) {
249+ moveit::core::MoveItErrorCode Task::plan (size_t max_solutions) {
250250 auto impl = pimpl ();
251251 init ();
252252
253+ // Print state and return success if there are solutions otherwise the input error_code
254+ const auto success_or = [this ](const int32_t error_code) {
255+ printState ();
256+ return numSolutions () > 0 ? moveit::core::MoveItErrorCode::SUCCESS : error_code;
257+ };
253258 impl->preempt_requested_ = false ;
254259 const double available_time = timeout ();
255260 const auto start_time = std::chrono::steady_clock::now ();
256- while (!impl->preempt_requested_ && canCompute () && (max_solutions == 0 || numSolutions () < max_solutions) &&
257- std::chrono::duration<double >(std::chrono::steady_clock::now () - start_time).count () < available_time) {
261+ while (canCompute () && (max_solutions == 0 || numSolutions () < max_solutions)) {
262+ if (impl->preempt_requested_ )
263+ return success_or (moveit::core::MoveItErrorCode::PREEMPTED);
264+ if (std::chrono::duration<double >(std::chrono::steady_clock::now () - start_time).count () > available_time)
265+ return success_or (moveit::core::MoveItErrorCode::TIMED_OUT);
258266 compute ();
259267 for (const auto & cb : impl->task_cbs_ )
260268 cb (*this );
261269 if (impl->introspection_ )
262270 impl->introspection_ ->publishTaskState ();
263- }
264- printState ();
265- return numSolutions () > 0 ;
271+ };
272+ return success_or (moveit::core::MoveItErrorCode::PLANNING_FAILED);
266273}
267274
268275void Task::preempt () {
269276 pimpl ()->preempt_requested_ = true ;
270277}
271278
272- moveit_msgs::MoveItErrorCodes Task::execute (const SolutionBase& s) {
279+ moveit::core::MoveItErrorCode Task::execute (const SolutionBase& s) {
273280 actionlib::SimpleActionClient<moveit_task_constructor_msgs::ExecuteTaskSolutionAction> ac (" execute_task_solution" );
274281 ac.waitForServer ();
275282
0 commit comments