GraspModelRetriever.cpp
Go to the documentation of this file.
00001 
00013 // RAIL Grasp Collection
00014 #include "rail_recognition/GraspModelRetriever.h"
00015 
00016 // ROS
00017 #include <geometry_msgs/PoseArray.h>
00018 
00019 using namespace std;
00020 using namespace rail::pick_and_place;
00021 
00022 GraspModelRetriever::GraspModelRetriever()
00023     : private_node_("~"),
00024       as_(private_node_, "retrieve_grasp_model", boost::bind(&GraspModelRetriever::retrieveGraspModel, this, _1), false)
00025 {
00026   // set defaults
00027   int port = graspdb::Client::DEFAULT_PORT;
00028   string host("127.0.0.1");
00029   string user("ros");
00030   string password("");
00031   string db("graspdb");
00032 
00033   // grab any parameters we need
00034   node_.getParam("/graspdb/host", host);
00035   node_.getParam("/graspdb/port", port);
00036   node_.getParam("/graspdb/user", user);
00037   node_.getParam("/graspdb/password", password);
00038   node_.getParam("/graspdb/db", db);
00039 
00040   // set up a connection to the grasp database
00041   graspdb_ = new graspdb::Client(host, port, user, password, db);
00042   okay_ = graspdb_->connect();
00043 
00044   // set up the latched publishers we need
00045   point_cloud_pub_ = private_node_.advertise<sensor_msgs::PointCloud2>("point_cloud", 1, true);
00046   poses_pub_ = private_node_.advertise<geometry_msgs::PoseArray>("poses", 1, true);
00047 
00048   // start the action server
00049   as_.start();
00050 
00051   if (okay_)
00052   {
00053     ROS_INFO("Grasp Model Retriever Successfully Initialized");
00054   }
00055 }
00056 
00057 GraspModelRetriever::~GraspModelRetriever()
00058 {
00059   // cleanup
00060   as_.shutdown();
00061   graspdb_->disconnect();
00062   delete graspdb_;
00063 }
00064 
00065 bool GraspModelRetriever::okay() const
00066 {
00067   return okay_;
00068 }
00069 
00070 void GraspModelRetriever::retrieveGraspModel(const rail_pick_and_place_msgs::RetrieveGraspModelGoalConstPtr &goal)
00071 {
00072   rail_pick_and_place_msgs::RetrieveGraspModelFeedback feedback;
00073   rail_pick_and_place_msgs::RetrieveGraspModelResult result;
00074 
00075   // attempt to load the grasp model from the database
00076   feedback.message = "Requesting grasp model from database...";
00077   as_.publishFeedback(feedback);
00078   graspdb::GraspModel gm;
00079   if (!graspdb_->loadGraspModel(goal->id, gm))
00080   {
00081     result.success = false;
00082     as_.setSucceeded(result, "Could not load grasp model from database.");
00083     return;
00084   } else
00085   {
00086     // store inside of the result
00087     result.grasp_model = gm.toROSGraspModelMessage();
00088 
00089     // publish the data
00090     feedback.message = "Publishing to latched topics...";
00091     as_.publishFeedback(feedback);
00092     // send the resulting point cloud message from the goal
00093     point_cloud_pub_.publish(result.grasp_model.point_cloud);
00094     // create and send a PoseArray
00095     geometry_msgs::PoseArray poses;
00096     for (size_t i = 0; i < result.grasp_model.grasps.size(); i++)
00097     {
00098       poses.header.frame_id = result.grasp_model.grasps[i].grasp.grasp_pose.header.frame_id;
00099       poses.poses.push_back(result.grasp_model.grasps[i].grasp.grasp_pose.pose);
00100     }
00101     poses_pub_.publish(poses);
00102 
00103     // success
00104     result.success = true;
00105     as_.setSucceeded(result, "Success!");
00106   }
00107 }


rail_recognition
Author(s): David Kent , Russell Toris , bhetherman
autogenerated on Sun Mar 6 2016 11:39:13