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
00038
00039 #include <object_manipulation_tools/controller_utils/GraspPoseControllerHandler.h>
00040
00041 static const double GRASP_COMMAND_EXECUTION_TIMEOUT = 4.0f;
00042
00043 GraspPoseControllerHandler::GraspPoseControllerHandler(const std::string& group_name,const std::string& controller_name)
00044 :TrajectoryControllerHandler(group_name, controller_name),
00045 grasp_posture_execution_action_client_(controller_name, true)
00046 {
00047 while(ros::ok() && !grasp_posture_execution_action_client_.waitForServer(ros::Duration(5.0)))
00048 {
00049 ROS_INFO_STREAM("Waiting for the grasp_posture_execution action for group " << group_name << " on the topic " << controller_name << " to come up");
00050 }
00051 }
00052
00053 bool GraspPoseControllerHandler::executeTrajectory(
00054 const trajectory_msgs::JointTrajectory& trajectory,
00055 boost::shared_ptr<trajectory_execution_monitor::TrajectoryRecorder>& recorder,
00056 const trajectory_execution_monitor::TrajectoryFinishedCallbackFunction& traj_callback)
00057 {
00058
00059 recorder_ = recorder;
00060 trajectory_finished_callback_ = traj_callback;
00061
00062 initializeRecordedTrajectory(trajectory);
00063
00064 object_manipulation_msgs::GraspHandPostureExecutionGoal goal;
00065 int graspCode = (int)trajectory.points[0].positions[0];
00066 std::string graspMoveName;
00067
00068 switch(graspCode)
00069 {
00070 case object_manipulation_msgs::GraspHandPostureExecutionGoal::GRASP:
00071
00072 ROS_INFO_STREAM("Grasp Controller should be commanding grasp");
00073 graspMoveName = "Grasp";
00074 goal.goal = object_manipulation_msgs::GraspHandPostureExecutionGoal::GRASP;
00075 break;
00076
00077 case object_manipulation_msgs::GraspHandPostureExecutionGoal::PRE_GRASP:
00078
00079 ROS_INFO_STREAM("Grasp Controller should be commanding pre-grasp");
00080 graspMoveName = "Pre-grasp";
00081 goal.goal = object_manipulation_msgs::GraspHandPostureExecutionGoal::PRE_GRASP;
00082 break;
00083
00084 case object_manipulation_msgs::GraspHandPostureExecutionGoal::RELEASE:
00085
00086 ROS_INFO_STREAM("Grasp Controller should be commanding release");
00087 graspMoveName = "Release";
00088 goal.goal = object_manipulation_msgs::GraspHandPostureExecutionGoal::RELEASE;
00089 break;
00090
00091 default:
00092 ROS_INFO_STREAM("Grasp Controller received unknown command, exiting ");
00093 return false;
00094 }
00095
00096 grasp_posture_execution_action_client_.sendGoal(goal,
00097 boost::bind(&GraspPoseControllerHandler::controllerDoneCallback, this, _1, _2),
00098 boost::bind(&GraspPoseControllerHandler::controllerActiveCallback, this),
00099 boost::bind(&GraspPoseControllerHandler::controllerFeedbackCallback, this, _1));
00100
00101
00102 recorder_->registerCallback(group_controller_combo_name_,
00103 boost::bind(&GraspPoseControllerHandler::addNewStateToRecordedTrajectory
00104 , this, _1, _2, _3));
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 return true;
00120 }
00121
00122 void GraspPoseControllerHandler::cancelExecution()
00123 {
00124
00125 }
00126
00127 void GraspPoseControllerHandler::controllerDoneCallback(const actionlib::SimpleClientGoalState& state,
00128 const object_manipulation_msgs::GraspHandPostureExecutionResultConstPtr& result)
00129 {
00130
00131 bool success = (state == actionlib::SimpleClientGoalState::SUCCEEDED);
00132
00133
00134 trajectory_execution_monitor::TrajectoryControllerState controllerState;
00135 controllerState = (success) ? trajectory_execution_monitor::TrajectoryControllerStates::SUCCESS :
00136 trajectory_execution_monitor::TrajectoryControllerStates::EXECUTION_FAILURE;
00137
00138
00139 controller_state_ = controllerState;
00140 recorder_->deregisterCallback(group_controller_combo_name_);
00141
00142 ROS_INFO_STREAM("Grasp Controller is done with state " <<
00143 (success?"SUCCESS":"FAULT"));
00144
00145 done();
00146 }
00147
00148 void GraspPoseControllerHandler::controllerActiveCallback()
00149 {
00150 ROS_DEBUG_STREAM("Grasp Controller went active");
00151 }
00152
00153 void GraspPoseControllerHandler::controllerFeedbackCallback(const object_manipulation_msgs::GraspHandPostureExecutionFeedbackConstPtr& feedback)
00154 {
00155 ROS_INFO_STREAM("Grasp Controller got feedback");
00156 }
00157