Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <ros/ros.h>
00038 #include <pr2_controllers_msgs/Pr2GripperCommandAction.h>
00039 #include <pr2_gripper_sensor_msgs/PR2GripperFindContactAction.h>
00040 #include <pr2_gripper_sensor_msgs/PR2GripperSlipServoAction.h>
00041 #include <pr2_gripper_sensor_msgs/PR2GripperEventDetectorAction.h>
00042 #include <actionlib/client/simple_action_client.h>
00043
00044 typedef actionlib::SimpleActionClient<pr2_gripper_sensor_msgs::PR2GripperSlipServoAction> SlipClient;
00045
00046 typedef actionlib::SimpleActionClient<pr2_gripper_sensor_msgs::PR2GripperFindContactAction> ContactClient;
00047
00048 typedef actionlib::SimpleActionClient<pr2_gripper_sensor_msgs::PR2GripperEventDetectorAction> EventDetectorClient;
00049
00050 typedef actionlib::SimpleActionClient<pr2_controllers_msgs::Pr2GripperCommandAction> GripperClient;
00051
00052
00053
00054
00055 class Gripper{
00056 private:
00057 GripperClient* gripper_client_;
00058 ContactClient* contact_client_;
00059 SlipClient* slip_client_;
00060 EventDetectorClient* event_detector_client_;
00061
00062 public:
00063
00064 Gripper(){
00065
00066
00067
00068 gripper_client_ = new GripperClient("r_gripper_sensor_controller/gripper_action", true);
00069 contact_client_ = new ContactClient("r_gripper_sensor_controller/find_contact",true);
00070 slip_client_ = new SlipClient("r_gripper_sensor_controller/slip_servo",true);
00071 event_detector_client_ = new EventDetectorClient("r_gripper_sensor_controller/event_detector",true);
00072
00073
00074
00075 while(!gripper_client_->waitForServer(ros::Duration(5.0))){
00076 ROS_INFO("Waiting for the r_gripper_sensor_controller/gripper_action action server to come up");
00077 }
00078
00079 while(!contact_client_->waitForServer(ros::Duration(5.0))){
00080 ROS_INFO("Waiting for the r_gripper_sensor_controller/find_contact action server to come up");
00081 }
00082
00083 while(!slip_client_->waitForServer(ros::Duration(5.0))){
00084 ROS_INFO("Waiting for the r_gripper_sensor_controller/slip_servo action server to come up");
00085 }
00086
00087 while(!event_detector_client_->waitForServer(ros::Duration(5.0))){
00088 ROS_INFO("Waiting for the r_gripper_sensor_controller/event_detector action server to come up");
00089 }
00090 }
00091
00092 ~Gripper(){
00093 delete gripper_client_;
00094 delete contact_client_;
00095 delete slip_client_;
00096 delete event_detector_client_;
00097
00098 }
00099
00100
00101 void open(){
00102 pr2_controllers_msgs::Pr2GripperCommandGoal open;
00103 open.command.position = 0.09;
00104 open.command.max_effort = -1.0;
00105
00106 ROS_INFO("Sending open goal");
00107 gripper_client_->sendGoal(open);
00108 gripper_client_->waitForResult();
00109 if(gripper_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
00110 ROS_INFO("The gripper opened!");
00111 else
00112 ROS_INFO("The gripper failed to open.");
00113 }
00114
00115
00116
00117 void findTwoContacts(){
00118 pr2_gripper_sensor_msgs::PR2GripperFindContactGoal findTwo;
00119 findTwo.command.contact_conditions = findTwo.command.BOTH;
00120 findTwo.command.zero_fingertip_sensors = true;
00121
00122 ROS_INFO("Sending find 2 contact goal");
00123 contact_client_->sendGoal(findTwo);
00124 contact_client_->waitForResult(ros::Duration(5.0));
00125 if(contact_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
00126 {
00127 ROS_INFO("Contact found. Left: %d, Right: %d", contact_client_->getResult()->data.left_fingertip_pad_contact,
00128 contact_client_->getResult()->data.right_fingertip_pad_contact);
00129 ROS_INFO("Contact force. Left: %f, Right: %f", contact_client_->getResult()->data.left_fingertip_pad_force,
00130 contact_client_->getResult()->data.right_fingertip_pad_force);
00131 }
00132 else
00133 ROS_INFO("The gripper did not find a contact.");
00134 }
00135
00136
00137
00138 void slipServo(){
00139 pr2_gripper_sensor_msgs::PR2GripperSlipServoGoal slip_goal;
00140
00141 ROS_INFO("Slip Servoing");
00142 slip_client_->sendGoal(slip_goal);
00143
00144 if(slip_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
00145 ROS_INFO("You Should Never See This Message!");
00146 else
00147 ROS_INFO("SlipServo Action returned without success.");
00148 }
00149
00150
00151
00152 void place(){
00153 pr2_gripper_sensor_msgs::PR2GripperEventDetectorGoal place_goal;
00154 place_goal.command.trigger_conditions = place_goal.command.FINGER_SIDE_IMPACT_OR_SLIP_OR_ACC;
00155 place_goal.command.acceleration_trigger_magnitude = 4.0;
00156 place_goal.command.slip_trigger_magnitude = .005;
00157
00158 ROS_INFO("Waiting for object placement contact...");
00159 event_detector_client_->sendGoal(place_goal);
00160 event_detector_client_->waitForResult();
00161 if(event_detector_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
00162 {
00163 ROS_INFO("Place Success");
00164 ROS_INFO("cond met: %d, acc_met: %d, slip_met: %d", event_detector_client_->getResult()->data.trigger_conditions_met, event_detector_client_->getResult()->data.acceleration_event, event_detector_client_->getResult()->data.slip_event);
00165 }
00166 else
00167 ROS_INFO("Place Failure");
00168 }
00169 };
00170
00171 int main(int argc, char** argv){
00172 ros::init(argc, argv, "simple_gripper");
00173
00174 Gripper gripper;
00175
00176
00177
00178 gripper.open();
00179
00180
00181
00182
00183 sleep(7.0);
00184
00185
00186 gripper.findTwoContacts();
00187
00188
00189 gripper.slipServo();
00190
00191
00192
00193 sleep(8.0);
00194
00195
00196 gripper.place();
00197
00198
00199 gripper.open();
00200
00201 return 0;
00202 }