GraspRetriever.cpp
Go to the documentation of this file.
00001 
00013 // RAIL Grasp Collection
00014 #include "rail_grasp_collection/GraspRetriever.h"
00015 
00016 using namespace std;
00017 using namespace rail::pick_and_place;
00018 
00019 GraspRetriever::GraspRetriever()
00020     : private_node_("~"),
00021       as_(private_node_, "retrieve_grasp", boost::bind(&GraspRetriever::retrieveGrasp, this, _1), false)
00022 {
00023   // set defaults
00024   int port = graspdb::Client::DEFAULT_PORT;
00025   string host("127.0.0.1");
00026   string user("ros");
00027   string password("");
00028   string db("graspdb");
00029 
00030   // grab any parameters we need
00031   node_.getParam("/graspdb/host", host);
00032   node_.getParam("/graspdb/port", port);
00033   node_.getParam("/graspdb/user", user);
00034   node_.getParam("/graspdb/password", password);
00035   node_.getParam("/graspdb/db", db);
00036 
00037   // set up a connection to the grasp database
00038   graspdb_ = new graspdb::Client(host, port, user, password, db);
00039   okay_ = graspdb_->connect();
00040 
00041   // set up the latched publishers we need
00042   point_cloud_pub_ = private_node_.advertise<sensor_msgs::PointCloud2>("point_cloud", 1, true);
00043   pose_pub_ = private_node_.advertise<geometry_msgs::PoseStamped>("pose", 1, true);
00044 
00045   // start the action server
00046   as_.start();
00047 
00048   if (okay_)
00049   {
00050     ROS_INFO("Grasp Retriever Successfully Initialized");
00051   }
00052 }
00053 
00054 GraspRetriever::~GraspRetriever()
00055 {
00056   // cleanup
00057   as_.shutdown();
00058   graspdb_->disconnect();
00059   delete graspdb_;
00060 }
00061 
00062 bool GraspRetriever::okay() const
00063 {
00064   return okay_;
00065 }
00066 
00067 void GraspRetriever::retrieveGrasp(const rail_pick_and_place_msgs::RetrieveGraspDemonstrationGoalConstPtr &goal)
00068 {
00069   rail_pick_and_place_msgs::RetrieveGraspDemonstrationFeedback feedback;
00070   rail_pick_and_place_msgs::RetrieveGraspDemonstrationResult result;
00071 
00072   // attempt to load the grasp from the database
00073   feedback.message = "Requesting grasp demonstration from database...";
00074   as_.publishFeedback(feedback);
00075   graspdb::GraspDemonstration gd;
00076   if (!graspdb_->loadGraspDemonstration(goal->id, gd))
00077   {
00078     result.success = false;
00079     as_.setSucceeded(result, "Could not load grasp from database.");
00080     return;
00081   } else
00082   {
00083     // store inside of the result
00084     result.grasp = gd.toROSGraspDemonstrationMessage();
00085 
00086     // publish the data
00087     feedback.message = "Publishing to latched topics...";
00088     as_.publishFeedback(feedback);
00089     // send the resulting point cloud message from the goal
00090     point_cloud_pub_.publish(result.grasp.point_cloud);
00091     // create and send a PoseStamped
00092     pose_pub_.publish(gd.getGraspPose().toROSPoseStampedMessage());
00093 
00094     // success
00095     result.success = true;
00096     as_.setSucceeded(result, "Success!");
00097   }
00098 }


rail_grasp_collection
Author(s): Russell Toris , David Kent
autogenerated on Thu Jun 6 2019 19:44:05