MutLocQuad.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010  Antonio Franchi
00006 //
00007 // This file is part of TeleKyb.
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
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 //#define WORLDGRAVITY 9.822
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  // A vector of mutLocState (one of each robot) performes the actual formation
00198  typedef vector<mutLocState>  actualForm;
00199  
00200  // A vector of actualForm performes the list of all the formations in each time step
00201  typedef vector<actualForm>  totalForm;
00202 };
00203 
00204 namespace kybalg{
00208  class MutLocQuadPar{
00209   private:
00210    // Linear tollerance
00211    Decimal  _linearTollerance;
00212    // Angular tollerance
00213    Decimal  _angularTollerance;
00214    // Projection tollerance
00215    Decimal  _projTollerance;
00216    // Zenith tollerance
00217    Decimal  _zenithTollerance;
00218    // Expansion method
00219    int    _expandMethod;
00220    // Specify if one wants to store the estimates
00221    bool   _saveEstimates;
00222    // Specify if one wants to store the output of the multiple registration algorithm
00223    bool   _saveMultiRegCam;
00224    // Threshold time in seconds
00225    Decimal  _thrTimeSec;
00226    // Threshold time in microseconds
00227    Decimal  _thrTimeUSec;
00228    // Root of the files where the bearing-only measurements are stored
00229    string  _rootFileMeasOff;
00230    // Root of the files where the IMU measurements are stored
00231    string  _rootFileTStateOff;
00232    // Root of the files where the list of ids is stored
00233    string  _rootFileIdsOff;
00234    // Root of the files where the configuration file of IMU is stored
00235    string  _rootFileIMUConfigOff;
00236    // Root of the folder where the files are stored
00237    string  _rootFiles;
00238    // Time for measurement update
00239    Decimal  _timeForMeasUpdate;
00240    // Minimum number of observation in feature set to be take in account in multiple registration algorithm
00241    int    _minObSize;
00242    // Specify if one wants to visualize the OpenGL window
00243    bool    _embVis;
00244    // Specify if one wants to visualize the actual estimates
00245    bool   _printForm;
00246    // Specify if one wants to visualize all the particles
00247    bool   _printFormDetails;
00248    // Specify if one wants to load data from ground truth
00249    bool    _loadFromAbsFile;
00250    // Root of ground truth files
00251    string  _rootAbsPosFile;
00252    // Specify if one wants to save all the particles plus ground truth as last coordinate
00253    bool    _saveAllParticles;
00254    // Specify if one wants to load velocity files
00255    bool    _readVelFile;
00256    // Specify if one wants to save all the particles state
00257    bool    _saveCompleteStateFilter;
00258    // Specify if one wants to save data in relative or absolute (it needs to load files from ground truth) reference frame
00259    bool    _saveRelAbs;
00260    // Specify if one wants to save the best particle
00261    bool    _saveBestEstimate;
00262    // Specify if one wants to run only the filter or the algorithm with multireg. True if only filter; false otherwise
00263    bool   _doOnlyFilter;
00264    // Specify which filter one wants to run (0 for acceleration, 1 for velocity). The acceleration filter is set by default
00265    int    _filterType;
00266    // Specify the noise acting on the bearing measurements
00267    Decimal  _noiseBear;
00268    // Specify the delay between the owner of the filter and the other robots in the formation
00269    Decimal  _delayBear;
00270             // Specify the delay between the owner of the filter and the other robots in the formation
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    // If one wants to use this class as a singletone class
00391    static MutLocQuad*                  _instance;
00392    // Specify if one wants to run the algorithm only with particle filters
00393    bool                         _doOnlyFilter;
00394    // Specify if one wants to save the particle filter inputs
00395    bool                         _saveInputFilterFile;
00396    //Stores if the drawing win has to be created
00397    bool                        _dwOn;
00398    // Pointer to the OpenGL window
00399    MipResources::DraWinGL*               _draWin;
00400    unsigned int                    _drawList;
00401    // Specify if one wants to visualize the estimates
00402    bool                         _printFormation;
00403    // Specify if one wants to visualize the entire particle sets
00404    bool                         _printFormationDetails;
00405    // Parameters of the algorithm
00406    MutLocQuadPar                    _par;
00407    // Multiple registration algorithm structure
00408    ProbMultiRegCam3DCam*                _probMultiReg;
00409    // Stores the input from files
00410    vector< vector<AngleBearId> >            inputMultiRegOff;
00411    // Map that stores the observed id and relative positions only to test particle filters
00412    vector<map<int,Position3D> >            idPosFilter;
00413    // It stores the observed id and relative positions only to test particle filters
00414    vector<map<int,Angle> >               _idYawFilter;
00415    // It stores the time in sec and microsec
00416    vector<pair<long int,long int> >           _timeOffline;
00417    vector<Decimal>                        _timeOff;
00418    // Variable to count the actual step of measures
00419    int                         countMeasOff;
00420    // It stores the IMU data
00421    vector< vector<IMUDataTime> >             _tStateOff;
00422    // There are roll and pitch of the formation over time
00423    vector< map<int, pair<Angle,Angle> > >        _rollPitch;
00424    // Bank of particle fitlers
00425 //    map<int,MipAlgorithms::PaFilBFLRelRelBearOnly3D*>  _filter;
00426    map<int,MipAlgorithms::PaFilBFL3D*>  _filter;
00427    
00428    // Bank of particle fitlers (with velocity input)
00429    map<int,MipAlgorithms::PaFilBFLRelRelBearOnly3Dvel*> _filterVel;
00430    // List of filter activated
00431    vector<int>                     _activatedFilters;
00432    
00433    // Used in the constructor to store data from files
00434    // It stores the bearing-only measurements
00435    map<int,vector<bearStr> >              _measFromMultiBeaReg;
00436    // It stores the orientations
00437    map<int,vector<Orientation3D> >           _measFromMultiBeaRegOri;
00438    // It stores the ids
00439    vector<int>                     _measFromMultiBeaRegIds;
00440    
00441    // Angular velocity in horizonthal frame of the owner
00442    vector<Velocity3D>                 _myOmegaVel;
00443    
00444    // Variables only to compare results
00445    // Absolute position of the owner
00446    vector<Pose3D>                   _absPosOwner;
00447    // Absolute position of other robots (not the owner)
00448    vector<map<int,Pose3D> >               _absPosOther; 
00449    // Absolute velocity of other robots (not the owner)
00450    vector<map<int,Velocity3D> >              _velAbsOther;
00451    // Absolute velocity of the owner
00452    vector<Velocity3D>                 _absVelOwner;
00453    
00454    
00455    // Self information = informations about the owner
00456    // Id
00457    int                         _myId;
00458    // Pose
00459    Pose3D                       _myPose;
00460    // IMU output
00461    IMUDataTime                     _myIMU;
00462    // Bearing-only measurements
00463    vector<bearStr>                   _myBearObs;
00464    
00465    // Others information = other robot informations
00466    //Bearing-only observations
00467    map<int, vector<bearStr> >             _othersBearObs;
00468    // Ids
00469    vector<int>                     _othersBearObsNums;
00470    //map<int,Pose3D>     _othersPose;
00471    // IMU outputs
00472    map<int,IMUDataTime>                _othersIMU;
00473    
00474    // Results
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    // Saving information
00482    map<int,fstream*>                  _savefile;
00483    // Save best particle
00484    map<int,fstream*>                  _saveBest;
00485    // Save ground truth
00486    fstream                       _saveRealPosFile;
00487    // Save output of multiple registration algorithm
00488    fstream                       _saveMultiRegCamFile;
00489    fstream                       _saveBestEstimate;
00490    fstream                       _readFile;
00491    // Save info about multiple registration algorithm
00492    fstream                       _logMultiRegCamFile;
00493    fstream                       _logMultiRegCamOff;
00494    //Save time steps
00495    fstream                       _logTimeOff;
00496    // Save all the particles
00497    map<int,fstream*>                  _saveAllP;
00498    // Save filters' input
00499    fstream                       _saveInputFilter;
00500    
00501    // Printing information inside the code
00502    stringstream      s;
00503  
00504    map<int,int>                     banned;
00505    Decimal                       _lastMeasUpdate;
00506    
00507    // Delay information
00508    map<int,Decimal>                  _delayTimeMeas;
00509    
00510    // Counter for saving particles
00511    int countSamples;
00512    int saveEachNSamples;
00513    
00514   //Methods
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    //void quadNoRollPitch(Decimal x, Decimal y, Decimal z, Angle roll, Angle pitch, Decimal* out);
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 } //end of namespace kybalg
00647 #endif

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