CLPaFil.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00030
00032
00033
00034 #ifndef __CL_PAR_FIL_H_
00035 #define __CL_PAR_FIL_H_
00036
00040 class Particle {
00041 public:
00043 Decimal weight;
00045 Pose p;
00046
00048 Particle(){
00049 }
00050
00052 Particle ( Pose a, Decimal w){
00053 p=a;
00054 weight=w;
00055 }
00056
00058 Particle(const Particle &A){
00059 p = A.p;
00060 weight= A.weight;
00061 }
00062
00064 void operator= (const Particle &A){
00065 p = A.p;
00066 weight= A.weight;
00067 }
00068
00070 string print(){
00071 stringstream s;
00072 s << "weight:" << this -> weight << endl << "Pose:" << this -> p.print();
00073 return s.str();
00074 }
00075 };
00076
00081 class CLPaFilParams{
00082 public:
00083
00085
00086
00088 int numPart;
00090 Decimal sigma_xx;
00092 Decimal sigma_yy;
00094 Decimal sigma_thetatheta;
00096 Decimal severity_xx;
00098 Decimal severity_yy;
00100 Decimal severity_thetatheta;
00102 int factor;
00104 int hisId;
00106 ParticleFilterType type;
00108 int tempo_in;
00110 CLPaFilParams(){
00111 }
00112
00114 CLPaFilParams( 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){
00115 sigma_xx = sx;
00116 sigma_yy = sy;
00117 sigma_thetatheta = sth;
00118 severity_xx = sev_x;
00119 severity_yy = sev_y;
00120 severity_thetatheta = sev_th;
00121 numPart = N;
00122 factor = fac;
00123 hisId = hId;
00124 type = ty;
00125 tempo_in = tmp;
00126 }
00127
00129 CLPaFilParams(const CLPaFilParams &A){
00130 sigma_xx = A.sigma_xx;
00131 sigma_yy = A.sigma_yy;
00132 sigma_thetatheta = A.sigma_thetatheta;
00133 severity_xx = A.severity_xx;
00134 severity_yy = A.severity_yy;
00135 severity_thetatheta = A.severity_thetatheta;
00136 numPart = A.numPart;
00137 factor = A.factor;
00138 hisId = A.hisId;
00139 type = A.type;
00140 tempo_in = A.tempo_in;
00141 }
00142
00144 void operator= (const CLPaFilParams &A){
00145 sigma_xx = A.sigma_xx;
00146 sigma_yy = A.sigma_yy;
00147 sigma_thetatheta = A.sigma_thetatheta;
00148 severity_xx = A.severity_xx;
00149 severity_yy = A.severity_yy;
00150 severity_thetatheta = A.severity_thetatheta;
00151 numPart = A.numPart;
00152 factor = A.factor;
00153 hisId = A.hisId;
00154 type = A.type;
00155 tempo_in = A.tempo_in;
00156 }
00157
00159 string print(){
00160 stringstream s;
00161 s << "Stampa CLPaFilParams: " << endl;
00162 s << "sigma_xx = " << sigma_xx << endl;
00163 s << "sigma_yy = " << sigma_yy << endl;
00164 s << "sigma_thetatheta = " << sigma_thetatheta << endl;
00165 s << "severity_xx = " << severity_xx << endl;
00166 s << "severity_yy = " << severity_yy << endl;
00167 s << "severity_thetatheta = " << severity_thetatheta << endl;
00168 s << "numPart = " << numPart << endl;
00169 s << "factor = " << factor << endl;
00170 s << "hisId = " << hisId << endl;
00171 s << "tempo_corrente = " << tempo_in << endl;
00172 if (type==ABS) s << "type = ABS" << endl;
00173 else s << "type = REL" << endl;
00174 return s.str();
00175 }
00176 };
00177
00181 class CLPaFilVariables{
00182 public:
00184 int step;
00186 vector<Particle> map;
00188 Pose Ixi_tmeno1;
00190 Pose Jxj_tmeno1;
00192 Pose bestIxJ_mean;
00194 Pose bestIxJ_winner;
00196 int bestParticle;
00198 Pose myLastConf;
00200 Pose hisLastConf;
00201
00202
00204 CLPaFilVariables (){
00205 step = 0;
00206 Ixi_tmeno1 = Pose ();
00207 Jxj_tmeno1 = Pose ();
00208 bestIxJ_mean = Pose ();
00209 bestIxJ_winner = Pose ();
00210 bestParticle=0;
00211 myLastConf = Pose();
00212 hisLastConf = Pose();
00213 }
00214
00216 CLPaFilVariables(const CLPaFilVariables &A){
00217
00218 step = A.step;
00219 Ixi_tmeno1 = A.Ixi_tmeno1;
00220 Jxj_tmeno1 = A.Jxj_tmeno1;
00221 bestIxJ_mean = A.bestIxJ_mean;
00222 bestIxJ_winner = A.bestIxJ_winner;
00223 bestParticle = A.bestParticle;
00224 myLastConf = A.myLastConf;
00225 hisLastConf = A.hisLastConf;
00226 map = A.map;
00227 }
00228
00230 CLPaFilVariables operator=(CLPaFilVariables &A){
00231 step = A.step;
00232 Ixi_tmeno1 = A.Ixi_tmeno1;
00233 Jxj_tmeno1 = A.Jxj_tmeno1;
00234 bestIxJ_mean = A.bestIxJ_mean;
00235 bestIxJ_winner = A.bestIxJ_winner;
00236 bestParticle = A.bestParticle;
00237 myLastConf = A.myLastConf;
00238 hisLastConf = A.hisLastConf;
00239 }
00240
00242 ~CLPaFilVariables(){
00243
00244 map.clear();
00245 }
00246
00248 string print(){
00249 stringstream s;
00250 s << endl;
00251 s << "Step: " << step << endl;
00252 s << "Ixi_tmeno1 = " << Ixi_tmeno1.print() << endl;
00253 s << "Jxj_tmeno1 = " << Jxj_tmeno1.print() << endl;
00254 s << "bestIxJ_mean = " << bestIxJ_mean.print() << endl;
00255 s << "bestIxJ_winner = " << bestIxJ_winner.print() << endl;
00256 s << "bestParticle = " << bestParticle << endl;
00257 s << "myLastConf = " << myLastConf.print() << endl;
00258 s << "hisLastConf = " << hisLastConf.print() << endl;
00259 return s.str();
00260 }
00261 };
00262
00263
00267 class ParticleFilter : public LocFilter{
00268 public:
00269
00270
00272 ParticleFilter(){
00273 }
00274
00276 ParticleFilter(CLPaFilParams in){
00277 par = in;
00278 var = (CLPaFilVariables*) new CLPaFilVariables();
00279 init();
00280 }
00281
00282
00284 void step(LocFilInput &input);
00285
00287 void reset(){}
00288
00290 void getInternalEstimate(LocFilInput &input, vector<Particle> &last_map);
00291
00293 void getInternalEstimate_abs(LocFilInput &input, vector<Particle> &last_map);
00294
00296 void getInternalEstimate_rel(LocFilInput &input, vector<Particle> &last_map);
00297
00300 int getEstimate(Pose* best);
00301
00304 int getAllEstimates(vector<Pose> &all, vector<Decimal> &allMarks);
00305
00307 void updateVar(LocFilInput &input, vector<Particle> &last_map, int &caso);
00308
00310 string print();
00311
00313 void reset(CLPaFilParams inPar){
00314 assert(initialized());
00315 par = inPar;
00316 var->step = 0;
00317 var->Ixi_tmeno1 = Pose();
00318 var->Jxj_tmeno1 = Pose();
00319 var->map.clear();
00320 }
00321
00323 int getStep(){
00324 assert(initialized());
00325 return var->step;
00326 }
00327
00329 Pose getIxi(){
00330 assert(initialized());
00331 return var->Ixi_tmeno1;
00332 }
00333
00335 Pose getJxj(){
00336 assert(initialized());
00337 return var->Jxj_tmeno1;
00338 }
00339
00341 void ComputeWeights (LocFilInput &input, int &caso);
00342
00344 void ComputeWeights_abs (LocFilInput &input, int &caso);
00345
00347 void ComputeWeights_rel (LocFilInput &input, int &caso);
00348
00351 vector<Particle> Resample();
00352
00354 void OutputPerformance (LocFilInput &input) ;
00355
00356 protected:
00358 CLPaFilParams par;
00360 CLPaFilVariables *var;
00361
00362 private:
00364 void CreateMap_abs(LocFilInput &input);
00365
00367 void CreateMap_rel(LocFilInput &input);
00368
00370 void PropagateMap(LocFilInput &input, int &caso);
00371
00373 void PropagateMap_abs(LocFilInput &input, int &caso);
00374
00376 void PropagateMap_rel(LocFilInput &input, int &caso);
00377
00380 Pose* gaussPose(int &factor);
00381
00383 void normalStep(LocFilInput &input);
00384
00386 void firstStep(LocFilInput &input);
00387
00389 void NormalizeWeights(int &caso);
00390 };
00391
00392
00393
00394 #endif
00395
00396
00397
00398
00399
00400