Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "execute_trajectory_service_capability.h"
00038 #include <moveit/trajectory_execution_manager/trajectory_execution_manager.h>
00039 #include <moveit/move_group/capability_names.h>
00040
00041 move_group::MoveGroupExecuteService::MoveGroupExecuteService()
00042 : MoveGroupCapability("ExecuteTrajectoryService")
00043 , callback_queue_()
00044 , spinner_(1 , &callback_queue_)
00045 {
00046 }
00047
00048 move_group::MoveGroupExecuteService::~MoveGroupExecuteService()
00049 {
00050 spinner_.stop();
00051 }
00052
00053 void move_group::MoveGroupExecuteService::initialize()
00054 {
00055
00056
00057
00058
00059 ros::AdvertiseServiceOptions ops;
00060 ops.template init<moveit_msgs::ExecuteKnownTrajectory::Request, moveit_msgs::ExecuteKnownTrajectory::Response>(
00061 EXECUTE_SERVICE_NAME, boost::bind(&MoveGroupExecuteService::executeTrajectoryService, this, _1, _2));
00062 ops.callback_queue = &callback_queue_;
00063 execute_service_ = root_node_handle_.advertiseService(ops);
00064 spinner_.start();
00065 }
00066
00067 bool move_group::MoveGroupExecuteService::executeTrajectoryService(moveit_msgs::ExecuteKnownTrajectory::Request& req,
00068 moveit_msgs::ExecuteKnownTrajectory::Response& res)
00069 {
00070 ROS_INFO("Received new trajectory execution service request...");
00071 if (!context_->trajectory_execution_manager_)
00072 {
00073 ROS_ERROR("Cannot execute trajectory since ~allow_trajectory_execution was set to false");
00074 res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
00075 return true;
00076 }
00077
00078
00079
00080
00081 context_->trajectory_execution_manager_->clear();
00082 if (context_->trajectory_execution_manager_->push(req.trajectory))
00083 {
00084 context_->trajectory_execution_manager_->execute();
00085 if (req.wait_for_execution)
00086 {
00087 moveit_controller_manager::ExecutionStatus es = context_->trajectory_execution_manager_->waitForExecution();
00088 if (es == moveit_controller_manager::ExecutionStatus::SUCCEEDED)
00089 res.error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
00090 else if (es == moveit_controller_manager::ExecutionStatus::PREEMPTED)
00091 res.error_code.val = moveit_msgs::MoveItErrorCodes::PREEMPTED;
00092 else if (es == moveit_controller_manager::ExecutionStatus::TIMED_OUT)
00093 res.error_code.val = moveit_msgs::MoveItErrorCodes::TIMED_OUT;
00094 else
00095 res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
00096 ROS_INFO_STREAM("Execution completed: " << es.asString());
00097 }
00098 else
00099 {
00100 ROS_INFO("Trajectory was successfully forwarded to the controller");
00101 res.error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
00102 }
00103 }
00104 else
00105 {
00106 res.error_code.val = moveit_msgs::MoveItErrorCodes::CONTROL_FAILED;
00107 }
00108 return true;
00109 }
00110
00111 #include <class_loader/class_loader.h>
00112 CLASS_LOADER_REGISTER_CLASS(move_group::MoveGroupExecuteService, move_group::MoveGroupCapability)