lasers_to_pointcloud_alg_node.cpp
Go to the documentation of this file.
00001 #include "lasers_to_pointcloud_alg_node.h"
00002 
00003 LasersToPointcloudAlgNode::LasersToPointcloudAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<LasersToPointcloudAlgorithm>()
00005 {
00006   //init class attributes if necessary
00007   //this->loop_rate_ = 2;//in [Hz]
00008 
00009   counter_ = 0;
00010   new_scan1_ = new_scan2_ = false;
00011 
00012   // [init publishers]
00013   this->cloud_publisher_ = this->public_node_handle_.advertise<sensor_msgs::PointCloud2>("cloud", 100);
00014 
00015   // [init subscribers]
00016   this->scan2_subscriber_ = this->public_node_handle_.subscribe("scan2", 100, &LasersToPointcloudAlgNode::scan2_callback, this);
00017   this->scan1_subscriber_ = this->public_node_handle_.subscribe("scan1", 100, &LasersToPointcloudAlgNode::scan1_callback, this);
00018 
00019 
00020   // [init services]
00021 
00022   // [init clients]
00023 
00024   // [init action servers]
00025 
00026   // [init action clients]
00027 }
00028 
00029 LasersToPointcloudAlgNode::~LasersToPointcloudAlgNode(void)
00030 {
00031   // [free dynamic memory]
00032 }
00033 
00034 void LasersToPointcloudAlgNode::mainNodeThread(void)
00035 {
00036   // [fill msg structures]
00037 
00038   // [fill srv structure and make request to the server]
00039 
00040   // [fill action structure and make request to the action server]
00041 
00042   // [publish messages]
00043   if(new_scan1_ && new_scan2_)
00044   {
00045 //    cloud_publisher_.publish(cloud1_);
00046 
00047     scan1_mutex_.enter();
00048     scan2_mutex_.enter();
00049       std::vector<unsigned char> all_data(cloud2_.data);
00050       all_data.reserve(cloud1_.data.size() + cloud2_.data.size());
00051       all_data.insert(all_data.end(), cloud1_.data.begin(), cloud1_.data.end());
00052       PointCloud2_msg_.header.seq      = counter_++;
00053       PointCloud2_msg_.header.stamp    = ros::Time::now(); //cloud1_.header.stamp;
00054       PointCloud2_msg_.header.frame_id = alg_.config_.base_frame; //cloud1_.header.frame_id;
00055       PointCloud2_msg_.fields          = cloud1_.fields;
00056       PointCloud2_msg_.is_bigendian    = cloud1_.is_bigendian;
00057       PointCloud2_msg_.point_step      = cloud1_.point_step;
00058       PointCloud2_msg_.row_step        = cloud1_.row_step;
00059       PointCloud2_msg_.is_dense        = cloud1_.is_dense;
00060       PointCloud2_msg_.height          = cloud1_.height;
00061       PointCloud2_msg_.width           = cloud1_.width+cloud2_.width;
00062       PointCloud2_msg_.data            = all_data;
00063     scan2_mutex_.exit();
00064     scan1_mutex_.exit();
00065 
00066     new_scan1_ = new_scan2_ = false;
00067 
00068     cloud_publisher_.publish(PointCloud2_msg_);
00069     ROS_DEBUG("Cloud published. Cloud stamp: %f width: %d height: %d",
00070               PointCloud2_msg_.header.stamp.toSec(),PointCloud2_msg_.width,PointCloud2_msg_.height);
00071 
00072   }
00073 }
00074 
00075 /*  [subscriber callbacks] */
00076 void LasersToPointcloudAlgNode::scan2_callback(const sensor_msgs::LaserScan::ConstPtr& msg)
00077 {
00078   bool t;
00079   scan2_mutex_.enter();
00080     sensor_msgs::PointCloud2 cloud;
00081     laser_projector_.projectLaser(*msg, cloud);
00082     t = pcl_ros::transformPointCloud (alg_.config_.base_frame, cloud, cloud2_, tfl_);
00083   scan2_mutex_.exit();
00084   if (t){
00085     new_scan2_ = true;
00086   }
00087 }
00088 void LasersToPointcloudAlgNode::scan1_callback(const sensor_msgs::LaserScan::ConstPtr& msg)
00089 {
00090   bool t;
00091   scan1_mutex_.enter();
00092     sensor_msgs::PointCloud2 cloud;
00093     laser_projector_.projectLaser(*msg, cloud);
00094     t = pcl_ros::transformPointCloud (alg_.config_.base_frame, cloud, cloud1_, tfl_);
00095   scan1_mutex_.exit();
00096    if (t){
00097      new_scan1_ = true;
00098    }
00099 }
00100 
00101 /*  [service callbacks] */
00102 
00103 /*  [action callbacks] */
00104 
00105 /*  [action requests] */
00106 
00107 void LasersToPointcloudAlgNode::node_config_update(Config &config, uint32_t level)
00108 {
00109   this->alg_.lock();
00110 
00111   this->alg_.unlock();
00112 }
00113 
00114 void LasersToPointcloudAlgNode::addNodeDiagnostics(void)
00115 {
00116 }
00117 
00118 /* main function */
00119 int main(int argc,char *argv[])
00120 {
00121   return algorithm_base::main<LasersToPointcloudAlgNode>(argc, argv, "lasers_to_pointcloud_alg_node");
00122 }
00123 
00124 


iri_lasers_to_pointcloud
Author(s): mmorta
autogenerated on Fri Dec 6 2013 23:01:11