hole_detection_alg_node.cpp
Go to the documentation of this file.
00001 #include "hole_detection_alg_node.h"
00002 
00003 HoleDetectionAlgNode::HoleDetectionAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<HoleDetectionAlgorithm>(),hole_min_p(60),box_y_end(0),box_z_ini(1),
00005   box_y_ini(-0.1),box_z_end(1.8),box_x(0.9)
00006 {
00007   //init class attributes if necessary
00008   //this->loop_rate_ = 2;//in [Hz]
00009 
00010   // [init publishers]
00011   this->hole_obstacle_publisher_ = this->public_node_handle_.advertise<sensor_msgs::PointCloud>("hole_obstacle", 10);
00012   this->hole_all_publisher_ = this->public_node_handle_.advertise<sensor_msgs::PointCloud2>("hole_zone", 10);
00013   // [init subscribers]
00014   this->input_subscriber_ = this->public_node_handle_.subscribe("input", 10, &HoleDetectionAlgNode::input_callback, this);
00015  
00016         
00017   // [init services]
00018   
00019   // [init clients]
00020   
00021   // [init action servers]
00022   
00023   // [init action clients]
00024 }
00025 
00026 HoleDetectionAlgNode::~HoleDetectionAlgNode(void)
00027 {
00028   // [free dynamic memory]
00029 }
00030 
00031 void HoleDetectionAlgNode::mainNodeThread(void)
00032 {
00033   // [fill msg structures]
00034   //this->PointCloud2_msg_.data = my_var;
00035   
00036   // [fill srv structure and make request to the server]
00037   
00038   // [fill action structure and make request to the action server]
00039 
00040   // [publish messages]
00041 }
00042 //PointCloud2_msg_
00043 /*  [subscriber callbacks] */
00044 void HoleDetectionAlgNode::input_callback(const sensor_msgs::PointCloud2::ConstPtr& msg) 
00045 { 
00046   ROS_INFO("HoleDetectionAlgNode::input_callback: New Message Received"); 
00047 
00048 
00049 
00050   pcl::fromROSMsg (*msg, cloud_in);
00051 
00053   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_for (new pcl::PointCloud<pcl::PointXYZ>);
00054   cloud_for->header.frame_id = cloud_in.header.frame_id;
00055   cloud_for->is_dense=false;
00056   cloud_for->header.stamp = ros::Time::now ();
00058   
00059  //use appropiate mutex to shared variables if necessary 
00060  
00061   this->alg_.lock(); 
00062 
00063   cloud_in_rgb.points.resize(cloud_in.size());
00064   for (size_t i = 0; i < cloud_in.points.size(); i++) {
00065     cloud_in_rgb.points[i].x = cloud_in.points[i].x;
00066     cloud_in_rgb.points[i].y = cloud_in.points[i].y;
00067     cloud_in_rgb.points[i].z = cloud_in.points[i].z;
00068     cloud_in_rgb.points[i].r = 0;
00069     cloud_in_rgb.points[i].g = 0;
00070     cloud_in_rgb.points[i].b = 0;
00071   }
00072   cloud_in_rgb.header.frame_id = cloud_in.header.frame_id;
00073   cloud_in_rgb.height = cloud_in.height;
00074   cloud_in_rgb.width = cloud_in.width;
00075   // cloud_in_rgb.fields=
00076   // cloud_in_rgb.is_bigendian=
00077   // cloud_in_rgb.point_step=
00078   // cloud_in_rgb.row_step=
00079   // cloud_in_rgb.is_dense=
00080 
00081   cloud_in_rgb.is_dense=false;
00082   cloud_in_rgb.header.stamp = ros::Time::now ();
00083 
00084   hole_detect.cloud_all(hole_min_p, box_y_end, box_z_ini, box_x, box_y_ini, box_z_end, Xl, Xc, Xr, Y, cloud_in_rgb, cloud_for);
00085   //unlock previously blocked shared variables 
00086   this->alg_.unlock();  
00087   
00089 
00090         pcl::toROSMsg (*cloud_for, PointCloud2_msg_);
00091   pcl::toROSMsg (cloud_in_rgb, PointCloud2_msg_all);
00092   
00093   sensor_msgs::convertPointCloud2ToPointCloud(PointCloud2_msg_, PointCloud_msg_);
00094 
00095   
00096   this->hole_obstacle_publisher_.publish(this->PointCloud_msg_);
00097   this->hole_all_publisher_.publish(this->PointCloud2_msg_all);
00098   
00099   //use appropiate mutex to shared variables if necessary 
00100   //this->alg_.lock(); 
00101   //this->input_mutex_.enter(); 
00102 
00103   //std::cout << msg->data << std::endl; 
00104 
00105   //unlock previously blocked shared variables 
00106   //this->alg_.unlock(); 
00107   //this->input_mutex_.exit(); 
00108 }
00109 
00110 /*  [service callbacks] */
00111 
00112 /*  [action callbacks] */
00113 
00114 /*  [action requests] */
00115 
00116 void HoleDetectionAlgNode::node_config_update(Config &config, uint32_t level)
00117 {
00118   this->alg_.lock();
00119 hole_min_p=config.hole_min_p;
00120 box_y_end=config.box_y_end;
00121 box_z_ini=config.box_z_ini;
00122 box_z_end=config.box_z_end;
00123 box_y_ini=config.box_y_ini;
00124 box_x=config.box_x;
00125   this->alg_.unlock();
00126 }
00127 
00128 void HoleDetectionAlgNode::addNodeDiagnostics(void)
00129 {
00130 }
00131 
00132 /* main function */
00133 int main(int argc,char *argv[])
00134 {
00135   return algorithm_base::main<HoleDetectionAlgNode>(argc, argv, "hole_detection_alg_node");
00136 }


iri_hole_detection
Author(s): asantamaria
autogenerated on Fri Dec 6 2013 20:21:38