00001 #include "gripper.h" 00002 #include <ros/ros.h> 00003 #include <boost/foreach.hpp> 00004 #include <pcl/io/pcd_io.h> 00005 #include <iostream> 00006 #include <fstream> 00007 #include <stdio.h> 00008 00009 #include <tf/tf.h> 00010 00011 #include <geometry_msgs/PointStamped.h> 00012 00013 //------Gripper open/close----------------------------- 00014 00015 00016 00017 #include <math.h> 00018 00019 00020 Gripper::Gripper() 00021 { //Initialize the client for the Action interface to the gripper controller 00022 //and tell the action client that we want to spin a thread by default 00023 gripper_client_right = new GripperClient("r_gripper_controller/gripper_action", true); 00024 gripper_client_left = new GripperClient("l_gripper_controller/gripper_action", true); 00025 00026 //wait for the gripper action server to come up 00027 while(!gripper_client_right->waitForServer(ros::Duration(5.0))) 00028 { ROS_INFO("Waiting for the r_gripper_controller/gripper_action action server to come up"); 00029 } 00030 while(!gripper_client_left->waitForServer(ros::Duration(5.0))) 00031 { ROS_INFO("Waiting for the l_gripper_controller/gripper_action action server to come up"); 00032 } 00033 } 00034 00035 Gripper::~Gripper() 00036 { delete gripper_client_right; 00037 delete gripper_client_left; 00038 } 00039 00040 //---Open the gripper--- 00041 void Gripper::open_gripper(char lr) 00042 { pr2_controllers_msgs::Pr2GripperCommandGoal open; 00043 open.command.position = 0.08; 00044 open.command.max_effort = -1.0; // Do not limit effort (negative) 00045 00046 ROS_INFO("Sending open goal"); 00047 if(lr == 'l') 00048 { gripper_client_left->sendGoal(open); 00049 gripper_client_left->waitForResult(); 00050 if(gripper_client_left->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00051 ROS_INFO("The left_gripper opened!"); 00052 else 00053 ROS_INFO("The left_gripper failed to open."); 00054 } 00055 else 00056 { gripper_client_right->sendGoal(open); 00057 gripper_client_right->waitForResult(); 00058 if(gripper_client_right->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00059 ROS_INFO("The right_gripper opened!"); 00060 else 00061 ROS_INFO("The right_gripper failed to open."); 00062 } 00063 } 00064 00065 //---Close the gripper--- 00066 void Gripper::close_gripper(char lr) 00067 { pr2_controllers_msgs::Pr2GripperCommandGoal squeeze; 00068 squeeze.command.position = 0.0; 00069 squeeze.command.max_effort = 50.0; // Close gently 00070 00071 ROS_INFO("Sending squeeze goal"); 00072 if (lr == 'l') 00073 { gripper_client_left->sendGoal(squeeze); 00074 gripper_client_left->waitForResult(); 00075 if(gripper_client_left->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00076 ROS_INFO("The left_gripper closed!"); 00077 else 00078 ROS_INFO("The left_gripper failed to close."); 00079 } 00080 else 00081 { gripper_client_right->sendGoal(squeeze); 00082 gripper_client_right->waitForResult(); 00083 if(gripper_client_right->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00084 ROS_INFO("The right_gripper closed!"); 00085 else 00086 ROS_INFO("The right_gripper failed to close."); 00087 } 00088 } 00089