Skip to content

Commit

Permalink
[fix] make stages preemptable when the Task has been preempted
Browse files Browse the repository at this point in the history
Forward Task::isPreempted() to all stages.
  • Loading branch information
captain-yoshi committed Jul 17, 2024
1 parent 000d3be commit d83d189
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/include/moveit/task_constructor/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Task : protected WrapperBase
/// interrupt current planning
void preempt();
void resetPreemptRequest();
bool isPreempted();
/// execute solution, return the result
moveit::core::MoveItErrorCode execute(const SolutionBase& s);

Expand Down
15 changes: 12 additions & 3 deletions core/src/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,12 @@ void Task::init() {
// task expects its wrapped child to push to both ends, this triggers interface resolution
stages()->pimpl()->resolveInterface(InterfaceFlags({ GENERATE }));

// provide introspection instance to all stages
// provide introspection instance and prempted requested to all stages
auto* introspection = impl->introspection_.get();
impl->traverseStages(
[introspection](Stage& stage, int /*depth*/) {
[introspection, impl](Stage& stage, int /*depth*/) {
stage.pimpl()->setIntrospection(introspection);
stage.pimpl()->setPreemptedCheck(&impl->preempt_requested_);
return true;
},
1, UINT_MAX);
Expand All @@ -232,7 +233,11 @@ bool Task::canCompute() const {
}

void Task::compute() {
stages()->pimpl()->runCompute();
try {
stages()->pimpl()->runCompute();
} catch (const PreemptStageException& e) {
// do nothing, needed for early stop
}
}

moveit::core::MoveItErrorCode Task::plan(size_t max_solutions) {
Expand Down Expand Up @@ -274,6 +279,10 @@ void Task::resetPreemptRequest() {
pimpl()->preempt_requested_ = false;
}

bool Task::isPreempted() {
return pimpl()->preempt_requested_;
}

moveit::core::MoveItErrorCode Task::execute(const SolutionBase& s) {
actionlib::SimpleActionClient<moveit_task_constructor_msgs::ExecuteTaskSolutionAction> ac("execute_task_solution");
if (!ac.waitForServer(ros::Duration(0.5))) {
Expand Down

0 comments on commit d83d189

Please sign in to comment.