00001 #include <ros/ros.h>
00002 #include <pr2_controllers_msgs/Pr2GripperCommandAction.h>
00003 #include <actionlib/client/simple_action_client.h>
00004
00005
00006 typedef actionlib::SimpleActionClient<pr2_controllers_msgs::Pr2GripperCommandAction> GripperClient;
00007
00008 class Gripper{
00009 private:
00010 GripperClient* gripper_client_;
00011
00012 public:
00013
00014 Gripper(){
00015
00016
00017
00018 gripper_client_ = new GripperClient("r_gripper_controller/gripper_action", true);
00019
00020
00021 while(!gripper_client_->waitForServer(ros::Duration(30.0))){
00022 ROS_INFO("Waiting for the r_gripper_controller/gripper_action action server to come up");
00023 }
00024 }
00025
00026 ~Gripper(){
00027 delete gripper_client_;
00028 }
00029
00030
00031 void open(){
00032 pr2_controllers_msgs::Pr2GripperCommandGoal open;
00033 open.command.position = 0.07;
00034 open.command.max_effort = 100.0;
00035
00036 ROS_INFO("Sending open goal");
00037
00038
00039
00040
00041
00042 if (gripper_client_->sendGoalAndWait(open,ros::Duration(10.0),ros::Duration(5.0)) == actionlib::SimpleClientGoalState::SUCCEEDED)
00043 ROS_INFO("The gripper opened!");
00044 else
00045 ROS_INFO("The gripper failed to open.");
00046 }
00047
00048
00049 void close(){
00050 pr2_controllers_msgs::Pr2GripperCommandGoal squeeze;
00051 squeeze.command.position = 0.0;
00052 squeeze.command.max_effort = 50.0;
00053
00054 ROS_INFO("Sending squeeze goal");
00055
00056
00057
00058
00059
00060 gripper_client_->sendGoal(squeeze);
00061 if (gripper_client_->waitForResult(ros::Duration(10.0)))
00062 ROS_INFO("The gripper closed!");
00063 else
00064 ROS_INFO("The gripper failed to close.");
00065 }
00066 };
00067
00068 int main(int argc, char** argv){
00069 ros::init(argc, argv, "simple_gripper");
00070
00071 int param = -1;
00072 if (argc > 1)
00073 param = atoi(argv[1]);
00074
00075 Gripper gripper;
00076
00077 switch (param)
00078 {
00079 case 0:
00080 for (int i=0; i < 100; i++)
00081 {
00082 gripper.open();
00083 gripper.close();
00084 }
00085 break;
00086 case 1:
00087 gripper.open();
00088 break;
00089 case 2:
00090 gripper.close();
00091 break;
00092 default:
00093 gripper.open();
00094 break;
00095 }
00096
00097 return 0;
00098 }
00099