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_gazebo_plugins/katana_gripper_grasp_controller.h>
00029
00030 namespace katana_gazebo_plugins
00031 {
00032
00033
00034
00036 static const double GRIPPER_OPEN_ANGLE = 0.30;
00037
00039 static const double GRIPPER_CLOSED_ANGLE = -0.44;
00040
00042 static const double DEFAULT_GRIPPER_OBJECT_PRESENCE_THRESHOLD = -0.43;
00043
00045 static const double GRIPPER_OPENING_CLOSING_DURATION = 6.0;
00046
00047 KatanaGripperGraspController::KatanaGripperGraspController(ros::NodeHandle private_nodehandle) :
00048 desired_angle_(0.0), current_angle_(0.0), has_new_desired_angle_(false)
00049 {
00050 ros::NodeHandle root_nh("");
00051
00052 private_nodehandle.param<double> ("goal_threshold", goal_threshold_, 0.01);
00053
00054 std::string query_service_name = root_nh.resolveName("gripper_grasp_status");
00055 query_srv_ = root_nh.advertiseService(query_service_name, &KatanaGripperGraspController::serviceCallback, this);
00056 ROS_INFO_STREAM("katana gripper grasp query service started on topic " << query_service_name);
00057
00058 std::string gripper_grasp_posture_controller = root_nh.resolveName("gripper_grasp_posture_controller");
00059 action_server_ = new actionlib::SimpleActionServer<control_msgs::GripperCommandAction>(root_nh,
00060 gripper_grasp_posture_controller, boost::bind(&KatanaGripperGraspController::executeCB, this, _1), false);
00061 action_server_->start();
00062 ROS_INFO_STREAM("katana gripper grasp hand posture action server started on topic " << gripper_grasp_posture_controller);
00063 }
00064
00065 KatanaGripperGraspController::~KatanaGripperGraspController()
00066 {
00067 delete action_server_;
00068 }
00069
00070 void KatanaGripperGraspController::executeCB(const control_msgs::GripperCommandGoalConstPtr &goal)
00071 {
00072 ROS_INFO("Moving gripper to position: %f", goal->command.position);
00073
00074 control_msgs::GripperCommandResult result;
00075 result.position = current_angle_;
00076 result.reached_goal = false;
00077 result.stalled = false;
00078
00079 if(goal->command.position < GRIPPER_CLOSED_ANGLE || goal->command.position > GRIPPER_OPEN_ANGLE)
00080 {
00081 ROS_WARN("Goal position (%f) outside gripper range. Or some other stuff happened.", goal->command.position);
00082 action_server_->setAborted(result);
00083 }
00084 else
00085 {
00086 setDesiredAngle(goal->command.position);
00087 ros::Duration(GRIPPER_OPENING_CLOSING_DURATION).sleep();
00088 if(fabs(goal->command.position - current_angle_) > goal_threshold_)
00089 {
00090 ROS_INFO("Gripper stalled.");
00091 result.stalled = true;
00092 }
00093 else
00094 {
00095 ROS_INFO("Gripper goal reached.");
00096 result.reached_goal = true;
00097 }
00098 result.position = current_angle_;
00099 action_server_->setSucceeded(result);
00100 }
00101 }
00102
00103 bool KatanaGripperGraspController::serviceCallback(control_msgs::QueryTrajectoryState::Request &request,
00104 control_msgs::QueryTrajectoryState::Response &response)
00105 {
00106 response.position.resize(1);
00107 response.position[0] = current_angle_;
00108 return true;
00109 }
00110
00111 void KatanaGripperGraspController::getGains(double &p, double &i, double &d, double &i_max, double &i_min) {
00112 p = 0.4;
00113 i = 0.1;
00114 d = 0.0;
00115 }
00116
00117
00118 }