Go to the documentation of this file.00001 #include <ndt_mcl/ndt_mcl.h>
00002
00003 void NDTMCL::updateAndPredict(Eigen::Affine3d Tmotion, pcl::PointCloud<pcl::PointXYZ> &cloud){
00004 Eigen::Vector3d tr = Tmotion.translation();
00005 Eigen::Vector3d rot = Tmotion.rotation().eulerAngles(0,1,2);
00006
00007
00017 pf.predict(mcl::pose(tr[0],tr[1],rot[2]), mcl::pose(tr[0]*0.1 + 0.005,tr[1]*0.1+ 0.005,rot[2]*0.1+0.001));
00018
00019 lslgeneric::NDTMap local_map(new lslgeneric::LazyGrid(resolution));
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 local_map.addPointCloudSimple(cloud);
00035
00036 local_map.computeNDTCells(CELL_UPDATE_MODE_STUDENT_T);
00037 int Nn = 0;
00038
00039 for(int i=0;i<pf.NumOfParticles;i++){
00040 Eigen::Affine3d T = getAsAffine(i);
00041
00042 std::vector<lslgeneric::NDTCell*> ndts;
00043 ndts = local_map.pseudoTransformNDT(T);
00044 double score=1;
00045
00046 if(ndts.size()==0) fprintf(stderr,"ERROR no gaussians in measurement!!!\n");
00047 Nn = ndts.size();
00048 for(int n=0;n<ndts.size();n++){
00049 Eigen::Vector3d m = ndts[n]->getMean();
00050 if(m[2]<zfilt_min) continue;
00051
00052 lslgeneric::NDTCell *cell;
00053 pcl::PointXYZ p;
00054 p.x = m[0];p.y=m[1];p.z=m[2];
00055
00056
00057 if(map.getCellForPoint(p,cell)){
00058 if(cell == NULL) continue;
00059 if(cell->hasGaussian_){
00060 Eigen::Matrix3d covCombined = cell->getCov() + ndts[n]->getCov();
00061 Eigen::Matrix3d icov;
00062 bool exists;
00063 double det = 0;
00064 covCombined.computeInverseAndDetWithCheck(icov,det,exists);
00065 if(!exists) continue;
00066 double l = (cell->getMean() - m).dot(icov*(cell->getMean() - m));
00067 if(l*0 != 0) continue;
00068
00069 score += 0.1 + 0.9 * exp(-0.05*l/2.0);
00070 }else{
00071 }
00072 }
00073 }
00074
00075
00076
00077 pf.Particles[i].lik = score;
00078 for(unsigned int j=0;j<ndts.size();j++){
00079 delete ndts[j];
00080 }
00081
00082 }
00083
00084 pf.normalize();
00085
00086
00087 if(forceSIR){
00088
00089 fprintf(stderr, "forceSIR(%d) ",forceSIR);
00090 pf.SIRUpdate();
00091 }else{
00092
00093 double varP=0;
00094 for(int i = 0; i<pf.NumOfParticles;i++){
00095 varP += (pf.Particles[i].p - 1.0/pf.NumOfParticles)*(pf.Particles[i].p - 1.0/pf.NumOfParticles);
00096 }
00097 varP /= pf.NumOfParticles;
00098 varP = sqrt(varP);
00099 fprintf(stderr,"Var P=%lf (Npf=%d, Nm=%d)",varP,pf.NumOfParticles, Nn);
00100 if(varP > 0.006 || sinceSIR >25){
00101 fprintf(stderr,"-SIR- ");
00102 sinceSIR = 0;
00103 pf.SIRUpdate();
00104 }else{
00105 sinceSIR++;
00106 }
00107
00108 }
00109 }