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 #include <katana/katana_gripper_grasp_controller.h>
00029
00030 namespace katana
00031 {
00032
00033 KatanaGripperGraspController::KatanaGripperGraspController(boost::shared_ptr<AbstractKatana> katana) :
00034 katana_(katana), last_command_was_close_(false)
00035 {
00036 ros::NodeHandle root_nh("");
00037 ros::NodeHandle pn("~");
00038
00039 pn.param<double> ("gripper_object_presence_threshold", gripper_object_presence_threshold_,
00040 DEFAULT_GRIPPER_OBJECT_PRESENCE_THRESHOLD);
00041
00042 std::string query_service_name = root_nh.resolveName("gripper_grasp_status");
00043 query_srv_ = root_nh.advertiseService(query_service_name, &KatanaGripperGraspController::serviceCallback, this);
00044 ROS_INFO_STREAM("katana gripper grasp query service started on topic " << query_service_name);
00045
00046 std::string gripper_grasp_posture_controller = root_nh.resolveName("gripper_grasp_posture_controller");
00047 action_server_ = new actionlib::SimpleActionServer<object_manipulation_msgs::GraspHandPostureExecutionAction>(root_nh,
00048 gripper_grasp_posture_controller, boost::bind(&KatanaGripperGraspController::executeCB, this, _1), false);
00049 action_server_->start();
00050 ROS_INFO_STREAM("katana gripper grasp hand posture action server started on topic " << gripper_grasp_posture_controller);
00051 }
00052
00053 KatanaGripperGraspController::~KatanaGripperGraspController()
00054 {
00055 delete action_server_;
00056 }
00057
00058 void KatanaGripperGraspController::executeCB(const object_manipulation_msgs::GraspHandPostureExecutionGoalConstPtr &goal)
00059 {
00060 switch (goal->goal)
00061 {
00062 case object_manipulation_msgs::GraspHandPostureExecutionGoal::GRASP:
00063 if (goal->grasp.grasp_posture.position.empty())
00064 {
00065 ROS_ERROR("katana gripper grasp execution: position vector empty in requested grasp");
00066 action_server_->setAborted();
00067 return;
00068 }
00069
00070
00071
00072
00073 katana_->moveJoint(GRIPPER_INDEX, GRIPPER_CLOSED_ANGLE);
00074
00075 last_command_was_close_ = true;
00076 break;
00077
00078 case object_manipulation_msgs::GraspHandPostureExecutionGoal::PRE_GRASP:
00079 if (goal->grasp.pre_grasp_posture.position.empty())
00080 {
00081 ROS_ERROR("katana gripper grasp execution: position vector empty in requested pre_grasp");
00082 action_server_->setAborted();
00083 return;
00084 }
00085
00086
00087
00088
00089 for (unsigned int i = 0; i < goal->grasp.pre_grasp_posture.position.size(); i++)
00090 {
00091 katana_->moveJoint(katana_->getJointIndex(goal->grasp.pre_grasp_posture.name[i]),
00092 goal->grasp.pre_grasp_posture.position[i]);
00093 }
00094
00095 last_command_was_close_ = false;
00096 break;
00097
00098 case object_manipulation_msgs::GraspHandPostureExecutionGoal::RELEASE:
00099
00100 katana_->moveJoint(GRIPPER_INDEX, GRIPPER_OPEN_ANGLE);
00101 last_command_was_close_ = false;
00102 break;
00103
00104 default:
00105 ROS_ERROR("katana gripper grasp execution: unknown goal code (%d)", goal->goal);
00106 action_server_->setAborted();
00107 return;
00108 }
00109
00110
00111 ros::Duration(GRIPPER_OPENING_CLOSING_DURATION).sleep();
00112
00113
00114
00115 static const bool move_gripper_success = true;
00116
00117
00118 if (move_gripper_success)
00119 {
00120 ROS_INFO("Gripper goal achieved");
00121 action_server_->setSucceeded();
00122 }
00123 else
00124 {
00125 if (goal->goal == object_manipulation_msgs::GraspHandPostureExecutionGoal::GRASP)
00126 {
00127
00128
00129 action_server_->setSucceeded();
00130 }
00131 else
00132 {
00133 ROS_WARN("Gripper goal not achieved for pre-grasp or release");
00134
00135 action_server_->setSucceeded();
00136 }
00137 }
00138 }
00139
00140 bool KatanaGripperGraspController::serviceCallback(object_manipulation_msgs::GraspStatus::Request &request,
00141 object_manipulation_msgs::GraspStatus::Response &response)
00142 {
00143 if (!last_command_was_close_)
00144 {
00145 ROS_INFO("Gripper grasp query false: the last gripper command was not 'close' (= not holding any object)");
00146 response.is_hand_occupied = false;
00147 return true;
00148 }
00149
00150 double gripperAngle = katana_->getMotorAngles()[GRIPPER_INDEX];
00151 if (gripperAngle < gripper_object_presence_threshold_)
00152 {
00153 ROS_INFO("Gripper grasp query false: gripper angle %f below threshold %f (= not holding any object)",
00154 gripperAngle, gripper_object_presence_threshold_);
00155 response.is_hand_occupied = false;
00156 }
00157 else
00158 {
00159 ROS_INFO("Gripper grasp query true: gripper angle %f above threshold %f (= holding an object)",
00160 gripperAngle, gripper_object_presence_threshold_);
00161 response.is_hand_occupied = true;
00162 }
00163 return true;
00164 }
00165
00166 }