3d_ndt_mcl.h
Go to the documentation of this file.
00001 #ifndef NDT_MCL_3D_HPP_
00002 #define NDT_MCL_3D_HPP_
00003 
00004 #include <pcl/conversions.h>
00005 #include <pcl/point_cloud.h>
00006 #include <pcl/io/pcd_io.h>
00007 #include <pcl/point_types.h>
00008 #include <cstdio>
00009 #include <Eigen/Eigen>
00010 #include <Eigen/Geometry>
00011 #include <fstream>
00012 #include <ndt_map/ndt_map.h>
00013 #include <ndt_map/ndt_cell.h>
00014 #include <ndt_map/pointcloud_utils.h>
00015 #include "ndt_mcl/ParticleFilter3D.h"
00016 #include <tf_conversions/tf_eigen.h>
00017 
00021 class NDTMCL3D{
00022     public:
00023         lslgeneric::NDTMap map;                 
00024         ParticleFilter3D pf;                                            
00025         double resolution;
00026         double resolution_sensor;
00027         int counter;
00028         double zfilt_min;
00029         bool forceSIR;
00033         NDTMCL3D(double map_resolution, lslgeneric::NDTMap &nd_map, double zfilter):
00034             map(new lslgeneric::LazyGrid(map_resolution))
00035         {
00036             isInit = false;
00037             forceSIR = false;
00038             resolution=map_resolution;
00039             resolution_sensor = resolution;
00040             counter = 0;
00041             zfilt_min = zfilter;
00042             sinceSIR = 0;
00045             double cx,cy,cz;
00046             if(!nd_map.getCentroid(cx, cy, cz)){
00047                 fprintf(stderr,"Centroid NOT Given-abort!\n");
00048                 exit(1);
00049             }else{
00050                 fprintf(stderr,"Centroid(%lf,%lf,%lf)\n",cx,cy,cz);
00051             }
00052 
00053             double wx,wy,wz;
00054 
00055             if(!nd_map.getGridSizeInMeters(wx, wy, wz)){
00056                 fprintf(stderr,"Grid size NOT Given-abort!\n");
00057                 exit(1);
00058             }else{
00059                 fprintf(stderr,"GridSize(%lf,%lf,%lf)\n",wx,wy,wz);
00060             }
00061 
00062             map.initialize(cx,cy,cz,wx,wy,wz);
00063 
00064             std::vector<lslgeneric::NDTCell*> ndts;
00065             ndts = nd_map.getAllCells();
00066             fprintf(stderr,"NDT MAP with %d components",ndts.size());
00067             for(unsigned int i=0;i<ndts.size();i++){
00068                 Eigen::Vector3d m = ndts[i]->getMean(); 
00069                 if(m[2]>zfilter){
00070                     Eigen::Matrix3d cov = ndts[i]->getCov();
00071                     unsigned int nump = ndts[i]->getN();
00072                     //fprintf(stderr,"-%d-",nump);
00073                     map.addDistributionToCell(cov, m,nump);
00074                 }
00075             }
00076         }
00077 
00082         void initializeFilter(double x, double y, double z, double roll, double pitch, double yaw,
00083                 double x_e, double y_e, double z_e, double roll_e, double pitch_e, double yaw_e, 
00084                 unsigned int numParticles)
00085         {
00086             pf.initializeNormalRandom(numParticles, x,y,z,roll,pitch, yaw, x_e,y_e,z_e,roll_e,pitch_e,yaw_e);
00087         }
00088 
00089         void updateAndPredict(Eigen::Affine3d Tmotion, pcl::PointCloud<pcl::PointXYZ> &cloud);
00090 
00091         void updateAndPredictEff(Eigen::Affine3d Tmotion, pcl::PointCloud<pcl::PointXYZ> &cloud, double subsample_level);
00092         Eigen::Vector3d getMeanVector(){
00093             return (pf.getMean().translation());
00094             //mcl::pose m = pf.getDistributionMean(true);
00095             //Eigen::Vector3d mm; mm<<m.x,m.y,m.a;
00096             //return mm;
00097         }
00098         Eigen::Affine3d getMean(){
00099             return (pf.getMean());
00100             //mcl::pose m = pf.getDistributionMean(true);
00101             //Eigen::Vector3d mm; mm<<m.x,m.y,m.a;
00102             //return mm;
00103         }
00104 
00105 
00106     private:
00107         bool isInit;
00108         int sinceSIR;
00109         double getDoubleTime()
00110         {
00111             struct timeval time;
00112             gettimeofday(&time,NULL);
00113             return time.tv_sec + time.tv_usec * 1e-6;
00114         }
00115 
00116 };
00117 
00118 #endif
00119 


ndt_mcl
Author(s): Jari Saarinen
autogenerated on Wed Aug 26 2015 15:25:02