katana_gripper_grasp_controller.cpp
Go to the documentation of this file.
1 /*
2  * UOS-ROS packages - Robot Operating System code by the University of Osnabrück
3  * Copyright (C) 2010 University of Osnabrück
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * katana_gripper_grasp_controller.cpp
20  *
21  * Created on: 29.01.2011
22  * Author: Martin Günther <mguenthe@uos.de>
23  *
24  * based on pr2_gripper_grasp_controller
25  *
26  */
27 
29 
30 namespace katana
31 {
32 
34  katana_(katana)
35 {
36  ros::NodeHandle root_nh("");
37  ros::NodeHandle pn("~");
38 
39  pn.param<double> ("goal_threshold", goal_threshold_, 0.01);
40 
41  std::string query_service_name = root_nh.resolveName("gripper_grasp_status");
43  ROS_INFO_STREAM("katana gripper grasp query service started on topic " << query_service_name);
44 
45  std::string gripper_grasp_posture_controller = root_nh.resolveName("gripper_grasp_posture_controller");
47  gripper_grasp_posture_controller, boost::bind(&KatanaGripperGraspController::executeCB, this, _1), false);
49  ROS_INFO_STREAM("katana gripper grasp hand posture action server started on topic " << gripper_grasp_posture_controller);
50 
51 }
52 
54 {
55  delete action_server_;
56 }
57 
58 void KatanaGripperGraspController::executeCB(const control_msgs::GripperCommandGoalConstPtr &goal)
59 {
60  ROS_INFO("Moving gripper to position: %f", goal->command.position);
61  bool moveJointSuccess = katana_->moveJoint(GRIPPER_INDEX, goal->command.position);
62  // wait for gripper to open/close
64 
65  control_msgs::GripperCommandResult result;
66  result.position = katana_->getMotorAngles()[GRIPPER_INDEX];
67  result.reached_goal = false;
68  result.stalled = false;
69 
70  if (moveJointSuccess && fabs(result.position - goal->command.position) < goal_threshold_)
71  {
72  ROS_INFO("Gripper goal reached");
73  result.reached_goal = true;
74  action_server_->setSucceeded(result);
75  }
76  else if (moveJointSuccess && fabs(result.position - goal->command.position) > goal_threshold_)
77  {
78  ROS_INFO("Gripper stalled.");
79  result.stalled = true;
81  }
82  else
83  {
84  ROS_WARN("Goal position (%f) outside gripper range. Or some other stuff happened.", goal->command.position);
85  action_server_->setAborted(result);
86  }
87 
88 
89 }
90 
91 bool KatanaGripperGraspController::serviceCallback(control_msgs::QueryTrajectoryState::Request &request,
92  control_msgs::QueryTrajectoryState::Response &response)
93 {
94  response.position.resize(1);
95  response.position[0] = katana_->getMotorAngles()[GRIPPER_INDEX];
96  return true;
97 }
98 
99 }
static const double GRIPPER_OPENING_CLOSING_DURATION
The maximum time it takes to open or close the gripper.
void executeCB(const control_msgs::GripperCommandGoalConstPtr &goal)
double goal_threshold_
A difference in desired goal angle and actual goal angle above this value indicates that the goal was...
std::string resolveName(const std::string &name, bool remap=true) const
bool sleep() const
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
#define ROS_WARN(...)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
boost::shared_ptr< AbstractKatana > katana_
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
actionlib::SimpleActionServer< control_msgs::GripperCommandAction > * action_server_
Action server for the grasp posture action.
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
#define ROS_INFO_STREAM(args)
const size_t GRIPPER_INDEX
The motor index of the gripper (used in all vectors – e.g., motor_angles_)
KatanaGripperGraspController(boost::shared_ptr< AbstractKatana > katana)
ros::ServiceServer query_srv_
Server for the posture query service.
bool serviceCallback(control_msgs::QueryTrajectoryState::Request &request, control_msgs::QueryTrajectoryState::Response &response)


katana
Author(s): Martin Günther
autogenerated on Fri Jun 7 2019 22:06:58