MutLocQuadStereoCam.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 
00029 #ifndef __PROB_MUTLOCQUAD_STEREO_CAM_H_
00030 #define __PROB_MUTLOCQUAD_STEREO_CAM_H_
00031 
00032 #include "baselib.h"
00033 #include "LogTrace.h"
00034 #include <Option.h>
00035 #include "ProbMultiRegStereoCam3D.h"
00036 #include "MutLocQuad.h"
00037 #include <PaFilBFLRelRel3D.h>
00038 #include <DraWinGL.h>
00039 
00040 #define DEBUGMUTLOCQUAD 0
00041 
00042 //#define WORLDGRAVITY 9.822
00043 #define WORLDGRAVITY 9.81
00044 
00045 typedef MipBaselib::IMUOdometry IMUData;
00046 
00047 namespace kybalg{
00048  
00052  class mutLocQuadStereoCamPar : public MutLocQuadPar{
00053   private:
00054    Decimal sigmaNoiseDist;
00055    Decimal rangeNoiseDist;
00056    Decimal minIntWeight;
00057    string rootFakeQuadIds;
00058   public:
00060    mutLocQuadStereoCamPar() : MutLocQuadPar(){};
00061    
00063    ~mutLocQuadStereoCamPar();
00064    
00066             mutLocQuadStereoCamPar(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, Decimal snd, Decimal rnd, Decimal miw, string fqif) : MutLocQuadPar(lt, at, pt, expandMethod, se, smrg, tts, rf, rtm, rfts, rfi, tmfmu, mno, ev, pf, pp, rfic, lfaf, rapf, sap, rvf, scfs, sra, sbe, zpt, false,0,0,0,0){
00067     sigmaNoiseDist = snd;
00068     rangeNoiseDist = rnd;
00069     minIntWeight  = miw;
00070     rootFakeQuadIds = fqif;
00071    };
00072    
00074    mutLocQuadStereoCamPar(const mutLocQuadStereoCamPar &A);
00075    
00077    mutLocQuadStereoCamPar& operator=(mutLocQuadStereoCamPar &A);
00078    
00081    Decimal getSigmaNoiseDist();
00082    
00085    Decimal getRangeNoiseDist();
00086    
00089    Decimal getMinIntWeight();
00090    
00093    string getRootFakeQuadIdsFile();
00094  };
00095  
00099  class mutLocQuadStereoCam : public MIPObject{
00100    private:
00101    // If one wants to use this class as a singletone class
00102    static mutLocQuadStereoCam*             _instance;
00103    // Specify if one wants to run the algorithm only with particle filters
00104    bool                         _doOnlyFilter;
00105    // Specify if one wants to save the particle filter inputs
00106    bool                         _saveInputFilterFile;
00107    //Stores if the drawing win has to be created
00108    bool                        _dwOn;
00109    // Pointer to the OpenGL window
00110    MipResources::DraWinGL*               _draWin;
00111    unsigned int                    _drawList;
00112    // Specify if one wants to visualize the estimates
00113    bool                         _printFormation;
00114    // Specify if one wants to visualize the entire particle sets
00115    bool                         _printFormationDetails;
00116    // Parameters of the algorithm
00117    mutLocQuadStereoCamPar               _par;
00118    // Multiple registration algorithm structure
00119    probMultiRegStereoCam3DCam*             _probMultiReg;
00120    // Stores the input from files
00121    vector< vector<bearDistId> >            inputMultiRegOff;
00122    // Ids list of the fake quadrotors
00123    vector<int>                     _fakeQuadIds;
00124    // Map that stores the observed id and relative positions only to test particle filters
00125    vector<map<int,Position3D> >            idPosFilter;
00126    // It stores the observed id and relative positions only to test particle filters
00127    vector<map<int,Angle> >               _idYawFilter;
00128    // It stores the time in sec and microsec
00129    vector<pair<long int,long int> >           _timeOffline;
00130    vector<Decimal>                        _timeOff;
00131    // Variable to count the actual step of measures
00132    int                         countMeasOff;
00133    // It stores the IMU data
00134    vector< vector<IMUDataTime> >             _tStateOff;
00135    // There are roll and pitch of the formation over time
00136    vector< map<int, pair<Angle,Angle> > >        _rollPitch;
00137    // Bank of particle fitlers
00138    map<int,MipAlgorithms::PaFilBFLRelRel3D*>      _filter;
00139    // List of filter activated
00140    vector<int>                     _activatedFilters;
00141    
00142    // Used in the constructor to store data from files
00143    // It stores the bearing-only measurements
00144    map<int,vector<bearStr> >              _measFromMultiBeaReg;
00145    // It stores the orientations
00146    map<int,vector<Orientation3D> >           _measFromMultiBeaRegOri;
00147    // It stores the ids
00148    vector<int>                     _measFromMultiBeaRegIds;
00149    
00150    // Angular velocity in horizonthal frame of the owner
00151    vector<Velocity3D>                 _myOmegaVel;
00152    
00153    // Variables only to compare results
00154    // Absolute position of the owner
00155    vector<Pose3D>                   _absPosOwner;
00156    // Absolute position of other robots (not the owner)
00157    vector<map<int,Pose3D> >               _absPosOther; 
00158    // Absolute velocity of other robots (not the owner)
00159    vector<map<int,Velocity3D> >              _velAbsOther;
00160    // Absolute velocity of the owner
00161    vector<Velocity3D>                 _absVelOwner;
00162    
00163    
00164    // Self information = informations about the owner
00165    // Id
00166    int                         _myId;
00167    // Pose
00168    Pose3D                       _myPose;
00169    // IMU output
00170    IMUDataTime                     _myIMU;
00171    // Bearing-only measurements
00172    vector<bearDistStr>                 _myBearObs;
00173    
00174    // Others information = other robot informations
00175    //Bearing-only observations
00176    map<int, vector<bearStr> >             _othersBearObs;
00177    // Ids
00178    vector<int>                     _othersBearObsNums;
00179    //map<int,Pose3D>     _othersPose;
00180    // IMU outputs
00181    map<int,IMUDataTime>                _othersIMU;
00182    
00183    // Results
00184    map<int,Pose3D>                   _estimates;
00185    map<int,Velocity3D>                 _velEstimates;
00186    vector<int>                     _activatedEstimates;
00187    map<int,Timer>                   _timeFromLastMessage;
00188    vector<PoseFeature3D>                _formation;
00189    
00190    // Saving information
00191    map<int,fstream*>                  _savefile;
00192    // Save best particle
00193    map<int,fstream*>                  _saveBest;
00194    // Save ground truth
00195    fstream                       _saveRealPosFile;
00196    // Save output of multiple registration algorithm
00197    fstream                       _saveMultiRegCamFile;
00198    fstream                       _saveBestEstimate;
00199    fstream                       _readFile;
00200    // Save info about multiple registration algorithm
00201    fstream                       _logMultiRegCamFile;
00202    fstream                       _logMultiRegCamOff;
00203    //Save time steps
00204    fstream                       _logTimeOff;
00205    // Save all the particles
00206    map<int,fstream*>                  _saveAllP;
00207    // Save filters' input
00208    fstream                       _saveInputFilter;
00209    
00210    // Printing information inside the code
00211    stringstream                     s;
00212  
00213    map<int,int>                     banned;
00214    
00215   //Methods
00216   private:   
00218    void _readDataFromFiles();
00219    
00221    int searchIMUData(vector<IMUDataTime> &inputIMUTime, Decimal time, Decimal thr);
00222    
00224    int searchAbsPos(vector<Pose3DIdTime> &inputPosTime, Decimal time, Decimal thr);
00225    
00227    Position3D _computeRelPos(Pose3DIdTime pos,Position3D posOther,bearDistStr &bearObs);
00228    
00230    Position3D _computeRelCoord(Position3D myVel,Orientation3D myOri,Position3D velOther);
00231    
00233    Pose3D _computeRelCoord(Pose3D myPose,Pose3D otherPose);
00234    
00236    void _doOnePropagationFilterStep(map <int, vector <Pose3D> > &likelihoods, vector<int> &likelihoodsActive,map <int, vector <Velocity3D> > &velLikelihoods);
00237    
00239    bool _activeFilter(int hisId);
00240    
00242    void _completeMutLocFilInput(MipAlgorithms::MutLocFilInput3D &fStepIn, int hisId);
00243    
00245    void _performBearingOnlyMultipleRegistration(map <int, vector <Pose3D> > &likelihoods, vector<int> &likelihoodsActive, probMultiRegStereoCam3DQuadSol* probMultiRegQuadSol);
00246 
00248    void _insertValidQuadObservations(vector<bearDistId> &allObservations);
00249    
00251    void _activateFilter(int hisId);
00252    
00254    bool _activeEstimate(int hisId);
00255    
00257    void _computeFormation(actualForm &af);
00258    
00260    Pose3D _computeAbsCoord(Pose3D owner,Pose3D other);
00261    
00263    Position3D _computeAbsCoord(Pose3D owner,Position3D other);
00264    
00266    void _draw();
00267    
00269    void selectParticles(vector<Decimal> weights, vector<int> &posBest,int numVis);
00270    
00271   public:
00273    mutLocQuadStereoCam(mutLocQuadStereoCamPar mlqp);
00274    
00276    mutLocQuadStereoCam(mutLocQuadStereoCamPar mlqp, bool falsePos);
00277    
00279    mutLocQuadStereoCam(int argc,char** argv,mutLocQuadStereoCamPar mlqp);
00280    
00282    mutLocQuadStereoCam();
00283    
00285    ~mutLocQuadStereoCam();
00286    
00288    Velocity3D transformPQRRDPDYD(Velocity3D pqr,Angle roll,Angle pitch);
00289    
00291    Position3D quadNoRollPitch(Position3D point,Angle roll,Angle pitch);
00293    Velocity3D quadNoRollPitch(Velocity3D point,Angle roll,Angle pitch);
00295    Acceleration3D quadNoRollPitch(Acceleration3D point,Angle roll, Angle pitch);
00296    //void quadNoRollPitch(Decimal x, Decimal y, Decimal z, Angle roll, Angle pitch, Decimal* out);
00297    
00299    vector<bearDistIdTime> _readBearingFromPos(ifstream &file,int id);
00300    
00302    vector<bearDistIdTime> _readBearingFromPosId(ifstream &file,int id,int opt);
00303    
00305    vector<Pose3DIdTime> _readBearingFromAbsPosId(ifstream &file,int id);
00306    
00308    vector<Velocity3D> _readVelFile(ifstream &file,int id);
00309    
00311    void _readIdsFile(ifstream &file,vector<int> &ris);
00312    
00314    void _readFakeQuadIdsFile(ifstream &file);
00315    
00317    vector<IMUDataTime> _readTState(ifstream &file,MIPMatrix rotAcc,MIPMatrix rotGyro,Position3D biasAcc,Position3D scalingAcc,Position3D biasAngVel,Position3D scalingAngVel);
00318    
00320    void _readIMUConfigFile(ifstream &file,vector<MIPMatrix> &RotAcc,vector<MIPMatrix> &rotGyro,vector<Position3D>& biasAcc,vector<Position3D>& scalingAcc,vector<Position3D>& biasAngVel,vector<Position3D>& scalingAngVel);
00321    
00323    void _computeInputMultiRegOff(vector<vector<bearDistIdTime> > &inputTime,vector<vector<bearDistId> > &inputMultiRegOff,int myIdPos, vector< vector<IMUDataTime> > &inputTStateOffTemp, vector< vector<IMUDataTime> > &inputTStateOff,vector<int> IdsF);
00324    
00326    static mutLocQuadStereoCam* instance(mutLocQuadStereoCamPar* mlqp);
00327    
00329    actualForm step(bool &nextStep);
00330    
00332    string getObjectName() const{
00333      return "mutLocQuadStereoCam";
00334    }
00335  };  
00336   
00337 } //end of namespace kybalg
00338 #endif

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