62 callback_executor_.cancel();
64 if (callback_thread_.joinable())
65 callback_thread_.join();
70 auto node =
context_->moveit_cpp_->getNode();
71 callback_group_ = node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive,
73 callback_executor_.add_callback_group(callback_group_, node->get_node_base_interface());
74 callback_thread_ = std::thread([
this]() { callback_executor_.spin(); });
76 execute_action_server_ = rclcpp_action::create_server<ExecTrajectory>(
77 node->get_node_base_interface(), node->get_node_clock_interface(), node->get_node_logging_interface(),
78 node->get_node_waitables_interface(), EXECUTE_ACTION_NAME,
79 [](
const rclcpp_action::GoalUUID& ,
const std::shared_ptr<const ExecTrajectory::Goal>& ) {
80 return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
82 [](
const std::shared_ptr<ExecTrajectoryGoal>& ) { return rclcpp_action::CancelResponse::ACCEPT; },
83 [
this](
const auto& goal) { executePathCallback(goal); }, rcl_action_server_get_default_options(),
87void MoveGroupExecuteTrajectoryAction::executePathCallback(
const std::shared_ptr<ExecTrajectoryGoal>& goal)
89 auto action_res = std::make_shared<ExecTrajectory::Result>();
90 if (!
context_->trajectory_execution_manager_)
92 const std::string response =
"Cannot execute trajectory since ~allow_trajectory_execution was set to false";
93 action_res->error_code.val = moveit_msgs::msg::MoveItErrorCodes::CONTROL_FAILED;
94 goal->abort(action_res);
98 executePath(goal, action_res);
101 auto fb = std::make_shared<ExecTrajectory::Feedback>();
102 fb->state = response;
103 if (action_res->error_code.val == moveit_msgs::msg::MoveItErrorCodes::SUCCESS)
105 goal->publish_feedback(fb);
106 goal->succeed(action_res);
110 goal->publish_feedback(fb);
111 goal->abort(action_res);
114 setExecuteTrajectoryState(
IDLE, goal);
117void MoveGroupExecuteTrajectoryAction::executePath(
const std::shared_ptr<ExecTrajectoryGoal>& goal,
118 std::shared_ptr<ExecTrajectory::Result>& action_res)
120 RCLCPP_INFO(
getLogger(),
"Execution request received");
122 if (
context_->trajectory_execution_manager_->push(goal->get_goal()->trajectory, goal->get_goal()->controller_names))
124 setExecuteTrajectoryState(
MONITOR, goal);
125 context_->trajectory_execution_manager_->execute();
129 action_res->error_code.val = moveit_msgs::msg::MoveItErrorCodes::SUCCESS;
133 action_res->error_code.val = moveit_msgs::msg::MoveItErrorCodes::PREEMPTED;
137 action_res->error_code.val = moveit_msgs::msg::MoveItErrorCodes::TIMED_OUT;
141 action_res->error_code.val = moveit_msgs::msg::MoveItErrorCodes::CONTROL_FAILED;
147 action_res->error_code.val = moveit_msgs::msg::MoveItErrorCodes::CONTROL_FAILED;
151void MoveGroupExecuteTrajectoryAction::preemptExecuteTrajectoryCallback()
153 context_->trajectory_execution_manager_->stopExecution(
true);
156void MoveGroupExecuteTrajectoryAction::setExecuteTrajectoryState(
MoveGroupState state,
157 const std::shared_ptr<ExecTrajectoryGoal>& goal)
159 auto execute_feedback = std::make_shared<ExecTrajectory::Feedback>();
161 goal->publish_feedback(execute_feedback);
166#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(cached_ik_kinematics_plugin::CachedIKKinematicsPlugin< kdl_kinematics_plugin::KDLKinematicsPlugin >, kinematics::KinematicsBase)
MoveGroupContextPtr context_
std::string getActionResultString(const moveit_msgs::msg::MoveItErrorCodes &error_code, bool planned_trajectory_empty, bool plan_only)
std::string stateToStr(MoveGroupState state) const
~MoveGroupExecuteTrajectoryAction() override
MoveGroupExecuteTrajectoryAction()
void initialize() override
rclcpp::Logger getLogger()
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
The reported execution status.
std::string asString() const
Convert the execution status to a string.