Skip to content

Commit

Permalink
[fix] early preempt lost request
Browse files Browse the repository at this point in the history
Remove the initialization of preemt_requested_ in Task::plan(). Make preempted flag atomic.
Added method to reset the preempt request.
  • Loading branch information
captain-yoshi committed Jul 17, 2024
1 parent f819a1f commit d99f49b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 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 @@ -129,6 +129,7 @@ class Task : protected WrapperBase
moveit::core::MoveItErrorCode plan(size_t max_solutions = 0);
/// interrupt current planning
void preempt();
void resetPreemptFlag();
/// execute solution, return the result
moveit::core::MoveItErrorCode execute(const SolutionBase& s);

Expand Down
2 changes: 1 addition & 1 deletion core/include/moveit/task_constructor/task_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TaskPrivate : public WrapperBasePrivate
std::string ns_;
robot_model_loader::RobotModelLoaderPtr robot_model_loader_;
moveit::core::RobotModelConstPtr robot_model_;
bool preempt_requested_;
std::atomic<bool> preempt_requested_;

// introspection and monitoring
std::unique_ptr<Introspection> introspection_;
Expand Down
5 changes: 4 additions & 1 deletion core/src/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ moveit::core::MoveItErrorCode Task::plan(size_t max_solutions) {
explainFailure();
return error_code;
};
impl->preempt_requested_ = false;
const double available_time = timeout();
const auto start_time = std::chrono::steady_clock::now();
while (canCompute() && (max_solutions == 0 || numSolutions() < max_solutions)) {
Expand All @@ -266,6 +265,10 @@ void Task::preempt() {
pimpl()->preempt_requested_ = true;
}

void Task::resetPreemptFlag() {
pimpl()->preempt_requested_ = false;
}

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 d99f49b

Please sign in to comment.