PaFil.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00030 
00032 /* @{ */
00033 
00034 #ifndef __PAR_FIL_H_
00035 #define __PAR_FIL_H_
00036 
00037 #include "MutLoc.h"
00038 
00039 namespace MipAlgorithms{
00042  typedef enum{
00043   ABS,
00044   REL
00045  }ParticleFilterType;
00046 };
00047 
00048 
00049 namespace MipAlgorithms{
00053  class Particle {     // Per ogni singola particella 
00054  //ho incominciato a scrivere i campi che sicuramente ci dovranno essere e che usa il resampling
00055   public:
00057    Decimal weight;
00059    Pose p;
00060    
00062    Particle(){
00063    }
00064    
00066    Particle ( Pose a, Decimal w){
00067     p=a;
00068     weight=w;
00069     }
00070  
00072    Particle(const Particle &A){
00073     p     = A.p;
00074     weight= A.weight;
00075    }
00076  
00078    void operator= (const Particle &A){
00079     p     = A.p;
00080     weight= A.weight;
00081    } 
00082    
00084    string print(){
00085     stringstream s;
00086     s << "weight:" << this -> weight << endl << "Pose:" << this -> p.print();
00087     return s.str();
00088    }
00089  };
00090 }; // end namespace MipAlgorithms
00091 
00092 
00093 namespace MipAlgorithms{
00098  class ParFilParams{
00099   public:
00100  /*  
00102    FilterType filterType;
00103  */
00105    int numPart; 
00107    Decimal sigma_xx;
00109    Decimal sigma_yy;
00111    Decimal sigma_thetatheta;
00113    Decimal severity_xx;
00115    Decimal severity_yy;
00117    Decimal severity_thetatheta;
00119    int factor;
00121    int hisId;
00123    ParticleFilterType type;
00125    int tempo_in;
00127    ParFilParams(){
00128    }
00129    
00131    ParFilParams( int N, Decimal sx , Decimal sy, Decimal sth, Decimal sev_x , Decimal sev_y, Decimal sev_th, int fac, int hId, ParticleFilterType ty, int tmp){
00132     sigma_xx     = sx;
00133     sigma_yy    = sy;
00134     sigma_thetatheta = sth;
00135     severity_xx = sev_x;
00136     severity_yy = sev_y;
00137     severity_thetatheta = sev_th;
00138     numPart    = N;
00139     factor   = fac;
00140     hisId  = hId;
00141     type  = ty;
00142     tempo_in = tmp; 
00143    }
00144  
00146    ParFilParams(const ParFilParams &A){
00147     sigma_xx     = A.sigma_xx;
00148     sigma_yy    =  A.sigma_yy;
00149     sigma_thetatheta = A.sigma_thetatheta;
00150     severity_xx = A.severity_xx;
00151     severity_yy = A.severity_yy;
00152     severity_thetatheta = A.severity_thetatheta;
00153     numPart    = A.numPart;
00154     factor  = A.factor;
00155     hisId  = A.hisId;
00156     type  = A.type;  
00157     tempo_in = A.tempo_in; 
00158    }
00159  
00161    void operator= (const ParFilParams &A){
00162     sigma_xx      = A.sigma_xx;
00163     sigma_yy     =  A.sigma_yy;
00164     sigma_thetatheta = A.sigma_thetatheta;
00165     severity_xx = A.severity_xx;
00166     severity_yy = A.severity_yy;
00167     severity_thetatheta = A.severity_thetatheta;
00168     numPart     = A.numPart;
00169     factor  = A.factor;
00170     hisId  = A.hisId;
00171     type  = A.type;
00172     tempo_in = A.tempo_in;
00173    } 
00174    
00176    string print(){
00177     stringstream s;
00178     s << "Stampa ParFilParams: " << endl;
00179     s << "sigma_xx = " << sigma_xx << endl;
00180     s << "sigma_yy = " << sigma_yy << endl;
00181     s << "sigma_thetatheta = " << sigma_thetatheta << endl;
00182     s << "severity_xx = " << severity_xx << endl;
00183     s << "severity_yy = " << severity_yy << endl;
00184     s << "severity_thetatheta = " << severity_thetatheta << endl;
00185     s << "numPart = " << numPart << endl;
00186     s << "factor = " << factor << endl;
00187     s << "hisId = " << hisId << endl;
00188     s << "tempo_corrente = " << tempo_in << endl;
00189     if (type==ABS) s << "type = ABS" << endl;
00190     else  s << "type = REL" << endl;
00191     return s.str();
00192    }
00193  };
00194 }; // end namespace MipAlgorithms
00195 
00196 
00197 namespace MipAlgorithms{
00201  class ParFilVariables{
00202   public:
00204    int step;
00206    vector<Particle> map;
00208    Pose Ixi_tmeno1;
00210    Pose Jxj_tmeno1;
00212    Pose bestIxJ_mean;
00214    Pose bestIxJ_winner;
00216    int bestParticle;
00218    Pose myLastConf;
00220    Pose hisLastConf;
00221    
00222    
00224    ParFilVariables (){
00225     step = 0;
00226     Ixi_tmeno1 = Pose (); 
00227     Jxj_tmeno1 = Pose (); 
00228     bestIxJ_mean = Pose ();
00229     bestIxJ_winner = Pose ();
00230     bestParticle=0;
00231     myLastConf = Pose();  
00232     hisLastConf = Pose(); 
00233    }
00234    
00236    ParFilVariables(const ParFilVariables &A){
00237     //un nuovo oggetto parFilVariables coi campi uguali
00238     step  = A.step;
00239     Ixi_tmeno1 = A.Ixi_tmeno1;
00240     Jxj_tmeno1 = A.Jxj_tmeno1;
00241     bestIxJ_mean = A.bestIxJ_mean;
00242     bestIxJ_winner = A.bestIxJ_winner;
00243     bestParticle = A.bestParticle;
00244     myLastConf = A.myLastConf;  
00245     hisLastConf = A.hisLastConf; 
00246     map = A.map; //Rivedere!!!!!!!!!
00247     }
00248    
00250    ParFilVariables operator=(ParFilVariables &A){
00251     step  = A.step;
00252     Ixi_tmeno1 = A.Ixi_tmeno1;
00253     Jxj_tmeno1 = A.Jxj_tmeno1;
00254     bestIxJ_mean = A.bestIxJ_mean;
00255     bestIxJ_winner = A.bestIxJ_winner;
00256     bestParticle = A.bestParticle;
00257     myLastConf = A.myLastConf;  
00258     hisLastConf = A.hisLastConf;
00259    }
00260    
00262    ~ParFilVariables(){
00263     //Particle.clear();
00264     map.clear();
00265    }
00266    
00268    string print(){
00269     stringstream s;
00270     s << endl;
00271     s << "Step: " << step << endl;
00272     s << "Ixi_tmeno1 = " << Ixi_tmeno1.print() << endl;
00273     s << "Jxj_tmeno1 = " << Jxj_tmeno1.print() << endl;
00274     s << "bestIxJ_mean = " << bestIxJ_mean.print() << endl;
00275     s << "bestIxJ_winner = " << bestIxJ_winner.print() << endl;
00276     s << "bestParticle = " << bestParticle << endl;
00277     s << "myLastConf = " << myLastConf.print() << endl; 
00278     s << "hisLastConf = " << hisLastConf.print() << endl;
00279     return s.str();
00280    }
00281  };
00282 };// end namespace MipAlgorithms
00283 
00284 
00285 namespace MipAlgorithms{
00289  class ParticleFilter : public MutLocFilter{
00290   public:
00291    
00292    //costruttori
00294    ParticleFilter(){
00295    }
00296  
00298    ParticleFilter(ParFilParams in){
00299     par = in;
00300     var = (ParFilVariables*) new ParFilVariables();
00301     init();
00302    }
00303    
00304    //metodi virtuali della classe genitore
00306    void step(MutLocFilInput &input);
00307    
00309    void reset(){} //qua dobbiamo eliminare i risultati delle operazioni fatte
00310    
00312    void getInternalEstimate(MutLocFilInput &input, vector<Particle> &last_map);
00313    
00315    void getInternalEstimate_abs(MutLocFilInput &input, vector<Particle> &last_map);
00316    
00318    void getInternalEstimate_rel(MutLocFilInput &input, vector<Particle> &last_map);
00319    
00322    int getEstimate(Pose* best);
00323    
00326    int getAllEstimates(vector<Pose> &all, vector<Decimal> &allMarks);
00327    
00329    void updateVar(MutLocFilInput &input, vector<Particle> &last_map, int &caso);
00330    
00332    string print();
00333  
00335    void reset(ParFilParams inPar){
00336     assert(initialized());
00337     par = inPar;
00338     var->step = 0;
00339     var->Ixi_tmeno1 = Pose();
00340     var->Jxj_tmeno1 = Pose();
00341     var->map.clear();
00342    }
00343    
00345    int getStep(){
00346     assert(initialized());
00347     return var->step;
00348    }
00349  
00351    Pose getIxi(){
00352     assert(initialized());
00353     return var->Ixi_tmeno1;
00354    }
00355    
00357    Pose getJxj(){
00358     assert(initialized());
00359     return var->Jxj_tmeno1;
00360    }
00361    
00363    void ComputeWeights (MutLocFilInput &input, int &caso);
00364    
00366    void ComputeWeights_abs (MutLocFilInput &input, int &caso);
00367    
00369    void ComputeWeights_rel (MutLocFilInput &input, int &caso);
00370    
00373    vector<Particle> Resample();
00374    
00376    void OutputPerformance (MutLocFilInput &input) ;
00377    
00378   protected:
00380    ParFilParams par;
00382    ParFilVariables *var;
00383    
00384   private:
00386    void CreateMap_abs(MutLocFilInput &input);
00387    
00389    void CreateMap_rel(MutLocFilInput &input);
00390    
00392    void PropagateMap(MutLocFilInput &input, int &caso);
00393    
00395    void PropagateMap_abs(MutLocFilInput &input, int &caso);
00396    
00398    void PropagateMap_rel(MutLocFilInput &input, int &caso);
00399    
00402    Pose* gaussPose(int &factor);
00403    
00405    void normalStep(MutLocFilInput &input);
00406    
00408    void firstStep(MutLocFilInput &input);
00409    
00411    void NormalizeWeights(int &caso);
00412  };
00413 }; // end namespace MipAlgorithms
00414 
00415 #endif
00416 
00417 
00418 
00419 
00420 
00421 

Generated on Mon Feb 20 07:01:06 2017 for MIP by  doxygen 1.5.6