execute_trajectory_action_capability.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2016, Kentaro Wada.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Kentaro Wada */
36 
38 
43 
44 namespace move_group
45 {
47  : MoveGroupCapability("ExecuteTrajectoryAction"), callback_queue_(), spinner_(1, &callback_queue_)
48 {
49  root_node_handle_.setCallbackQueue(&callback_queue_);
50  spinner_.start();
51 }
52 
54 {
55  spinner_.stop();
56 }
57 
59 {
60  // start the move action server
61  execute_action_server_ = std::make_unique<actionlib::SimpleActionServer<moveit_msgs::ExecuteTrajectoryAction>>(
62  root_node_handle_, EXECUTE_ACTION_NAME, [this](const auto& goal) { executePathCallback(goal); }, false);
63  execute_action_server_->registerPreemptCallback([this] { preemptExecuteTrajectoryCallback(); });
64  execute_action_server_->start();
65 }
66 
67 void MoveGroupExecuteTrajectoryAction::executePathCallback(const moveit_msgs::ExecuteTrajectoryGoalConstPtr& goal)
68 {
69  moveit_msgs::ExecuteTrajectoryResult action_res;
70  if (!context_->trajectory_execution_manager_)
71  {
72  const std::string response = "Cannot execute trajectory since ~allow_trajectory_execution was set to false";
73  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
74  execute_action_server_->setAborted(action_res, response);
75  return;
76  }
77 
78  executePath(goal, action_res);
79 
80  const std::string response = getActionResultString(action_res.error_code, false, false);
81  if (action_res.error_code.val == moveit_msgs::MoveItErrorCodes::SUCCESS)
82  {
83  execute_action_server_->setSucceeded(action_res, response);
84  }
85  else if (action_res.error_code.val == moveit_msgs::MoveItErrorCodes::PREEMPTED)
86  {
87  execute_action_server_->setPreempted(action_res, response);
88  }
89  else
90  {
91  execute_action_server_->setAborted(action_res, response);
92  }
93 
95 }
96 
97 void MoveGroupExecuteTrajectoryAction::executePath(const moveit_msgs::ExecuteTrajectoryGoalConstPtr& goal,
98  moveit_msgs::ExecuteTrajectoryResult& action_res)
99 {
100  ROS_INFO_NAMED(getName(), "Execution request received");
101 
102  context_->trajectory_execution_manager_->clear();
103  if (context_->trajectory_execution_manager_->push(goal->trajectory))
104  {
106  context_->trajectory_execution_manager_->execute();
107  moveit_controller_manager::ExecutionStatus status = context_->trajectory_execution_manager_->waitForExecution();
109  {
110  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
111  }
113  {
114  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::PREEMPTED;
115  }
117  {
118  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::TIMED_OUT;
119  }
120  else
121  {
122  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
123  }
124  ROS_INFO_STREAM_NAMED(getName(), "Execution completed: " << status.asString());
125  }
126  else
127  {
128  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
129  }
130 }
131 
133 {
134  context_->trajectory_execution_manager_->stopExecution(true);
135 }
136 
138 {
139  moveit_msgs::ExecuteTrajectoryFeedback execute_feedback;
140  execute_feedback.state = stateToStr(state);
141  execute_action_server_->publishFeedback(execute_feedback);
142 }
143 
144 } // namespace move_group
145 
response
const std::string response
move_group::MoveGroupState
MoveGroupState
Definition: move_group_capability.h:79
move_group::MoveGroupExecuteTrajectoryAction
Definition: execute_trajectory_action_capability.h:82
move_group::MoveGroupCapability
Definition: move_group_capability.h:89
move_group::IDLE
@ IDLE
Definition: move_group_capability.h:113
move_group::MoveGroupCapability::context_
MoveGroupContextPtr context_
Definition: move_group_capability.h:132
move_group::MoveGroupCapability::getName
const std::string & getName() const
Definition: move_group_capability.h:104
moveit_controller_manager::ExecutionStatus::PREEMPTED
PREEMPTED
move_group::MoveGroupExecuteTrajectoryAction::setExecuteTrajectoryState
void setExecuteTrajectoryState(MoveGroupState state)
Definition: execute_trajectory_action_capability.cpp:169
utils.h
move_group::MoveGroupExecuteTrajectoryAction::MoveGroupExecuteTrajectoryAction
MoveGroupExecuteTrajectoryAction()
Definition: execute_trajectory_action_capability.cpp:78
execute_trajectory_action_capability.h
moveit_controller_manager::ExecutionStatus::TIMED_OUT
TIMED_OUT
move_group::MoveGroupExecuteTrajectoryAction::initialize
void initialize() override
Definition: execute_trajectory_action_capability.cpp:90
ROS_INFO_NAMED
#define ROS_INFO_NAMED(name,...)
move_group::MoveGroupCapability::root_node_handle_
ros::NodeHandle root_node_handle_
Definition: move_group_capability.h:129
moveit_controller_manager::ExecutionStatus::SUCCEEDED
SUCCEEDED
move_group::MoveGroupExecuteTrajectoryAction::spinner_
ros::AsyncSpinner spinner_
Definition: execute_trajectory_action_capability.h:131
move_group::MoveGroupExecuteTrajectoryAction::executePath
void executePath(const moveit_msgs::ExecuteTrajectoryGoalConstPtr &goal, moveit_msgs::ExecuteTrajectoryResult &action_res)
Definition: execute_trajectory_action_capability.cpp:129
move_group
Definition: capability_names.h:41
class_loader.hpp
move_group::MONITOR
@ MONITOR
Definition: move_group_capability.h:115
ros::NodeHandle::setCallbackQueue
void setCallbackQueue(CallbackQueueInterface *queue)
ros::AsyncSpinner::stop
void stop()
move_group::MoveGroupExecuteTrajectoryAction::execute_action_server_
std::unique_ptr< actionlib::SimpleActionServer< moveit_msgs::ExecuteTrajectoryAction > > execute_action_server_
Definition: execute_trajectory_action_capability.h:132
move_group::EXECUTE_ACTION_NAME
static const std::string EXECUTE_ACTION_NAME
Definition: capability_names.h:77
move_group::MoveGroupCapability::getActionResultString
std::string getActionResultString(const moveit_msgs::MoveItErrorCodes &error_code, bool planned_trajectory_empty, bool plan_only)
Definition: move_group_capability.cpp:117
move_group::MoveGroupCapability::stateToStr
std::string stateToStr(MoveGroupState state) const
Definition: move_group_capability.cpp:149
ROS_INFO_STREAM_NAMED
#define ROS_INFO_STREAM_NAMED(name, args)
move_group::MoveGroupExecuteTrajectoryAction::preemptExecuteTrajectoryCallback
void preemptExecuteTrajectoryCallback()
Definition: execute_trajectory_action_capability.cpp:164
CLASS_LOADER_REGISTER_CLASS
CLASS_LOADER_REGISTER_CLASS(default_planner_request_adapters::AddIterativeSplineParameterization, planning_request_adapter::PlanningRequestAdapter)
trajectory_tools.h
move_group::MoveGroupExecuteTrajectoryAction::executePathCallback
void executePathCallback(const moveit_msgs::ExecuteTrajectoryGoalConstPtr &goal)
Definition: execute_trajectory_action_capability.cpp:99
move_group::MoveGroupExecuteTrajectoryAction::~MoveGroupExecuteTrajectoryAction
~MoveGroupExecuteTrajectoryAction()
Definition: execute_trajectory_action_capability.cpp:85
moveit_controller_manager::ExecutionStatus
capability_names.h
plan_execution.h
moveit_controller_manager::ExecutionStatus::asString
std::string asString() const


move_group
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Sat May 3 2025 02:26:47