grasp_retriever.h
Go to the documentation of this file.
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 // Author(s): Peter Brook
00036 
00037 #ifndef _GRASP_RETRIEVER_H_
00038 #define _GRASP_RETRIEVER_H_
00039 
00040 #include <ros/ros.h>
00041 
00042 #include <vector>
00043 #include <map>
00044 #include <tf/transform_broadcaster.h>
00045 #include <object_manipulation_msgs/GraspableObject.h>
00046 
00047 #include <household_objects_database_msgs/DatabaseModelPose.h>
00048 #include <household_objects_database/database_grasp.h>
00049 #include <household_objects_database/database_perturbation.h>
00050 using household_objects_database::DatabasePerturbationPtr;
00051 
00052 #include "probabilistic_grasp_planner/forward_decls.h"
00053 
00054 #include "probabilistic_grasp_planner/probabilistic_planner_tools.h"
00055 
00056 namespace probabilistic_grasp_planner {
00057 
00058 class GraspRetriever
00059 {
00060 protected:
00061   std::string arm_name_;
00062   std::vector<GraspWithMetadata> grasps_;
00063 public:
00064   //virtual void getGrasps(std::vector<GraspWithMetadata> &grasps) = 0;
00065   virtual void getGrasps(std::vector<GraspWithMetadata> &grasps) = 0;
00066 
00067   GraspRetriever(const std::string &arm_name) :
00068                    arm_name_(arm_name)
00069   {
00070 
00071   }
00072 };
00073 typedef boost::shared_ptr<GraspRetriever> GraspRetrieverPtr;
00074 
00075 class DatabaseGraspRetriever : public GraspRetriever
00076 {
00077 private:
00079   std::map<int, std::vector<household_objects_database::DatabaseGraspPtr> > grasps_cache_;
00080 
00081 protected:
00082   ObjectsDatabasePtr database_;
00083 
00085   const household_objects_database_msgs::DatabaseModelPose &model_;
00086 
00088   bool prune_compliant_copies_;
00089 
00091   bool use_cluster_rep_grasps_;
00092 
00098   void appendMetadataToGrasps(const std::vector<household_objects_database::DatabaseGraspPtr> &db_grasps,
00099                               std::vector<GraspWithMetadata> &grasps);
00103   void pruneGraspList(std::vector<household_objects_database::DatabaseGraspPtr> &grasps, double gripper_threshold,
00104                         double table_clearance_threshold);
00105 
00106 public:
00110   DatabaseGraspRetriever(ObjectsDatabasePtr database,
00111                          const household_objects_database_msgs::DatabaseModelPose &model,
00112                          const std::string &arm_name,
00113                          bool prune_compliant_copies,
00114                                                  bool use_cluster_rep_grasps);
00115 
00120   virtual void getGrasps(std::vector<GraspWithMetadata> &grasps);
00121 
00122   virtual void fetchFromDB();
00123 
00124 };
00125 typedef boost::shared_ptr<DatabaseGraspRetriever> DatabaseGraspRetrieverPtr;
00126 
00127 class ClusterRepGraspRetriever : public DatabaseGraspRetriever
00128 {
00129 private:
00131     std::map<int, std::vector<household_objects_database::DatabaseGraspPtr> > grasps_cache_;
00132 protected:
00133 
00134 public:
00135   ClusterRepGraspRetriever(ObjectsDatabasePtr database, const household_objects_database_msgs::DatabaseModelPose &model,
00136                            const std::string &arm_name);
00141   virtual void getGrasps(std::vector<GraspWithMetadata> &grasps);
00142 
00143   virtual void fetchFromDB();
00144 };
00145 typedef boost::shared_ptr<ClusterRepGraspRetriever> ClusterRepGraspRetrieverPtr;
00146 
00147 class DebugClusterRepGraspRetriever : public ClusterRepGraspRetriever
00148 {
00149 public:
00150   DebugClusterRepGraspRetriever(ObjectsDatabasePtr database,
00151                                 const household_objects_database_msgs::DatabaseModelPose &model,
00152                                 const std::string &arm_name) :
00153                                   ClusterRepGraspRetriever(database, model, arm_name)
00154   {
00155 
00156   }
00157 
00162   virtual void getGrasps(std::vector<GraspWithMetadata> &grasps);
00163 };
00164 
00168 class PerturbationGraspRetriever : public DatabaseGraspRetriever
00169 {
00170 private:
00171   const GraspWithMetadata *gstar_;
00172 protected:
00173   std::vector<DatabasePerturbationPtr> perturbations_;
00174   virtual void fetchFromDB();
00175 public:
00176   PerturbationGraspRetriever(ObjectsDatabasePtr database,
00177                              const household_objects_database_msgs::DatabaseModelPose &model,
00178                              const std::string &arm_name);
00179   void setGrasp(const GraspWithMetadata *gstar)
00180   {
00181     gstar_ = gstar;
00182   }
00183 
00184   void getGrasps(std::vector<GraspWithMetadata> &grasps);
00185 };
00186 
00187 class OnlinePerturbationGraspRetriever : GraspRetriever
00188 {
00189 private:
00190   const GraspWithMetadata *gstar_;
00191 
00192 public:
00193   OnlinePerturbationGraspRetriever(const GraspWithMetadata *gstar, const std::string &arm_name) :
00194     GraspRetriever(arm_name), gstar_(gstar)
00195   {
00196 
00197   }
00198 
00199   void getGrasps(std::vector<GraspWithMetadata> &grasps);
00200 };
00201 
00202 class ClusterPlannerGraspRetriever : public GraspRetriever
00203 {
00204 private:
00205   tf::TransformBroadcaster tf_broadcaster;
00206   ros::ServiceClient cluster_planner_srv_;
00207   std::vector<object_manipulation_msgs::Grasp> grasps_from_cluster_planner_;
00208   sensor_msgs::PointCloud cloud_;
00209 protected:
00210   void appendGraspsFromClusterPlanner(std::vector<GraspWithMetadata> &grasps);
00211   virtual void fetchFromPlanner(const object_manipulation_msgs::GraspableObject &graspable_object);
00212 public:
00213   ClusterPlannerGraspRetriever(ros::NodeHandle &nh, const std::string &cluster_planner_name,
00214                                const object_manipulation_msgs::GraspableObject &graspable_object,
00215                                const std::string &arm_name);
00216 
00220   virtual void getGrasps(std::vector<GraspWithMetadata> &grasps);
00221 };
00222 } //namespace
00223 
00224 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


probabilistic_grasp_planner
Author(s): Peter Brook
autogenerated on Fri Jan 25 2013 15:03:22