grabActionTest.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  * \author Joe Romano
00030  */
00031 
00032 // @author: Joe Romano
00033 // @email: joeromano@gmail.com 
00034 // @brief: grabActionTest.cpp - example for using the grab
00035 //         action server
00036 
00037 #include <ros/ros.h>
00038 #include <pr2_gripper_sensor_msgs/PR2GripperGrabAction.h>
00039 #include <pr2_gripper_sensor_msgs/PR2GripperReleaseAction.h>
00040 #include <actionlib/client/simple_action_client.h>
00041 
00042 // Our Action interface type, provided as a typedef for convenience
00043 typedef actionlib::SimpleActionClient<pr2_gripper_sensor_msgs::PR2GripperGrabAction> GrabClient;
00044 // Our Action interface type, provided as a typedef for convenience
00045 typedef actionlib::SimpleActionClient<pr2_gripper_sensor_msgs::PR2GripperReleaseAction> ReleaseClient;
00046 
00047 
00048 class Gripper{
00049 private:
00050   GrabClient* grab_client_;
00051   ReleaseClient* release_client_;
00052 
00053 public:
00054   //Action client initialization
00055   Gripper(){
00056 
00057     //Initialize the client for the Action interface to the gripper controller
00058     //and tell the action client that we want to spin a thread by default
00059     grab_client_  = new GrabClient("r_gripper_sensor_controller/grab",true);
00060     release_client_  = new ReleaseClient("r_gripper_sensor_controller/release",true);
00061 
00062     while(!grab_client_->waitForServer(ros::Duration(5.0))){
00063       ROS_INFO("Waiting for the r_gripper_sensor_controller/grab action server to come up");
00064     }
00065 
00066     while(!release_client_->waitForServer(ros::Duration(5.0))){
00067       ROS_INFO("Waiting for the r_gripper_sensor_controller/release action server to come up");
00068     }
00069   }
00070 
00071   ~Gripper(){
00072     delete grab_client_;
00073     delete release_client_;
00074   }
00075 
00076   //Find contact on both fingers and go into slip-servo control mode
00077   void grab(){
00078     pr2_gripper_sensor_msgs::PR2GripperGrabGoal grip;
00079     grip.command.hardness_gain = 0.03;
00080     
00081     ROS_INFO("Sending grab goal");
00082     grab_client_->sendGoal(grip);
00083     grab_client_->waitForResult(ros::Duration(20.0));
00084     if(grab_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
00085       ROS_INFO("Successfully completed Grab");
00086     else
00087       ROS_INFO("Grab Failed");
00088   }
00089 
00090   void release(){
00091     pr2_gripper_sensor_msgs::PR2GripperReleaseGoal place;
00092     // set the robot to release on a figner-side impact, fingerpad slip, or acceleration impact with hand/arm
00093     place.command.event.trigger_conditions = place.command.event.FINGER_SIDE_IMPACT_OR_SLIP_OR_ACC;  
00094     // set the acceleration impact to trigger on to 5 m/s^2
00095     place.command.event.acceleration_trigger_magnitude = 5.0; 
00096     // set our slip-gain to release on to .005
00097     place.command.event.slip_trigger_magnitude = .01;
00098 
00099 
00100     ROS_INFO("Waiting for object placement contact...");
00101     release_client_->sendGoal(place);
00102     release_client_->waitForResult();
00103     if(release_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
00104       ROS_INFO("Release Success");
00105     else
00106       ROS_INFO("Place Failure");
00107 
00108   }
00109 
00110 
00111 };
00112 
00113 int main(int argc, char** argv){
00114   ros::init(argc, argv, "simple_gripper");
00115 
00116   Gripper gripper;
00117 
00118   // wait a few seconds so we can put something in the robot's gripper
00119   sleep(5.0);
00120 
00121   // grab something
00122   gripper.grab();
00123 
00124   // move the robot arm all ove the place here!
00125   sleep(5.0);
00126   
00127   // now that we've decided we want to look for contact and let go
00128   gripper.release();
00129   
00130 
00131   return 0;
00132 }


pr2_gripper_sensor_action
Author(s): Joe Romano
autogenerated on Mon Oct 6 2014 12:22:38