GMPHDUnicycle2DCamIdRCFilter.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 
00029 
00030 #ifndef __GMPHD_UNICYCLE_2D_CAM_ID_FILTER_H
00031 #define __GMPHD_UNICYCLE_2D_CAM_ID_FILTER_H
00032 
00033 #include <Spaces.h>
00034 #include <SpacesArma.h>
00035 #include <GaussianMixture.h>
00036 #include "PHDFilter.h"
00037 #include <map>
00038 #include <CameraParameters.h>
00039 
00040 #define NO_ID -1
00041 #define STEADY_ID -2
00042 
00043 using namespace MipBaselib;
00044 using namespace arma;
00045 
00046 namespace MipAlgorithms{
00047  
00049  /* @{ */
00050  
00054  class GMPHDUnicycle2DCamIdRCFilterPars:public PHDFilterPars{
00055   public:
00056    // System model
00058    DMat           N_n_x;
00059    
00060    // Measurement model
00062    DMat           H;
00063    
00065    DMat           N_n_z;
00066    
00067    // Pruning thresholds
00070    Decimal         truncThresh;
00071    
00073    int           maxNumComponents;
00074    
00077    Decimal         mergThresh;
00078    
00080    int           partNumber;
00081    
00082    // Parameters for the computation of the actual detection probability of a target.
00084    Decimal         sensorDetectionRay;
00085    
00087    Decimal         targetDimension;
00088    
00090    Decimal         maxDetectionBearing;
00091    
00093    bool           useNewNoMeasWeight;
00094    
00096    CameraPar3DArma*    camPars;
00097    
00099    int           myId;
00100    
00102    Roto3DArma*       rotoQuadMobRob;
00103    
00105    Roto3DArma*       rotSonarQuad;
00106    
00108    Roto3DArma       rotCameraQuadTrans;
00109    
00111    Position3DArma*     posSonarQuad;
00112    
00114    bool          vertZSonarAlgo;
00115    
00117    string print();
00118    
00119    // Constructors
00121    GMPHDUnicycle2DCamIdRCFilterPars();
00122    
00124    GMPHDUnicycle2DCamIdRCFilterPars(int mId, Decimal pS, Decimal pD, SimTime t, DMat& nx, DMat& h, DMat& nz, Decimal tt, int mc, Decimal mt, int pN, Decimal sdr, Decimal td, Decimal mdb, Decimal flc, Decimal wc, Decimal hc, Roto3DHomoArma &qct, Decimal ppx, Decimal ppy, Roto3DArma& rotoQuadMob, Roto3DHomoArma& rotoSonarQuad, bool vzsm);
00125  };
00126  
00130  class GMPHDUnicycle2DCamIdRCFilterVars:public PHDFilterVars{
00131   
00132   public:
00133    
00134    // It saves the rototranslation between quadrotor and camera mapping
00135    DMat::fixed<3,3>       AMat;
00136    Position3DArma        bVec;
00137    Roto3DArma         CMat;
00138    
00139    // Vertical height by sonar in quadrotor frame
00140    Decimal           vHeight;
00141    // Height from z-axis of sonar in sonar reference frame
00142    Decimal           zHeight;
00143    
00144    // Attitude of the robot
00145    // Roll
00146    Decimal           roll;
00147    // Pitch
00148    Decimal           pitch;
00149    // Yaw
00150    Decimal           myYaw;
00151    Decimal           myLastYaw;
00152    
00153    // Coordinates of the image plane border
00154    Position2DArma        borders[4];
00155    
00156    // New plate measurements
00157    vector<Position2DArma>    newMeas;
00158    
00159    // New image border
00160    vector<Position2DArma>    newBorder;
00161    
00162    // Variable to store the previous velocity of the owner
00163    Odometry2DTimeArma      myLastOdom;
00164    Odometry2DTimeArma      myOdo;
00165    
00166    Decimal           lastMeasurementNumber;
00167    vector<Position>       lastMeasurements;
00168    
00169    GaussianMixtureJointId    prediction;
00170    
00171    vector<DCol>         predictedMeasures;
00172    vector<Decimal>       predictedMeasuresD;
00173    vector<Angle>        predictedMeasuresB;
00174    vector<DMat>         predictedCovariances;
00175    vector<DMat>         kalmanGains;
00176    vector<DMat>         stepKCovariances;
00177    vector<Decimal>       detectionProbability;
00178    
00179    int bestMyEstimate;
00180    
00181    vector<vector<Decimal> >   predictedMeasuresOth;
00182    vector<vector<Decimal> >   predictedCovariancesOth;
00183    vector<vector<DMat> >    kalmanGainsOth;
00184    vector<vector<DMat> >    stepKCovariancesOth;
00185    vector<vector<Decimal> >   detectionProbabilityOth;
00186    vector<vector<Decimal> >   sensorWeightsOth;
00187    
00188    vector<Decimal>       detectionProbabilitySum;
00189    Decimal           sensorWeightSum;
00190    vector<Decimal>       notDetectionProbabilityProd;
00191    
00192    vector<vector<Decimal > >  dists;
00193    
00194    //map of current sensors in the current belief
00195    map <int, vector <int> >   currSens;
00196    
00197    bool             firstStepAfterMeasurements;
00198    
00199    GaussianMixtureJointId    belief;
00200    
00201    GaussianMixtureJointId   beliefOth;
00202    
00203    vector<int>         lastOtherRobotPoseNum;
00204    map<int,Pose2DArma>     lastOtherRobotPose;
00205    map<int,Pose2DArma>     odometries;
00206    
00207    GMPHDUnicycle2DCamIdRCFilterVars();
00208  };
00209  
00211  /* @{ */
00212  
00216  class GMPHDUnicycle2DCamIdRCFilter:public PHDFilter{
00217   protected:
00218    GMPHDUnicycle2DCamIdRCFilterVars* _gmvars;
00219    GMPHDUnicycle2DCamIdRCFilterPars* _gmpars;
00220    
00221   public:
00223    GMPHDUnicycle2DCamIdRCFilter();
00224    
00227    GMPHDUnicycle2DCamIdRCFilter(GMPHDUnicycle2DCamIdRCFilterPars inParams);
00228    
00231    void step(PHDFilterIn &in);
00232    
00235    string print();
00236    
00239    void getBelief(GaussianMixtureJointId &gm);
00240    
00244    void getBeliefWeightedSum(map<int,Col<Decimal>::fixed<3> > &out, SimTime* actTime=NULL);
00245    
00249    void getBestBelief(map<int,Col<Decimal>::fixed<3> > &out, SimTime* actTime=NULL);
00250    
00253    string exportAsStringWeightedSum();
00254    
00257    string exportAsStringWeightedSumImagePlane();
00258    
00261    string exportAsStringBestGuess();
00262    
00265    string exportAsStringBestGuessImagePlane();
00266    
00269    string exportAsStringAllGuessImagePlane();
00270    
00273    string exportAsStringAllGuess();
00274    
00277    string exportAsStringUAVData();
00278    
00282    string exportAsStringClusterGuess(const Decimal &per);
00283    
00286             string exportAsString();
00287 
00290             void exportAs3DRelCoordBestGuess(map<int,DCol::fixed<4> > &in);
00291    
00292    PHDFilterOutputType getOutputType(){
00293     return PHD_OUT_GMJID;
00294    }
00295    
00296   private:
00297    
00298    fstream streamFile;
00299    
00301    void _initialize(PHDFilterIn&);
00302    
00304    void _initializeWithMeas(PHDFilterIn&);
00305    
00307    void _normalStep(PHDFilterIn&);
00308    
00310    void _computeOdometries(PHDFilterIn&);
00311    
00313    void _computeOdometriesInit(PHDFilterIn &in);
00314    
00316    void _predictBirthTarget(PHDFilterIn&);
00317    
00319    void _predictExistingTarget();
00320    
00326    vector<Position2DArma> _plateMeasurements(vector<Position2DArma> &points, const Decimal &height);
00327    
00333    vector<Position2DArma> _plateMeasurementsAlongZCam(vector<Position2DArma> &points, const Decimal &height);
00334    
00340    vector<Position2DArma> _plateMeasurementsVert(vector<Position2DArma> &points, const Decimal &height);
00341    
00343    void _findMyBestEstimate();
00344    
00347    void _buildPHDUpdateComponents(PHDFilterIn &in);
00348    
00350    void _updateWithNoMeasurements();
00351    
00354    void _updateWithMeasurements(PHDFilterIn &in);
00355    
00357    void _prune();
00358    
00366    void _transRotoPlateAbsHeight();
00367    
00374    void _transRotoPlateRelHeight(DMat::fixed<3,3> &KFun, Position3DArma &b);
00375    
00377    Velocity2DArma _transPlateLinVel(const Velocity3DArma &vel);
00378    
00383    vector<Position2DArma> _findImagePlaneBorder(const Decimal &height);
00384    
00389    vector<Position2DArma> _findImagePlaneBorderAlongZCam(const Decimal &height);
00390    
00394    vector<Position2DArma> _findImagePlaneBorderVert();
00395    
00398    void _updateLinearCoeff();
00399    
00406    Decimal _computeProbDetVert(Position2DArma& point);
00407    
00411    Decimal _mahalanobisDist(GaussianComponent& a, GaussianComponent& b);
00412    
00414    void _pruneSimple();
00415    
00418    void _preProcessingData(PHDFilterIn& in);
00419    
00424    void _plateOdometry(PHDFilterIn &in);
00425    
00427    Decimal _transformPQRYD(const Velocity3DArma &pqr);
00428    
00429   public:
00435    Pose2DArma _integral(Odometry2DTimeArma& vA, Odometry2DTimeArma& vB, const Decimal& dT);
00436    
00437    string getObjectName() const {
00438     return "GMPHDUnicycle2DCamIdRCFilter";
00439    }
00440  };
00441    
00442    /* @} */
00443  
00444 }
00445  
00446  
00447 #endif

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