OfflinerTask.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 
00030 
00031 
00037 
00038 
00039 #ifndef __OFFLINER_TASK_H_
00040 #define __OFFLINER_TASK_H_
00041 
00042 #include <Task.h>
00043 #include <Resource.h>
00044 #include <CommModule.h>
00045 #include <SharedMem.h>
00046 #include <CommonOptions.h>
00047 #include <GaussianMixture.h>
00048 #include <OfflineMR.h>
00049 
00050 #include <SpacesArma.h>
00051 
00052 // Inclusion of offline UAV
00053 #include <OfflineUav.h>
00054 
00055 #ifndef MIP_PLATFORM_ARM
00056  #include <DraWin.h>
00057 #endif
00058 #include <SimTime.h>
00059 
00060 // #include <libxml/tree.h>
00061 // #include <libxml/parser.h>
00062 
00063 using namespace MipResources;
00064 
00065 namespace MipTasks{
00066  
00068  /* @{ */
00069  
00070  
00074  enum OfflineJobs{
00075   OJ_PARTICLE_MUT_LOC, 
00076   OJ_FAST_SLAM_PMLNMR, 
00077   OJ_PHDFILTER_STAGE1, 
00078   OJ_PHDFILTER_STAGE2, 
00079   OJ_PHDFILTER_QUAD, 
00080   OFFLINE_JOBS_TYPES_NUM
00081  };
00082  
00084  static const char* OfflineJobsNames[OFFLINE_JOBS_TYPES_NUM] = {
00085   "ParticleMutLoc",
00086   "FastSLAMMutLoc",
00087   "PHDFilter_Stage1",
00088   "PHDFilter_Stage2",
00089   "PHDFilter_Quad"
00090  };
00091 
00092  
00095  enum OfflinerFunctionalities{
00096   OFF_SHME_MYPF, 
00097   OFF_SHME_MYCO, 
00098   OFF_SHME_MYCI, 
00099   OFF_SHME_MYGM, 
00100   OFF_COMM_OTPOSE, 
00101   OFF_COMM_OTPF, 
00102   OFF_COMM_OTCO, 
00103   OFF_COMM_OTCI, 
00104   OFF_COMM_OTGM, 
00105   OFF_EMU_UAV,  
00106   OFFLINER_FUNCTIONALITIES_NUM
00107  };
00108  
00114  static const bool OfflinerFunctionalitiesTable[OFFLINE_JOBS_TYPES_NUM][OFFLINER_FUNCTIONALITIES_NUM]={
00115 //                       SHME_MYPF SHME_MYCO SHME_MYCI SHME_MYGM COMM_OTPOSE COMM_OTPF COMM_OTCO COMM_OTCI COMM_OTGM EMU_HOV
00116 /*OJ_PARTICLE_MUT_LOC*/  true,     false,    false,    false,    true,       true,     false,    false,    false,    false,   
00117 /*OJ_FAST_SLAM_PMLNMR*/  true,     false,    false,    false,    true,       true,     false,    false,    false,    false,
00118 /*OJ_PHDFILTER_STAGE1*/  true,     false,    false,    false,    true,       false,    false,    false,    false,    false,
00119 /*OJ_PHDFILTER_STAGE2*/  false,    false,    true,     true,     false,      false,    false,    true,     true,     false,
00120 /*OJ_PHDFILTER_QUAD*/    false,    false,    false,    false,    true,       false,    false,    false,    false,    true
00121  };
00122  
00123  
00127  enum OfflinerTaskStates{
00128   OFFLINER_TASK_FIRST_RUN,
00129   OFFLINER_TASK_NORMAL_RUN,
00130   OFFLINER_TASK_STATES_NUM
00131  };
00132  
00135  static const char* OfflinerTaskStatesNames[OFFLINER_TASK_STATES_NUM] = {
00136   "FirstRun",
00137   "NormalRun"
00138  };
00139  
00140  
00144  class OfflinerTaskOptions : public Options {
00145   public:
00147    StringOption*       rootFiles;
00148    StringOption*       rootFileIds;
00149    StringOption*       rootFileFeatSet;
00150    StringOption*       rootFileTState;
00151    StringOption*       rootFileGaussianMixture;
00152    StringOption*       rootFileControlInput;
00153    StringOption*       rootFileTruth;
00154    StringOption*       rootFileTruthTSt;
00155    StringOption*       rootImPlaneMeasFile;
00156    DecimalOption*       startTime;
00157    DecimalOption*       endTime;
00158    DecimalOption*       timeStep;
00159    BoolOption*        stepByStep;
00160    StringOption*       jobType;
00161    Pose3DOption*       startPoseGroundTruthQuad;
00162    Pose3DOption*       relGroundTruthQuadMobRob;
00163    DecimalArrayOption*    rotoAxisFromGroundToQuad;
00164    BoolOption*        useStaticQuad;
00165    BoolOption*        saveGTFile;
00166    BoolOption*        saveImPlaneMeas;
00167    IntOption*         GTTypeData;
00168    
00169    // Uav files
00170    StringOption*       UavId;
00171    StringOption*       UavSonarAttFile;
00172    StringOption*       UavVelFile;
00173    StringOption*       UavObsFile;
00174    StringOption*       UavTimeFile;
00175    StringOption*       UavGTFile;
00176    StringOption*       UavGTTimeFile;
00177    
00179    Pose3DOption*       UavMRGTRelPose;
00180    
00182    DecimalOption* widthCam;
00183    
00185    DecimalOption* heightCam;
00186    
00188    DecimalOption* focaLengthCam;
00189    
00191    Pose3DOption* relQuadCam;
00192    
00194    PositionOption* principalPoint;
00195    
00197    StringOption*  rootSaveFolder;
00198    
00203    BoolOption*        setAbsoluteStartTime;
00204    
00206    OfflinerTaskOptions();
00207 
00208    string getObjectName() const {
00209     return "OfflinerTaskOptions";
00210    }
00211  };
00212  
00213  
00217  class OfflinerTaskSharedMem : public SharedMem{
00218   public:
00219    
00220    
00223    void setTime(Time &t);
00224    
00228    void setMyProtrusions(PosiFeatures &protrusions, MotionModuleTState &protrusionsTState);
00229    
00233    void setMyCamObs(vector<Angle> &camObs, MotionModuleTState &camObsTState);
00234    
00235    
00242    void setGroundTruthMobRobQuad(const Decimal &roll, const Decimal &pitch, const PosiFeatures3DTimeArma& pos, const Roto3DArma *rotGT, vector<int> &ids);
00243    
00246    void setGroundTruthMobRobQuad(const map<int,Pose> &gtPose);
00247    
00250    void initSharedMem();
00251    
00252    void doMloc(){
00253     _doMloc = true;
00254    }
00255    
00258    void setMyGaussianMixture(string &gm);
00259    
00262    void setMyControlInput(MRControlInputs &ci);
00263    
00264    // From now on, the methods are for UAV
00265    
00269    void setMyAttitude(const Decimal &ro, const Decimal &pit);
00270    
00274    void setMyAttitude(const Angle &ro, const Angle &pit);
00275    
00278    void setMyYaw(const Decimal &y);
00279    
00282    void setMyYaw(const Angle &y);
00283    
00292    void setMyVelocity(const Decimal& lvx, const Decimal& lvy, const Decimal& lvz,const Decimal &avx,const Decimal &avy,const Decimal &avz, const Time &time);
00293    
00301    void setMyVelocity(const Decimal& lvx, const Decimal& lvy, const Decimal& lvz,const Decimal &avx,const Decimal &avy,const Decimal &avz);
00302    
00306    void setMyVelocity(const Velocity3DArma& lv, const Velocity3DArma& av);
00307    
00312    void setMyVelocity(const Velocity3DArma& lv, const Velocity3DArma& av, const Time &time);
00313    
00314    
00315    void setMy3DObs(const vector<Position2DArma> &obs);
00316    
00324    void setMy3DObs(PosiFeatures3DTimeArma &camObs, const Roto3DArma &aMat, const Position3DArma &bVec, const Decimal &width, const Decimal &height);
00325    
00329    void setMy3DObs(PosiFeatures3DTimeArma &camObs);
00330     
00333    void setMyHeight(const Decimal &hei);
00334  };
00335  
00336  
00340  class OfflinerTask : public Task{
00341   private:
00342    fstream fileStream;
00343    
00344    OfflineJobs _job;
00345    
00346    
00348    static const TaskPlate _plate = OFF_TASK;
00349    
00351 //    static const long int  _maxDurSec  = 0,      _maxDurUsec = 100000; 
00352 //    static const long int  _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 500000;
00353 //    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 400000;
00354    
00355    
00358    static const long int  _maxDurSec  = 0,      _maxDurUsec = 150000;
00359    static const long int  _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 500000;
00360    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 200000;
00361    
00362    
00364    CommModule* _commModule;
00365 //    MobileRob*  _mobileRob;
00366    
00368  #ifndef MIP_PLATFORM_ARM
00369    DraWin*      _draWin;   
00370    unsigned int _drawList; 
00371    bool         dwOn;      
00372  #endif
00373    
00375    OfflinerTaskSharedMem* _sharedMem;
00376    
00378    OfflinerTaskOptions _options;
00379    
00380    // Define here the local variables of your task.
00381    OfflinerTaskStates    _state;
00382    Time           _ctime;
00383    SimTime         _stime;
00384    SimTime         _prevStime;
00385    
00386    vector<int>       _IdsF;
00387    int           _robotId;
00388    int           _myIdPos;
00389    int           _myId;
00390    MotionModuleTState   _myTState;
00391    
00392    map<int, OfflineMR*>  _robots;
00393 /*   
00394    map<int, OfflineMR> _robotsGT;*/
00395    
00396    OfflineMR        _my3DObs;
00397    
00398    OfflineUav*       _myUav;
00399    
00401    Roto3DArma*       _rotoAxisGroundQuad;
00403    Roto3DArma*       _calibMatrix;
00405    Roto3DArma*       _rotoQuadCam;
00407    Position3DArma*     _posApp;
00409    Roto3DArma*       _matApp;
00411    vector<Roto3DArma>   rotoActFromGroundTruthQuadToQuad;
00412    vector<Position3DArma> traslActFromGroundTruthQuadToQuad;
00413    
00414    // Attitude and sonar info
00416    Decimal         _roll;
00418    Decimal         _pitch;
00420    Decimal         _yaw;
00422    Decimal         _height;
00424    Velocity3DArma     _linVelUav;
00426    Velocity3DArma     _angVelUav;
00428    Roto3DArma*       _rotAppGTOri;
00430    vector<Position2DArma> _obs;
00431    
00433    Roto3DArma*       _rotUavMRGT;
00435    Position3DArma*     _posUavMRGT;
00436    
00438    void _firstRun();
00439    
00441    map<int,fstream*>    _gtStreams;
00442    
00444    fstream*        _imPlaneMeas;
00445    
00447    map<int,Pose>      _gtMobRobQuad;
00448    
00450    vector<Position2DArma> _myObs;
00451    
00453    TaskOutputs _normalRun();
00454    
00455   public:
00457    OfflinerTask(ResourcePointers resources,int argc, const char* argv[]);
00458    
00460    ~OfflinerTask();
00461    
00464    TaskPlate getPlate() const {
00465     return _plate;
00466    }
00469    Time getMaxDuration(){
00470     return Time(_maxDurSec,_maxDurUsec);
00471    }
00474    Time getMaxSamplPeriod(){
00475     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00476    }
00479    Time getMinSamplPeriod(){
00480     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00481    }
00482    
00484    TaskOutputs run();
00485    
00486   private:
00487    
00489    void _readIdsFile();
00490    
00493    void _sendMessages(int hisId);
00494    
00496    void _writeSharedMem();
00497    
00499    void _writeSharedMemUav();
00500    
00502    void _syncCamObs();
00503    
00505    void _draw();
00506    
00508    map<int,Pose> _computeGT(const PosiFeatures3DTimeArma& pos, int index);
00509    
00511    void _computeGTDyn();
00512    
00514    void _saveGT();
00515    
00517    void _saveImPlaneMeas();
00518  };
00519  
00520  /* @} */
00521  
00522 };// end namespace MipTasks
00523 
00524 
00525 
00526 #endif
00527 
00528 
00529 
00530 

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