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 {
46 MoveGroupExecuteTrajectoryAction::MoveGroupExecuteTrajectoryAction() : MoveGroupCapability("ExecuteTrajectoryAction")
47 {
48 }
49 
51 {
52  // start the move action server
53  execute_action_server_ = std::make_unique<actionlib::SimpleActionServer<moveit_msgs::ExecuteTrajectoryAction>>(
54  root_node_handle_, EXECUTE_ACTION_NAME, [this](const auto& goal) { executePathCallback(goal); }, false);
55  execute_action_server_->registerPreemptCallback([this] { preemptExecuteTrajectoryCallback(); });
56  execute_action_server_->start();
57 }
58 
59 void MoveGroupExecuteTrajectoryAction::executePathCallback(const moveit_msgs::ExecuteTrajectoryGoalConstPtr& goal)
60 {
61  moveit_msgs::ExecuteTrajectoryResult action_res;
62  if (!context_->trajectory_execution_manager_)
63  {
64  const std::string response = "Cannot execute trajectory since ~allow_trajectory_execution was set to false";
65  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
66  execute_action_server_->setAborted(action_res, response);
67  return;
68  }
69 
70  executePath(goal, action_res);
71 
72  const std::string response = getActionResultString(action_res.error_code, false, false);
73  if (action_res.error_code.val == moveit_msgs::MoveItErrorCodes::SUCCESS)
74  {
75  execute_action_server_->setSucceeded(action_res, response);
76  }
77  else if (action_res.error_code.val == moveit_msgs::MoveItErrorCodes::PREEMPTED)
78  {
79  execute_action_server_->setPreempted(action_res, response);
80  }
81  else
82  {
83  execute_action_server_->setAborted(action_res, response);
84  }
85 
87 }
88 
89 void MoveGroupExecuteTrajectoryAction::executePath(const moveit_msgs::ExecuteTrajectoryGoalConstPtr& goal,
90  moveit_msgs::ExecuteTrajectoryResult& action_res)
91 {
92  ROS_INFO_NAMED(getName(), "Execution request received");
93 
94  context_->trajectory_execution_manager_->clear();
95  if (context_->trajectory_execution_manager_->push(goal->trajectory))
96  {
98  context_->trajectory_execution_manager_->execute();
99  moveit_controller_manager::ExecutionStatus status = context_->trajectory_execution_manager_->waitForExecution();
101  {
102  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
103  }
105  {
106  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::PREEMPTED;
107  }
109  {
110  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::TIMED_OUT;
111  }
112  else
113  {
114  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
115  }
116  ROS_INFO_STREAM_NAMED(getName(), "Execution completed: " << status.asString());
117  }
118  else
119  {
120  action_res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
121  }
122 }
123 
125 {
126  context_->trajectory_execution_manager_->stopExecution(true);
127 }
128 
130 {
131  moveit_msgs::ExecuteTrajectoryFeedback execute_feedback;
132  execute_feedback.state = stateToStr(state);
133  execute_action_server_->publishFeedback(execute_feedback);
134 }
135 
136 } // namespace move_group
137 
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:161
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:82
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::executePath
void executePath(const moveit_msgs::ExecuteTrajectoryGoalConstPtr &goal, moveit_msgs::ExecuteTrajectoryResult &action_res)
Definition: execute_trajectory_action_capability.cpp:121
move_group
Definition: capability_names.h:41
class_loader.hpp
move_group::MONITOR
@ MONITOR
Definition: move_group_capability.h:115
move_group::MoveGroupExecuteTrajectoryAction::execute_action_server_
std::unique_ptr< actionlib::SimpleActionServer< moveit_msgs::ExecuteTrajectoryAction > > execute_action_server_
Definition: execute_trajectory_action_capability.h:128
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:156
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:91
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 Thu Apr 18 2024 02:24:44