finddd_alg_node.cpp
Go to the documentation of this file.
00001 #include "finddd_alg_node.h"
00002 
00003 FindddAlgNode::FindddAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<FindddAlgorithm>()
00005 {
00006   //init class attributes if necessary
00007   //this->loop_rate_ = 2;//in [Hz]
00008 
00009   // [init publishers]
00010   this->descriptor_publisher_ = this->public_node_handle_.advertise<iri_perception_msgs::DescriptorSet>("ndesc", 1); 
00011   
00012   // [init subscribers]
00013   this->points_subscriber_ = this->public_node_handle_.subscribe("points", 1, &FindddAlgNode::points_callback, this);
00014   
00015   // [init services]
00016   this->get_finddd_from_pointcloud_server_ = this->public_node_handle_.advertiseService("get_finddd_from_pointcloud", &FindddAlgNode::get_finddd_from_pointcloudCallback, this);
00017   
00018   // [init clients]
00019   
00020   // [init action servers]
00021   
00022   // [init action clients]
00023   this->accumulated_time=0;
00024 }
00025 
00026 FindddAlgNode::~FindddAlgNode(void)
00027 {
00028   // [free dynamic memory]
00029 }
00030 
00031 void FindddAlgNode::mainNodeThread(void)
00032 {
00033   // [fill msg structures]
00034   
00035   // [fill srv structure and make request to the server]
00036   
00037   // [fill action structure and make request to the action server]
00038 
00039   // [publish messages]
00040 }
00041 
00042 /*  [subscriber callbacks] */
00043 
00044 /*  [service callbacks] */
00045 bool FindddAlgNode::get_finddd_from_pointcloudCallback(iri_perception_msgs::PclToDescriptorSet::Request &req, iri_perception_msgs::PclToDescriptorSet::Response &res) 
00046 { 
00047   ROS_DEBUG("FindddAlgNode::get_finddd_from_pointcloudCallback: New Request Received!"); 
00048 
00049 //   sensor_msgs::PointCloud2::Ptr pointcloud(&(req.pointcloud));
00050   res.descriptor_set = get_finddd_from_pointcloud(req.pointcloud);
00051 
00052   return true; 
00053 }
00054 
00055 /*  [action callbacks] */
00056 
00057 /*  [action requests] */
00058 
00059 void FindddAlgNode::node_config_update(Config &config, uint32_t level)
00060 {
00061   this->alg_.lock();
00062   ROS_INFO("Config update");
00063 
00064   this->alg_.unlock();
00065 }
00066 
00067 
00068 void FindddAlgNode::points_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
00069 {
00070   iri_perception_msgs::DescriptorSet descriptor_set = get_finddd_from_pointcloud(*msg);
00071   this->descriptor_publisher_.publish(descriptor_set);
00072 }
00073 
00074 
00075 void FindddAlgNode::addNodeDiagnostics(void)
00076 {
00077 }
00078 
00079 /* main function */
00080 int main(int argc,char *argv[])
00081 {
00082   return algorithm_base::main<FindddAlgNode>(argc, argv, "finddd_alg_node");
00083 }
00084 
00085 
00086 // other functions
00087 
00088 iri_perception_msgs::DescriptorSet FindddAlgNode::get_finddd_from_pointcloud(const sensor_msgs::PointCloud2& ros_pointcloud)
00089 {
00090   clock_t start=clock();
00091   ROS_INFO("Received pointcloud in subscriber");
00092   pcl::PointCloud<pcl::PointXYZ> cloud;
00093   pcl::fromROSMsg(ros_pointcloud, cloud);  
00094   
00095   iri_perception_msgs::DescriptorSet descriptor_set;
00096   this->alg_.compute_ndescs_integral_spatial_interpolation(cloud, descriptor_set);
00097   descriptor_set.header = pcl_conversions::fromPCL(cloud.header);
00098   
00099   this->accumulated_time+=( (double)clock() - start ) / CLOCKS_PER_SEC;
00100   ROS_INFO("Accumulated time %f", this->accumulated_time);
00101   
00102   return descriptor_set;
00103 }


iri_finddd
Author(s): Arnau Ramisa
autogenerated on Fri Dec 6 2013 21:09:52