katana_gripper_grasp_controller.cpp
Go to the documentation of this file.
00001 /*
00002  * UOS-ROS packages - Robot Operating System code by the University of Osnabrück
00003  * Copyright (C) 2010  University of Osnabrück
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  *
00019  * katana_gripper_grasp_controller.cpp
00020  *
00021  *  Created on: 29.01.2011
00022  *      Author: Martin Günther <mguenthe@uos.de>
00023  *
00024  * based on pr2_gripper_grasp_controller
00025  *
00026  */
00027 
00028 #include <katana_gazebo_plugins/katana_gripper_grasp_controller.h>
00029 
00030 namespace katana_gazebo_plugins
00031 {
00032 
00033 // copied from katana_constants.h:
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 }


katana_gazebo_plugins
Author(s): Martin Günther
autogenerated on Mon Oct 6 2014 10:47:21