$search
00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of the Willow Garage nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 *********************************************************************/ 00034 00035 #ifndef _ROS_GRASPIT_INTERFACE_H_ 00036 #define _ROS_GRASPIT_INTERFACE_H_ 00037 00038 #include <map> 00039 00040 //GraspIt! includes 00041 #include <include/plugin.h> 00042 namespace db_planner 00043 { 00044 class DatabaseManager; 00045 } 00046 class GraspitDBModel; 00047 class Pr2Gripper2010; 00048 class Body; 00049 class transf; 00050 class GraspableBody; 00051 00052 #include <ros/ros.h> 00053 00054 #include <object_manipulation_msgs/Grasp.h> 00055 #include <object_manipulation_msgs/GraspPlanning.h> 00056 00057 #include "graspit_ros_planning_msgs/LoadDatabaseModel.h" 00058 #include "graspit_ros_planning_msgs/LoadObstacle.h" 00059 #include "graspit_ros_planning_msgs/ClearBodies.h" 00060 #include "graspit_ros_planning_msgs/SimulateScan.h" 00061 #include "graspit_ros_planning_msgs/TestGrasp.h" 00062 #include "graspit_ros_planning_msgs/GenerateGrasp.h" 00063 #include "graspit_ros_planning_msgs/VerifyGrasp.h" 00064 00065 namespace graspit_ros_planning 00066 { 00067 00069 00077 class RosGraspitInterface : public Plugin 00078 { 00079 private: 00081 ros::NodeHandle *root_nh_; 00082 00084 ros::NodeHandle *priv_nh_; 00085 00087 00089 db_planner::DatabaseManager *db_mgr_; 00090 00092 ros::ServiceServer load_model_srv_; 00093 00095 ros::ServiceServer load_obstacle_srv_; 00096 00098 ros::ServiceServer clear_bodies_srv_; 00099 00101 ros::ServiceServer simulate_scan_srv_; 00102 00104 ros::ServiceServer test_grasp_srv_; 00105 00107 ros::ServiceServer grasp_planning_srv_; 00108 00110 ros::ServiceServer generate_grasp_srv_; 00111 00113 ros::ServiceServer verify_grasp_srv_; 00114 00116 ros::Publisher scan_publisher_; 00117 00119 std::map<int, GraspitDBModel*> models_; 00120 00122 Pr2Gripper2010 *gripper_; 00123 00125 int default_grasp_test_type_; 00126 00128 double default_energy_threshold_; 00129 00131 00133 GraspitDBModel* getModel(int model_id); 00134 00136 bool loadGripper(); 00137 00138 // ------------------------- helper functions for grasp tests --------------------------- 00139 00141 void gripperCollisionCheck(const Body *object, graspit_ros_planning_msgs::TestGrasp::Response &response); 00142 00144 void computeEnergy(Body *object, graspit_ros_planning_msgs::TestGrasp::Response &response); 00145 00146 // ---------------------------------- grasp tests ---------------------------------------- 00147 00149 void testGraspDirect(const object_manipulation_msgs::Grasp &grasp, GraspableBody *object, 00150 graspit_ros_planning_msgs::TestGrasp::Response &response); 00151 00153 void testGraspCompliant(const object_manipulation_msgs::Grasp &grasp, GraspableBody *object, 00154 graspit_ros_planning_msgs::TestGrasp::Response &response); 00155 00157 void testGraspReactive(const object_manipulation_msgs::Grasp &grasp, GraspableBody *object, 00158 graspit_ros_planning_msgs::TestGrasp::Response &response); 00159 00161 void testGraspRobustReactive(const object_manipulation_msgs::Grasp &grasp, GraspableBody *object, 00162 graspit_ros_planning_msgs::TestGrasp::Response &response); 00163 00164 // ---------------------------------- callbacks ---------------------------------------- 00165 00167 bool loadModelCB(graspit_ros_planning_msgs::LoadDatabaseModel::Request &request, 00168 graspit_ros_planning_msgs::LoadDatabaseModel::Response &response); 00169 00171 bool loadObstacleCB(graspit_ros_planning_msgs::LoadObstacle::Request &request, 00172 graspit_ros_planning_msgs::LoadObstacle::Response &response); 00173 00175 bool clearBodiesCB(graspit_ros_planning_msgs::ClearBodies::Request &request, 00176 graspit_ros_planning_msgs::ClearBodies::Response &response); 00177 00179 bool simulateScanCB(graspit_ros_planning_msgs::SimulateScan::Request &request, 00180 graspit_ros_planning_msgs::SimulateScan::Response &response); 00181 00183 bool testGraspCB(graspit_ros_planning_msgs::TestGrasp::Request &request, 00184 graspit_ros_planning_msgs::TestGrasp::Response &response); 00185 00187 bool graspPlanningCB(object_manipulation_msgs::GraspPlanning::Request &request, 00188 object_manipulation_msgs::GraspPlanning::Response &response); 00189 00191 bool generateGraspCB(graspit_ros_planning_msgs::GenerateGrasp::Request &request, 00192 graspit_ros_planning_msgs::GenerateGrasp::Response &response); 00193 00195 bool verifyGraspCB(graspit_ros_planning_msgs::VerifyGrasp::Request &request, 00196 graspit_ros_planning_msgs::VerifyGrasp::Response &response); 00197 00198 00199 public: 00201 RosGraspitInterface(); 00203 ~RosGraspitInterface(); 00205 virtual int init(int argc, char **argv); 00207 virtual int mainLoop(); 00208 }; 00209 00210 } 00211 00212 #endif