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 #include "baselib.h"
00027 #include "LogTrace.h"
00028 #include <Option.h>
00029 #include "ProbMultiRegCam3D.h"
00030 #include <PaFilBFLRelRelBearOnly3D.h>
00031 #include <PaFilBFLRelRelBearOnly3Dvel.h>
00032 #include <PaFilBFLRelRelBearOnly3DvelUpdate.h>
00033 #include <DraWinGL.h>
00034
00038 #ifndef __PROB_MUTLOCQUAD_H_
00039 #define __PROB_MUTLOCQUAD_H_
00040
00041 #define DEBUGMUTLOCQUAD 0
00042
00043
00044 #define WORLDGRAVITY 9.81
00045
00046 typedef MipBaselib::IMUOdometry IMUData;
00047
00048 namespace kybalg{
00053 class IMUDataTime{
00054 private:
00055 IMUData IMUDatas;
00056 long int _ttSec;
00057 long int _ttUSec;
00058 Angle actualRoll;
00059 Angle actualPitch;
00060 public:
00062 IMUDataTime();
00063
00065 IMUDataTime(Acceleration3D la, Velocity3D av,long int ttSec, long int ttUSec,Angle roll,Angle pitch);
00066
00068 IMUDataTime(IMUData bs, long int ttSec, long int ttUSec,Angle roll,Angle pitch);
00069
00071 ~IMUDataTime();
00072
00074 void setTimeSec(long int sec);
00075
00077 void setTimeUSec(long int usec);
00078
00080 void setTime(long int sec, long int usec);
00081
00083 long int getTimeSec();
00084
00086 long int getTimeUSec();
00087
00089 bool overTime(long int sec, long int usec);
00090
00092 bool underTime(long int sec, long int usec);
00093
00095 Decimal getTime();
00096
00098 bool underTime(Decimal sec);
00099
00101 bool overTime(Decimal sec);
00102
00104 void setXLinAcc(Decimal x);
00105
00107 void setYLinAcc(Decimal y);
00108
00110 void setZLinAcc(Decimal z);
00111
00113 void setLinAcc(Acceleration3D la);
00114
00116 void setXAngVel(Decimal x);
00117
00119 void setYAngVel(Decimal y);
00120
00122 void setZAngVel(Decimal z);
00123
00125 void setAngVel(Velocity3D av);
00126
00128 Acceleration3D getLinAcc();
00129
00131 Velocity3D getAngVel();
00132
00134 IMUData getIMUData();
00135
00137 Angle getActualRoll();
00138
00140 Angle getActualPitch();
00141
00143 void setActualRoll(Angle roll);
00144
00146 void setActualPitch(Angle pitch);
00147
00149 void setActualRoll(Decimal roll);
00150
00152 void setActualPitch(Decimal pitch);
00153 };
00154
00159 class mutLocState{
00160 private:
00161 Velocity3D _vel;
00162 Pose3D _pos;
00163 int _id;
00164 public:
00165
00167 mutLocState();
00168
00170 mutLocState(int id, Pose3D pos,Velocity3D vel);
00171
00173 ~mutLocState();
00174
00176 Velocity3D getVel();
00177
00179 Pose3D getPose();
00180
00182 int getId();
00183
00185 void setVel(Velocity3D vel);
00186
00188 void setPose(Pose3D pos);
00189
00191 void setId(int id);
00192
00194 mutLocState& operator=(const mutLocState &A);
00195 };
00196
00197
00198 typedef vector<mutLocState> actualForm;
00199
00200
00201 typedef vector<actualForm> totalForm;
00202 };
00203
00204 namespace kybalg{
00208 class MutLocQuadPar{
00209 private:
00210
00211 Decimal _linearTollerance;
00212
00213 Decimal _angularTollerance;
00214
00215 Decimal _projTollerance;
00216
00217 Decimal _zenithTollerance;
00218
00219 int _expandMethod;
00220
00221 bool _saveEstimates;
00222
00223 bool _saveMultiRegCam;
00224
00225 Decimal _thrTimeSec;
00226
00227 Decimal _thrTimeUSec;
00228
00229 string _rootFileMeasOff;
00230
00231 string _rootFileTStateOff;
00232
00233 string _rootFileIdsOff;
00234
00235 string _rootFileIMUConfigOff;
00236
00237 string _rootFiles;
00238
00239 Decimal _timeForMeasUpdate;
00240
00241 int _minObSize;
00242
00243 bool _embVis;
00244
00245 bool _printForm;
00246
00247 bool _printFormDetails;
00248
00249 bool _loadFromAbsFile;
00250
00251 string _rootAbsPosFile;
00252
00253 bool _saveAllParticles;
00254
00255 bool _readVelFile;
00256
00257 bool _saveCompleteStateFilter;
00258
00259 bool _saveRelAbs;
00260
00261 bool _saveBestEstimate;
00262
00263 bool _doOnlyFilter;
00264
00265 int _filterType;
00266
00267 Decimal _noiseBear;
00268
00269 Decimal _delayBear;
00270
00271 Decimal _timeStartOffset;
00272
00273 public:
00274
00276 MutLocQuadPar();
00277
00279 ~MutLocQuadPar();
00280
00282 MutLocQuadPar(Decimal lt, Decimal at, Decimal pt,int expandMethod,bool se,bool smrg,Decimal tts,string rf,string rtm,string rfts,string rfi, Decimal tmfmu,int mno,bool ev,bool pf,bool pp,string rfic,bool lfaf,string rapf, bool sap, bool rvf,bool scfs, bool sra,bool sbe,Decimal zpt, bool dof,int ftp,Decimal noi,Decimal dor, Decimal sot);
00283
00285 MutLocQuadPar(const MutLocQuadPar &A);
00286
00288 MutLocQuadPar& operator=(MutLocQuadPar &A);
00289
00291 Decimal getLinearTollerance();
00292
00294 Decimal getAngularTollerance();
00295
00297 Decimal getProjTollerance();
00298
00300 int getExpandMethod();
00301
00303 bool getSaveEstimates();
00304
00306 bool getSaveMultiRegOutput();
00307
00309 Decimal getTimeForMeasUpdate();
00310
00312 string getRootMeasFile();
00313
00315 string getRootTStateFile();
00316
00318 string getRootIdsFile();
00319
00321 string getRootIMUConfigFile();
00322
00324 Decimal getThrTimeSec();
00325
00327 int getMinNumObs();
00328
00330 bool getEmbVis();
00331
00333 bool getPrintForm();
00334
00336 bool getPrintFormDetails();
00337
00339 string getRootFiles();
00340
00342 bool getLoadFromAbsFile();
00343
00345 string getRootAbsFile();
00346
00348 bool getSaveAllParticles();
00349
00351 bool getReadVelFile();
00352
00354 bool getSaveCompleteStateFilter();
00355
00357 bool getSaveRelAbs();
00358
00360 bool getSaveBestEstim();
00361
00363 bool getZenithTollerance();
00364
00366 bool getDoOnlyFilter();
00367
00369 int getFilterType();
00370
00372 Decimal getNoiseMeasBear();
00373
00375 Decimal getDelayMeasBear();
00376
00378 Decimal getTimeStartOffset();
00379
00381 void setSaveCompleteStateFilter(bool state);
00382
00383 };
00384
00388 class MutLocQuad : public MIPObject{
00389 private:
00390
00391 static MutLocQuad* _instance;
00392
00393 bool _doOnlyFilter;
00394
00395 bool _saveInputFilterFile;
00396
00397 bool _dwOn;
00398
00399 MipResources::DraWinGL* _draWin;
00400 unsigned int _drawList;
00401
00402 bool _printFormation;
00403
00404 bool _printFormationDetails;
00405
00406 MutLocQuadPar _par;
00407
00408 ProbMultiRegCam3DCam* _probMultiReg;
00409
00410 vector< vector<AngleBearId> > inputMultiRegOff;
00411
00412 vector<map<int,Position3D> > idPosFilter;
00413
00414 vector<map<int,Angle> > _idYawFilter;
00415
00416 vector<pair<long int,long int> > _timeOffline;
00417 vector<Decimal> _timeOff;
00418
00419 int countMeasOff;
00420
00421 vector< vector<IMUDataTime> > _tStateOff;
00422
00423 vector< map<int, pair<Angle,Angle> > > _rollPitch;
00424
00425
00426 map<int,MipAlgorithms::PaFilBFL3D*> _filter;
00427
00428
00429 map<int,MipAlgorithms::PaFilBFLRelRelBearOnly3Dvel*> _filterVel;
00430
00431 vector<int> _activatedFilters;
00432
00433
00434
00435 map<int,vector<bearStr> > _measFromMultiBeaReg;
00436
00437 map<int,vector<Orientation3D> > _measFromMultiBeaRegOri;
00438
00439 vector<int> _measFromMultiBeaRegIds;
00440
00441
00442 vector<Velocity3D> _myOmegaVel;
00443
00444
00445
00446 vector<Pose3D> _absPosOwner;
00447
00448 vector<map<int,Pose3D> > _absPosOther;
00449
00450 vector<map<int,Velocity3D> > _velAbsOther;
00451
00452 vector<Velocity3D> _absVelOwner;
00453
00454
00455
00456
00457 int _myId;
00458
00459 Pose3D _myPose;
00460
00461 IMUDataTime _myIMU;
00462
00463 vector<bearStr> _myBearObs;
00464
00465
00466
00467 map<int, vector<bearStr> > _othersBearObs;
00468
00469 vector<int> _othersBearObsNums;
00470
00471
00472 map<int,IMUDataTime> _othersIMU;
00473
00474
00475 map<int,Pose3D> _estimates;
00476 map<int,Velocity3D> _velEstimates;
00477 vector<int> _activatedEstimates;
00478 map<int,Timer> _timeFromLastMessage;
00479 vector<PoseFeature3D> _formation;
00480
00481
00482 map<int,fstream*> _savefile;
00483
00484 map<int,fstream*> _saveBest;
00485
00486 fstream _saveRealPosFile;
00487
00488 fstream _saveMultiRegCamFile;
00489 fstream _saveBestEstimate;
00490 fstream _readFile;
00491
00492 fstream _logMultiRegCamFile;
00493 fstream _logMultiRegCamOff;
00494
00495 fstream _logTimeOff;
00496
00497 map<int,fstream*> _saveAllP;
00498
00499 fstream _saveInputFilter;
00500
00501
00502 stringstream s;
00503
00504 map<int,int> banned;
00505 Decimal _lastMeasUpdate;
00506
00507
00508 map<int,Decimal> _delayTimeMeas;
00509
00510
00511 int countSamples;
00512 int saveEachNSamples;
00513
00514
00515 private:
00517 void _readDataFromFiles();
00518
00520 int searchIMUData(vector<IMUDataTime> &inputIMUTime, Decimal time, Decimal thr);
00521
00523 int searchAbsPos(vector<Pose3DIdTime> &inputPosTime, Decimal time, Decimal thr);
00524
00526 Position3D _computeRelPos(Pose3DIdTime pos,Position3D posOther,bearStr &bearObs);
00527
00529 Position3D _computeRelCoord(Position3D myVel,Orientation3D myOri,Position3D velOther);
00530
00532 Pose3D _computeRelCoord(Pose3D myPose,Pose3D otherPose);
00533
00535 void _doOnePropagationFilterStep(map <int, vector <Pose3D> > &likelihoods, vector<int> &likelihoodsActive,map <int, vector <Velocity3D> > &velLikelihoods);
00536
00538 bool _activeFilter(int hisId);
00539
00541 void _completeMutLocFilInput(MipAlgorithms::MutLocFilInput3D &fStepIn, int hisId);
00542
00544 void _completeMutLocFilInputVelUpdate(MipAlgorithms::MutLocFilInput3D &fStepIn, int hisId);
00545
00547 void _performBearingOnlyMultipleRegistration(map <int, vector <Pose3D> > &likelihoods, vector<int> &likelihoodsActive, ProbMultiRegCam3DQuadSol* probMultiRegQuadSol);
00548
00550 void _insertValidQuadObservations(vector<AngleBearId> &allObservations);
00551
00553 void _activateFilter(int hisId);
00554
00556 bool _activeEstimate(int hisId);
00557
00559 void _computeFormation(actualForm &af);
00560
00562 Pose3D _computeAbsCoord(Pose3D owner,Pose3D other);
00563
00565 Position3D _computeAbsCoord(Pose3D owner,Position3D other);
00566
00568 void _draw();
00569
00571 void selectParticles(vector<Decimal> weights, vector<int> &posBest,int numVis);
00572
00573 public:
00575 MutLocQuad(MutLocQuadPar mlqp);
00577 MutLocQuad(int argc,char** argv,MutLocQuadPar mlqp);
00578
00580 MutLocQuad();
00581
00583 ~MutLocQuad();
00584
00586 Velocity3D transformPQRRDPDYD(Velocity3D pqr,Angle roll,Angle pitch);
00587
00589 Position3D quadNoRollPitch(Position3D point,Angle roll,Angle pitch);
00591 Velocity3D quadNoRollPitch(Velocity3D point,Angle roll,Angle pitch);
00593 Acceleration3D quadNoRollPitch(Acceleration3D point,Angle roll, Angle pitch);
00594
00595
00597 vector<BearIdTime> _readBearingFromPos(ifstream &file,int id);
00598
00600 vector<BearIdTime> _readBearingFromPosId(ifstream &file,int id,int opt);
00601
00603 vector<Pose3DIdTime> _readBearingFromAbsPosId(ifstream &file,int id);
00604
00606 vector<BearIdTime> _readBearing(ifstream &file,int id);
00607
00609 vector<Velocity3D> _readVelFile(ifstream &file,int id);
00610
00612 void _readIdsFile(ifstream &file,vector<int> &ris);
00613
00615 vector<IMUDataTime> _readTState(ifstream &file,MIPMatrix rotAcc,MIPMatrix rotGyro,Position3D biasAcc,Position3D scalingAcc,Position3D biasAngVel,Position3D scalingAngVel,int id);
00616
00618 void _readIMUConfigFile(ifstream &file,vector<MIPMatrix> &RotAcc,vector<MIPMatrix> &rotGyro,vector<Position3D>& biasAcc,vector<Position3D>& scalingAcc,vector<Position3D>& biasAngVel,vector<Position3D>& scalingAngVel);
00619
00621 void _computeInputMultiRegOff(vector<vector<BearIdTime> > &inputTime,vector<vector<AngleBearId> > &inputMultiRegOff,int myIdPos, vector< vector<IMUDataTime> > &inputTStateOffTemp, vector< vector<IMUDataTime> > &inputTStateOff,vector<int> IdsF);
00622
00624 void _plateLinVel();
00625
00629 void _fillFilterMeas(MipAlgorithms::MutLocFilInput3D& fStepIn, int hisId);
00630
00632 static MutLocQuad* instance(MutLocQuadPar* mlqp);
00633
00635 actualForm step(bool &nextStep);
00636
00638 string getObjectName() const{
00639 return "mutLocQuad";
00640 }
00641
00643 void computeStartingTime();
00644 };
00645
00646 }
00647 #endif