grabActionTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * \author Joe Romano
30  */
31 
32 // @author: Joe Romano
33 // @email: joeromano@gmail.com
34 // @brief: grabActionTest.cpp - example for using the grab
35 // action server
36 
37 #include <ros/ros.h>
38 #include <pr2_gripper_sensor_msgs/PR2GripperGrabAction.h>
39 #include <pr2_gripper_sensor_msgs/PR2GripperReleaseAction.h>
41 
42 // Our Action interface type, provided as a typedef for convenience
44 // Our Action interface type, provided as a typedef for convenience
46 
47 
48 class Gripper{
49 private:
52 
53 public:
54  //Action client initialization
56 
57  //Initialize the client for the Action interface to the gripper controller
58  //and tell the action client that we want to spin a thread by default
59  grab_client_ = new GrabClient("r_gripper_sensor_controller/grab",true);
60  release_client_ = new ReleaseClient("r_gripper_sensor_controller/release",true);
61 
62  while(!grab_client_->waitForServer(ros::Duration(5.0))){
63  ROS_INFO("Waiting for the r_gripper_sensor_controller/grab action server to come up");
64  }
65 
66  while(!release_client_->waitForServer(ros::Duration(5.0))){
67  ROS_INFO("Waiting for the r_gripper_sensor_controller/release action server to come up");
68  }
69  }
70 
72  delete grab_client_;
73  delete release_client_;
74  }
75 
76  //Find contact on both fingers and go into slip-servo control mode
77  void grab(){
78  pr2_gripper_sensor_msgs::PR2GripperGrabGoal grip;
79  grip.command.hardness_gain = 0.03;
80 
81  ROS_INFO("Sending grab goal");
82  grab_client_->sendGoal(grip);
83  grab_client_->waitForResult(ros::Duration(20.0));
85  ROS_INFO("Successfully completed Grab");
86  else
87  ROS_INFO("Grab Failed");
88  }
89 
90  void release(){
91  pr2_gripper_sensor_msgs::PR2GripperReleaseGoal place;
92  // set the robot to release on a figner-side impact, fingerpad slip, or acceleration impact with hand/arm
93  place.command.event.trigger_conditions = place.command.event.FINGER_SIDE_IMPACT_OR_SLIP_OR_ACC;
94  // set the acceleration impact to trigger on to 5 m/s^2
95  place.command.event.acceleration_trigger_magnitude = 5.0;
96  // set our slip-gain to release on to .005
97  place.command.event.slip_trigger_magnitude = .01;
98 
99 
100  ROS_INFO("Waiting for object placement contact...");
101  release_client_->sendGoal(place);
102  release_client_->waitForResult();
103  if(release_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
104  ROS_INFO("Release Success");
105  else
106  ROS_INFO("Place Failure");
107 
108  }
109 
110 
111 };
112 
113 int main(int argc, char** argv){
114  ros::init(argc, argv, "simple_gripper");
115 
116  Gripper gripper;
117 
118  // wait a few seconds so we can put something in the robot's gripper
119  sleep(5.0);
120 
121  // grab something
122  gripper.grab();
123 
124  // move the robot arm all ove the place here!
125  sleep(5.0);
126 
127  // now that we've decided we want to look for contact and let go
128  gripper.release();
129 
130 
131  return 0;
132 }
int main(int argc, char **argv)
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
actionlib::SimpleActionClient< pr2_gripper_sensor_msgs::PR2GripperReleaseAction > ReleaseClient
void release()
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
actionlib::SimpleActionClient< pr2_gripper_sensor_msgs::PR2GripperGrabAction > GrabClient
#define ROS_INFO(...)
void grab()
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
SimpleClientGoalState getState() const
ReleaseClient * release_client_
GrabClient * grab_client_


pr2_gripper_sensor_action
Author(s): Joe Romano
autogenerated on Wed Apr 1 2020 03:58:26