Pursuing.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 #ifndef __PURSUING_H_
00037 #define __PURSUING_H_
00038 
00039 #ifdef MIP_HOST_APPLE
00040 #include <applePatch.h>
00041 #endif
00042 
00043 #include <fstream>
00044 
00045 #include <R2.h>
00046 #include <Grid.h>
00047 #include <Scan.h>
00048 
00049 #include <Task.h>
00050 #include <Resource.h>
00051 #include <MobileRob.h>
00052 #include <SharedMem.h>
00053 #include <Time.h>
00054 
00055 #include <CommonOptions.h>
00056 #include <CommModule.h>
00057 #include <PursuingData.h>
00058 #include <PursuingComm.h>
00059 
00060 using namespace MipResources;
00061 
00062 namespace MipTasks{
00063  
00065  /* @{ */
00066 
00067  
00072  class PursuingOptions : public Options {
00073   public:
00074  //    DecimalOption* minSamplTime;
00075    IntOption* customDebugLevel;
00076  
00077  
00078    PursuingOptions(){
00079  //    minSamplTime = new DecimalOption("scanMatchingSampleTime", "Suggested time between two scans to match, in seconds, <= 0.0 means never checked.", 2.0);
00080      customDebugLevel = new IntOption("PursuingDebugLevel", "Custom debug level of the Pursuing task.", 3);
00081  
00082  //    
00083  //    list.push_back(minSamplTime);
00084    }
00085  };
00086 
00087  // /// \class PursuingSharedMem
00088 // /// \brief Shared memory for the scan matching.
00089 // /// \author Antonio Franchi, Joey Durham and Arnaud Dufranne
00090 // class PursuingSharedMem : public SharedMem{
00091 //  public:
00092 //   /// init function for the PursuingSharedMem
00093 //   void initSharedMem(){
00094 //   }
00095 // };
00096 
00097  typedef std::vector<Position > PositionPath;
00098  typedef std::vector<Position > ViewPoints;
00099  
00100  int gMinArcSize = 2;
00101  int gMinMergeArcSize = 1;
00102  int gMinRadialArcSize = 3;
00103  
00104  
00109  class Pursuing : public Task{
00110   private:
00111    static const TaskPlate _plate = PUR_TASK;
00112    static const long int  _maxDurSec  = 0,     _maxDurUsec = 30000;
00113    static const long int  _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 200000;
00114    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 100000;
00115    
00116    MobileRob* _mobileRob;
00117    CommModule* _commModule;
00118    PursuingComm *_pursuingComm;
00119    
00120    uint _robotId;
00121  //   PursuingSharedMem* _sharedMem;
00122    
00123    PursuingOptions _options;
00124    
00125    PursuingStates _state;
00126    PursuingGuardStates _frontGuardSubState; //substate for the frontierGuard
00127    PursuingGuardUpdatingStates _frontGuardUpdatingSubState; //substate for the Updating Frontier Guard
00128    PursuingWandererStates _wandererSubState; //substate for the wanderer
00129    
00130    Frontier _frontier;
00131    Frontier _freeArcs;
00132    Frontier _prevFrontier;
00133    Grid _LSR;
00134    Grid _prevLSR;
00135    bool _bFrontierInitialized;
00136    
00137    //Pose _goalPose;
00138    int _iLeader;
00139    //int _iWaitForAgent
00140    
00141    // If an int so we can set it to -1 when not waiting, but have to check when using it that it's > 0
00142    int _iWaitForAgent;// i wait for an agent
00143  //   uint _waitedForAgent;//id of the agent we wait for
00144    
00145    map<uint,PursuingMessageTypes > _asynRequests;//list of asyncrequest, documentation in _updateGuardList
00146    vector<uint> _followers;
00147    map<uint,GuardUpdatingState> _localGuards; //the table containing the local guards and their state in the protocol
00148    map<uint,PursuingStates> _neighborStates; //the last received States of the neighbours
00149    map<uint,TimeStampedPose> _neighborPoses; // the last received Poses of the neighbours
00150  
00151    void _expand( );
00152    
00153    void _guardUpdating( ); //subfunction of _guard()
00154    void _guardPlanning(); //subfunction of _guard()
00155    void _guardIdleSendingFollower( ); //subfunction of _guard()
00156    void _guardIdle( ); //subfunction of _guard()
00157    
00158    void _follow( );
00159    void _wander( );
00160    void _wanderWaiting();
00161    
00162    void _recordLSR();
00163    Position _pickBestViewpoint( uint *iNumViewPoints );
00164    bool _isCellCovered( DubInt iViewPoint, DubInt iCell );
00165    ExplorationParams _getExplParams();
00166    
00167    
00168  
00170    void _setToExpand( Pose goalPose );
00171    
00174    string getObjectName() const {
00175     stringstream ss;
00176     assert(getPlate()<TASK_NUM);
00177     
00178     ss << TaskNames[getPlate()] << ", Agent : "<< getId();
00179     return ss.str();
00180    }
00181    
00183    void _setToGuard( );
00184    
00186    void _setToFollow( uint leaderId );
00187    
00189    void _setToWander( );
00190    void _setToWanderWaitingForLeader( uint leaderId );
00191    
00193    void _printNeighbouringGuards();
00194    
00196    void _printAsyncRequests();
00197    
00200    void _updateAsynRequests();
00201    
00204    void _updateGuardList();
00205    
00208    bool _guardUpdatingDone();
00209    
00213    void _receiveGimmeYourFrontier(int &robIdTosendTo,bool &hasToSendFrontier);
00214    
00218    void _checkLocalGuardsArray(int &robIdToSendTo,bool &hasToSendFrontier );
00219    
00221    void _receiveFrontiers();
00222    
00224    void _receiveUpdatedFrontier();
00225  
00227    void _commonActions();
00228    
00231    bool _isWaitingForAnyAgent();
00232    
00234    void _updateFrontier();
00235    
00237    void _processFrontier();
00238   
00239   public:
00244    Pursuing(ResourcePointers resources,int argc, const char* argv[]);
00245    
00247    ~Pursuing();
00248    
00252    TaskPlate getPlate() const {
00253     return _plate;
00254    }
00257    Time getMaxDuration(){
00258     return Time(_maxDurSec,_maxDurUsec);
00259    }
00262    Time getMaxSamplPeriod(){
00263     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00264    }
00267    Time getMinSamplPeriod(){
00268     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00269    }
00271    TaskOutputs run();
00272    
00274    uint getId();
00275  };
00276  
00277  /* @} */
00278  
00279 };// end namespace MipTasks
00280 
00281 #endif
00282 
00283 
00284 
00285 
00286 

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