noise_gen.cpp
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2010
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name:
00012  * ROS package name:
00013  * Description:
00014  *
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *
00017  * Author:
00018  * Supervised by:
00019  *
00020  * Date of creation:
00021  * ToDo:
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Fraunhofer Institute for Manufacturing
00034  *       Engineering and Automation (IPA) nor the names of its
00035  *       contributors may be used to endorse or promote products derived from
00036  *       this software without specific prior written permission.
00037  *
00038  * This program is free software: you can redistribute it and/or modify
00039  * it under the terms of the GNU Lesser General Public License LGPL as
00040  * published by the Free Software Foundation, either version 3 of the
00041  * License, or (at your option) any later version.
00042  *
00043  * This program is distributed in the hope that it will be useful,
00044  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00045  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00046  * GNU Lesser General Public License LGPL for more details.
00047  *
00048  * You should have received a copy of the GNU Lesser General Public
00049  * License LGPL along with this program.
00050  * If not, see <http://www.gnu.org/licenses/>.
00051  *
00052  ****************************************************************/
00053 
00054 //##################
00055 //#### includes ####
00056 
00057 // standard includes
00058 //--
00059 
00060 // ROS includes
00061 #include <ros/ros.h>
00062 #include <pcl_conversions/pcl_conversions.h>
00063 
00064 // ROS message includes
00065 #include <std_msgs/String.h>
00066 #include <sensor_msgs/PointCloud2.h>
00067 
00068 
00069 // ROS service includes
00070 
00071 // external includes
00072 //--
00073 #include <boost/random/normal_distribution.hpp>
00074 #include <boost/random.hpp>
00075 
00076 #include <pcl/point_cloud.h>
00077 #include <pcl/point_types.h>
00078 #include <pcl/conversions.h>
00079 //####################
00080 //#### node class ####
00081 class noise_gen
00082 {
00083   //
00084 public:
00085   // create a handle for this node, initialize node
00086   ros::NodeHandle n;
00087 
00088   // topics to publish
00089   ros::Publisher pub_;
00090 
00091   // topics to subscribe, callback is called for new messages arriving
00092   ros::Subscriber sub_;
00093 
00094   // service servers
00095   //--
00096 
00097   // service clients
00098   //--
00099 
00100   // global variables
00101   //--
00102 
00103 
00104 
00105 
00106 
00107 
00108   // Constructor
00109   noise_gen()
00110   {
00111 
00112     std::string in_topic,out_topic;
00113     in_topic = "cloud_in";
00114     out_topic = "cloud_out";
00115 
00116 
00117     pub_ = n.advertise<sensor_msgs::PointCloud2>(out_topic, 1);
00118     sub_ = n.subscribe(in_topic, 1, &noise_gen::cloud_callback, this);
00119   }
00120 
00121   // Destructor
00122   ~noise_gen()
00123   {
00124   }
00125 
00126   double random_number_kinect(double z)
00127   {
00128 
00129 
00130     double mean = 0.0;
00131 
00132     float sigma;
00133 
00134 
00135 
00136     sigma= ((5*z*z)/100000);
00137 
00138     //    std::cout<<"Z---"<<z<<std::endl;
00139 
00140     //    std::cout<<"SIGMA---"<<sigma<<std::endl;
00141 
00142 
00143 
00144 
00145 
00146     typedef boost::normal_distribution<double> NormalDistribution;
00147     typedef boost::mt19937 RandomGenerator;
00148     typedef boost::variate_generator<RandomGenerator&,NormalDistribution> GaussianGenerator;
00150     static RandomGenerator rng(static_cast<unsigned> (time(0)));
00151 
00152     /* Choose Normal Distribution */
00153     NormalDistribution gaussian_dist(mean, sigma);
00154 
00155     /* Create a Gaussian Random Number generator
00156      *  by binding with previously defined
00157      *  normal distribution object
00158      */
00159     GaussianGenerator generator(rng, gaussian_dist);
00160     return generator();
00161   }
00162 
00163   double random_number_static(double sigma)
00164   {
00165 
00166 
00167     double mean = 0.0;
00168 
00169 
00170 
00171 
00172 
00173 
00174     typedef boost::normal_distribution<double> NormalDistribution;
00175     typedef boost::mt19937 RandomGenerator;
00176     typedef boost::variate_generator<RandomGenerator&,NormalDistribution> GaussianGenerator;
00178     static RandomGenerator rng(static_cast<unsigned> (time(0)));
00179 
00180     /* Choose Normal Distribution */
00181     NormalDistribution gaussian_dist(mean, sigma);
00182 
00183     /* Create a Gaussian Random Number generator
00184      *  by binding with previously defined
00185      *  normal distribution object
00186      */
00187     GaussianGenerator generator(rng, gaussian_dist);
00188     return generator();
00189   }
00190 
00191   // topic callback functions
00192   // function will be called when a new message arrives on a topic
00193   void cloud_callback(const sensor_msgs::PointCloud2 cloud_in)
00194   {
00195 
00196 
00197 
00198 
00199     bool bin_mode = true;
00200     double sigma = 0.002;
00201 
00202 
00203     sensor_msgs::PointCloud2 out_msg;
00204     pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_work (new pcl::PointCloud<pcl::PointXYZRGB>);
00205     //pcl::fromROSMsg(cloud_in,*cloud_work);
00206     pcl::PCLPointCloud2 cloud_work2;
00207     pcl_conversions::toPCL(out_msg, cloud_work2);
00208     pcl::fromPCLPointCloud2(cloud_work2, *cloud_work);
00209 
00210 
00211 
00212     for (size_t i = 0; i < cloud_work->points.size(); ++i) {
00213       //      cloud_work->points[i].x +=random_number();
00214       //      cloud_work->points[i].y +=random_number();
00215 
00216       if ( isnan( cloud_work->points[i].z)==true)
00217       {
00218         continue;
00219       }
00220       else
00221       {
00222         if(bin_mode==true)
00223         {
00224 //          double z_float=  cloud_work->points[i].z+random_number_kinect(cloud_work->points[i].z);
00225           double z_float=  cloud_work->points[i].z+random_number_static(sigma);
00226 
00227 
00228           double z_bin =round(1090-(348/z_float));
00229 
00230           cloud_work->points[i].z = (-348/(z_bin-1090));
00231         }
00232         else
00233           cloud_work->points[i].z += random_number_static(sigma);
00234       }
00235 
00236     }
00237     pcl::toPCLPointCloud2(*cloud_work, cloud_work2);
00238     pcl_conversions::fromPCL(cloud_work2, out_msg);
00239     //pcl::toROSMsg(*cloud_work,out_msg);
00240 
00241     pub_.publish(out_msg);
00242 
00243   }
00244 
00245 
00246 };
00247 
00248 
00249 
00250 //#######################
00251 //#### main programm ####
00252 int main (int argc, char** argv)
00253 {
00254   ros::init (argc, argv, "eval_node");
00255   noise_gen nodeClass;
00256 
00257   while(nodeClass.n.ok())
00258   {
00259 
00260     ros::spinOnce();
00261   }
00262 
00263   //    ros::spin();
00264 
00265   return 0;
00266 }
00267 
00268 


cob_3d_mapping_tools
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:04:27