Skip to content

Commit ba841a9

Browse files
committed
[fix] make stages preemptable when the Task has been preempted
Forward Task::isPreempted() to all stages.
1 parent 2a8ae67 commit ba841a9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

core/include/moveit/task_constructor/task.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class Task : protected WrapperBase
130130
/// interrupt current planning
131131
void preempt();
132132
void resetPreemptRequest();
133+
bool isPreempted();
133134
/// execute solution, return the result
134135
moveit::core::MoveItErrorCode execute(const SolutionBase& s);
135136

core/src/task.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,12 @@ void Task::init() {
213213
// task expects its wrapped child to push to both ends, this triggers interface resolution
214214
stages()->pimpl()->resolveInterface(InterfaceFlags({ GENERATE }));
215215

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

234235
void Task::compute() {
235-
stages()->pimpl()->runCompute();
236+
try {
237+
stages()->pimpl()->runCompute();
238+
} catch (const PreemptStageException& e) {
239+
// do nothing, needed for early stop
240+
}
236241
}
237242

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

282+
bool Task::isPreempted() {
283+
return pimpl()->preempt_requested_;
284+
}
285+
277286
moveit::core::MoveItErrorCode Task::execute(const SolutionBase& s) {
278287
actionlib::SimpleActionClient<moveit_task_constructor_msgs::ExecuteTaskSolutionAction> ac("execute_task_solution");
279288
if (!ac.waitForServer(ros::Duration(0.5))) {

0 commit comments

Comments
 (0)