Skip to content

Commit c11a34a

Browse files
JafarAbdirhaschke
authored andcommitted
ExecuteTaskSolutionCapability: Reject new goals when busy (moveit#496)
- Rename goalCallback() -> execCallback() - Run execCallback asynchronously and use future to know status of execution
1 parent 1e05859 commit c11a34a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

capabilities/src/execute_task_solution_capability.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ void ExecuteTaskSolutionCapability::initialize() {
9595
ActionServerType::CancelCallback(
9696
std::bind(&ExecuteTaskSolutionCapability::preemptCallback, this, std::placeholders::_1)),
9797
ActionServerType::AcceptedCallback(
98-
std::bind(&ExecuteTaskSolutionCapability::goalCallback, this, std::placeholders::_1)));
98+
[this](const std::shared_ptr<rclcpp_action::ServerGoalHandle<ExecuteTaskSolutionAction>>& goal_handle) {
99+
last_goal_future_ =
100+
std::async(std::launch::async, &ExecuteTaskSolutionCapability::execCallback, this, goal_handle);
101+
}));
99102
}
100103

101-
void ExecuteTaskSolutionCapability::goalCallback(
104+
void ExecuteTaskSolutionCapability::execCallback(
102105
const std::shared_ptr<rclcpp_action::ServerGoalHandle<ExecuteTaskSolutionAction>>& goal_handle) {
103106
auto result = std::make_shared<moveit_task_constructor_msgs::action::ExecuteTaskSolution::Result>();
104107

capabilities/src/execute_task_solution_capability.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,22 @@ class ExecuteTaskSolutionCapability : public MoveGroupCapability
6363
bool constructMotionPlan(const moveit_task_constructor_msgs::msg::Solution& solution,
6464
plan_execution::ExecutableMotionPlan& plan);
6565

66-
void goalCallback(const std::shared_ptr<rclcpp_action::ServerGoalHandle<ExecuteTaskSolutionAction>>& goal_handle);
66+
void execCallback(const std::shared_ptr<rclcpp_action::ServerGoalHandle<ExecuteTaskSolutionAction>>& goal_handle);
6767

6868
rclcpp_action::CancelResponse
6969
preemptCallback(const std::shared_ptr<rclcpp_action::ServerGoalHandle<ExecuteTaskSolutionAction>>& goal_handle);
7070

71-
/** Always accept the goal */
71+
/** Only accept the goal if we aren't executing one */
7272
rclcpp_action::GoalResponse handleNewGoal(const rclcpp_action::GoalUUID& /*uuid*/,
7373
const ExecuteTaskSolutionAction::Goal::ConstSharedPtr& /*goal*/) const {
74+
if (last_goal_future_.valid() &&
75+
last_goal_future_.wait_for(std::chrono::seconds::zero()) != std::future_status::ready)
76+
return rclcpp_action::GoalResponse::REJECT;
7477
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
7578
}
7679

7780
ActionServerType::SharedPtr as_;
81+
std::future<void> last_goal_future_;
7882
};
7983

8084
} // namespace move_group

0 commit comments

Comments
 (0)