$search
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2011, Southwest Research Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the Southwest Research Institute, nor the names 00016 * of its contributors may be used to endorse or promote products derived 00017 * from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 00032 00033 #include <ros/ros.h> 00034 #include <actionlib/server/action_server.h> 00035 00036 #include <object_manipulation_msgs/GraspHandPostureExecutionAction.h> 00037 #include "object_manipulation_msgs/GraspHandPostureExecutionGoal.h" 00038 #include <simple_message/smpl_msg_connection.h> 00039 #include <simple_message/simple_message.h> 00040 #include <armadillo/armadillo.h> 00041 #include <armadillo/messages/gripper_message.h> 00042 00043 using namespace object_manipulation_msgs; 00044 using namespace actionlib; 00045 using namespace industrial::smpl_msg_connection; 00046 using namespace industrial::simple_message; 00047 using namespace industrial::armadillo; 00048 using namespace industrial::gripper_message; 00049 00050 class GraspExecutionAction 00051 { 00052 private: 00053 typedef ActionServer<GraspHandPostureExecutionAction> GEAS; 00054 typedef GEAS::GoalHandle GoalHandle; 00055 public: 00056 GraspExecutionAction(ros::NodeHandle &n, SmplMsgConnection *robot) : 00057 node_(n), 00058 action_server_(node_, "grasp_execution_action", 00059 boost::bind(&GraspExecutionAction::goalCB, this, _1), 00060 boost::bind(&GraspExecutionAction::cancelCB, this, _1), 00061 false) 00062 { 00063 ros::NodeHandle pn("~"); 00064 00065 robot_ = robot; 00066 robot_->makeConnect(); 00067 action_server_.start(); 00068 00069 ROS_INFO("Grasp execution action node started"); 00070 00071 /* 00072 //A little bit of debug 00073 GripperMessage gMsg; 00074 SimpleMessage request; 00075 SimpleMessage reply; 00076 00077 gMsg.init(GripperOperationTypes::INIT); 00078 gMsg.toRequest(request); 00079 this->robot_->sendAndReceiveMsg(request, reply); 00080 ROS_INFO("Gripper initialized"); 00081 00082 gMsg.init(GripperOperationTypes::CLOSE); 00083 gMsg.toRequest(request); 00084 this->robot_->sendAndReceiveMsg(request, reply); 00085 ROS_INFO("Gripper closed"); 00086 00087 gMsg.init(GripperOperationTypes::OPEN); 00088 gMsg.toRequest(request); 00089 this->robot_->sendAndReceiveMsg(request, reply); 00090 ROS_INFO("Gripper opened"); 00091 */ 00092 } 00093 00094 ~GraspExecutionAction() 00095 { 00096 } 00097 00098 private: 00099 00100 00101 void goalCB(GoalHandle gh) 00102 { 00103 GripperMessage gMsg; 00104 SimpleMessage request; 00105 SimpleMessage reply; 00106 00107 ROS_DEBUG("Received grasping goal"); 00108 00109 while (!(robot_->isConnected())) 00110 { 00111 ROS_DEBUG("Reconnecting"); 00112 robot_->makeConnect(); 00113 } 00114 00115 00116 switch(gh.getGoal()->goal) 00117 { 00118 case GraspHandPostureExecutionGoal::PRE_GRASP: 00119 00120 gh.setAccepted(); 00121 ROS_WARN("Pre-grasp is not supported by this gripper"); 00122 gh.setSucceeded(); 00123 break; 00124 00125 case GraspHandPostureExecutionGoal::GRASP: 00126 case GraspHandPostureExecutionGoal::RELEASE: 00127 00128 gh.setAccepted(); 00129 switch(gh.getGoal()->goal) 00130 { 00131 case GraspHandPostureExecutionGoal::GRASP: 00132 ROS_INFO("Executing a gripper grasp"); 00133 gMsg.init(GripperOperationTypes::CLOSE); 00134 case GraspHandPostureExecutionGoal::RELEASE: 00135 ROS_INFO("Executing a gripper release"); 00136 gMsg.init(GripperOperationTypes::OPEN); 00137 } 00138 gMsg.toRequest(request); 00139 this->robot_->sendAndReceiveMsg(request, reply); 00140 00141 switch(reply.getReplyCode()) 00142 { 00143 case ReplyTypes::SUCCESS: 00144 ROS_INFO("Robot gripper returned success"); 00145 gh.setSucceeded(); 00146 case ReplyTypes::FAILURE: 00147 ROS_ERROR("Robot gripper returned failure"); 00148 gh.setCanceled(); 00149 } 00150 break; 00151 00152 default: 00153 gh.setRejected(); 00154 00155 } 00156 } 00157 00158 void cancelCB(GoalHandle gh) 00159 { 00160 ROS_ERROR("Action cancel not supported for grasp execution action"); 00161 gh.setRejected(); 00162 } 00163 00164 00165 ros::NodeHandle node_; 00166 GEAS action_server_; 00167 00168 industrial::smpl_msg_connection::SmplMsgConnection *robot_; 00169 00170 }; 00171 00172 00173 #include <simple_message/socket/tcp_client.h> 00174 00175 int main(int argc, char** argv) 00176 { 00177 ros::init(argc, argv, "grasp_execution_action_node"); 00178 ros::NodeHandle node; 00179 industrial::tcp_client::TcpClient robot; 00180 00181 robot.init("192.168.10.3", industrial::simple_socket::StandardSocketPorts::IO); 00182 GraspExecutionAction ge(node, &robot); 00183 00184 ros::spin(); 00185 00186 return 0; 00187 } 00188 00189 00190 00191