ScanMatching.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 
00034 
00035 
00036 
00037 
00038 #ifndef __SCAN_MATCHING_H_
00039 #define __SCAN_MATCHING_H_
00040 
00041 #ifdef MIP_HOST_APPLE
00042 #include <applePatch.h>
00043 #endif
00044 
00045 #include <fstream>
00046 
00047 #include <baselib.h>
00048 #include <ScanMap.h>
00049 #include <Task.h>
00050 #include <Resource.h>
00051 #include <MobileRob.h>
00052 #include <SharedMem.h>
00053 #include <Keyboard.h>
00054 #include <Time.h>
00055 #include <DraWin.h>
00056 
00057 #include <ExternScanMatch.h>
00058 #include <CommonOptions.h>
00059 
00060 
00061 using namespace MipResources;
00062 
00063 
00064 namespace MipTasks{
00065  
00067  /* @{ */
00068  
00069  
00075  class ScanMatchingOptions : public Options {
00076   public:
00077    DecimalOption* minSamplTime;
00078    DecimalOption* maxLinDist;
00079    DecimalOption* maxAngDist;
00080    DecimalOption* maxPosCorrection;
00081    DecimalOption* maxAngCorrection;
00082    DecimalOption* maxReading;
00083    DecimalOption* minReading;
00084    DecimalOption* preprocTresh;
00085    StringOption*  mapFileName;
00086    DecimalOption* maxMapLinDist;
00087    DecimalOption* maxMapAngDist;
00088    IntOption*   customDebugLevel;
00089    StringOption*  correct;
00090    
00091    ScanMatchingOptions();
00092 
00093    string getObjectName() const {
00094     return "ScanMatchingOptions";
00095    }
00096  };
00097  
00098  
00102  class ScanMatchingSharedMem : public SharedMem{
00103   public:
00105    void initSharedMem(){
00106    }
00107  };
00108  
00109  
00113  enum ScanMatchingPhases{
00114   SCANMATCH_GET_FIRST_SCAN_ONLY,
00115   SCANMATCH_WAIT_MIN_SAMPL_TIME_OR_GET_SCAN_AND_START_MATCH,
00116   SCANMATCH_WAIT_RESULT_OR_WRITE_IT,
00117   SCANMATCH_NUM
00118  };
00119  
00120  
00140  class ScanMatching : public Task{
00141   private:
00142    static const TaskPlate _plate = SCM_TASK;
00143    static const long int  _maxDurSec  = 0,     _maxDurUsec = 200000;
00144    static const long int  _maxSamplPeriodSec = 1, _maxSamplPeriodUsec = 0;
00145    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 100000;
00146    
00147    MobileRob* _mobileRob;
00148    
00149    ScanMatchingSharedMem *_sharedMem;
00150    ExternScanMatch  *_externScanMatcher;
00151    Keyboard *_keyboard;
00152    
00153  #ifndef MIP_PLATFORM_ARM
00154    DraWin* _draWin;
00155    unsigned int _drawList;
00156    unsigned int _robotDrawList;
00157  #endif
00158    
00159    Timer _drawTimer;
00160    
00161    string _keyCommand;
00162    
00163    Timer _minSamplTimeTimer;
00164    Time _minSamplTime;
00165    Decimal _maxLinDist;
00166    Decimal _maxAngDist;
00167    Decimal _maxPosCorrection;
00168    Decimal _maxAngCorrection;
00169    Decimal _maxReading;
00170    Decimal _minReading;
00171    Decimal _preprocTresh;
00172    
00173    bool _checkTime;
00174    bool _checkLinDist;
00175    bool _checkAngDist;
00176    bool _checkPosCorrection;
00177    bool _checkAngCorrection;
00178    bool _doPreprocessing;
00179    bool _useMap;
00180    bool _correct;
00181    
00182    Timer _smExecStatTimer;
00183    
00184    ScanMatchingPhases _status;
00185    ScanMatchingOptions _options;
00186    
00187    Pose _firstPose;
00188    MotionModuleTState _firstTState;
00189    Scan _firstScan;
00190    MotionModuleTState _secondTState;
00191    Pose _secondPose;
00192    Scan _secondScan;
00193    
00194  //   Pose _mapFirstPose;
00195  //   MotionModuleTState _mapFirstTState;
00196  //   Scan _mapFirstScan;
00197    
00198    Scan _backuppedFS;
00199    Scan _backuppedSS;
00200    
00201    Pose _globalPoseError;
00202    Pose _stepPoseError;
00203    
00204    Pose _correctedSecondPose;
00205    
00206    Decimal _linRangeMax;
00207    int _scanNumRays;
00208    
00209    ScanMap* _map;
00210    int _mapBisquit;
00211    Decimal _maxMapLinDist;
00212    Decimal _maxMapAngDist;
00213    
00214    stringstream _debugss;
00215    
00216    Pose _voidCorrections(Pose& firstGuessedPose,Pose& proposedCorrectedPose, bool validResult);
00217    void _voidExceedingReadings(Scan &s);
00218    void _voidReciprocalFarReadings(Scan& firstScan,Pose& firstPose,Scan& secondScan,Pose& secondPose);
00219    
00220    void _drawFirstScan();
00221    void _drawScanPair();
00222    void _drawCurrentRobot();
00223    void _drawCurrentRobotAndScan();
00224    
00225    Pose _predictedPose(Pose currentPose);
00226    
00227    void _preprocessingIn();
00228    void _preprocessingOut();
00229    
00230    void _getFirstScanOnly();
00231    void _waitMinSamplTimeOrGetScanAndStartMatch();
00232    void _waitResultOrWriteIt();
00233    void _recovery();
00234    
00235   public:
00240    ScanMatching(ResourcePointers resources,int argc, const char* argv[]);
00241    
00243    ~ScanMatching();
00244    
00248    TaskPlate getPlate() const{
00249     return _plate;
00250    }
00251    
00254    Time getMaxDuration(){
00255     return Time(_maxDurSec,_maxDurUsec);
00256    }
00257    
00260    Time getMaxSamplPeriod(){
00261     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00262    }
00263    
00266    Time getMinSamplPeriod(){
00267     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00268    }
00269    
00271    TaskOutputs run();
00272  };
00273  
00274  /* @} */
00275  
00276 };// end namespace MipTasks
00277 
00278 #endif
00279 
00280 
00281 
00282 
00283 

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