Deploy.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 
00026 
00027 #ifndef __DEPLOY_H_
00028 #define __DEPLOY_H_
00029 
00030 
00031 #include <math.h>
00032 
00033 #include <Task.h>
00034 #include <Resource.h>
00035 #include <MobileRob.h>
00036 #include <CommModule.h>
00037 #include <DraWin.h>
00038 #include <ProtrusionExtr.h>
00039 #include <Voronoi.h>
00040 #include <CommonOptions.h>
00041 #include <Serialization.h>
00042 
00043 #include <CGAL/IO/Geomview_stream.h>
00044 #include <CGAL/IO/Triangulation_geomview_ostream_2.h>
00045 
00046 #include <CGAL/Polygon_with_holes_2.h>
00047 #include <CGAL/Polygon_set_2.h>
00048 #include <CGAL/Boolean_set_operations_2.h>
00049 
00053 
00057 
00058 using namespace MipAlgorithms;
00059 using namespace MipResources;
00060 
00061 
00062 namespace MipTasks{
00063  
00065  /* @{ */
00066  
00067  typedef CGAL::Polygon_with_holes_2<K>         Polygon_with_holes_2;
00068  typedef CGAL::Polygon_set_2<K>                Polygon_set_2;
00069  
00070  
00073  class DeployOptions : public Options {
00074   public:
00075    
00076    IntOption*   deployAlgo;
00077    IntOption*   deployCommOn;
00078    DecimalOption* deployCommRange;
00079    DecimalOption* deployEnvMaxDim;
00080    IntOption*   deployFillScan;
00081    IntOption*   deployComputeCoverage;
00082    
00083    DeployOptions(){
00084     /*default values*/
00085     deployAlgo = createIntOption(string("deployAlgo"),string("0 centroid (default), 1 weighted normal, 2 circumcenter  "),0);
00086     deployCommOn = createIntOption(string("deployCommOn"),string("0 communication disabled, 1 communication enabled"),1);
00087     deployCommRange = createDecimalOption(string("deployCommRange"),string("communication range (meters) [default: not limited]"),0.0);
00088     deployEnvMaxDim = createDecimalOption(string("deployEnvMaxDim"),string("environment max dimension (meters)"),4.0);
00089     deployFillScan = createIntOption(string("deployFillScan"),string("0 scan filling disabled, 1 scan filling enabled"),1);
00090     deployComputeCoverage = createIntOption(string("deployComputeCoverage"),string("0 coverage computing disabled, 1 coverage computing enabled"),0);
00091     
00092     updateValues();
00093    
00094    }
00095    
00096    string getObjectName() const{
00097      return "DeployOptions";
00098    }
00099  };
00100  
00101  
00103  enum DeployState{
00104   DEPLOY_FIRST_RUN,
00105   DEPLOY_SETUP_RUN,
00106   DEPLOY_NORMAL_RUN,
00107   DEPLOY_NUM_RUNS
00108  };
00109  
00111  enum DeployAlgo{
00112   CENTROID_ALGO=0, //does not limit the laser range
00113   WEIGHTED_NORMAL_ALGO=1,
00114   CIRCUMCENTER_ALGO=2,
00115   DEPLOY_NUM_ALGO
00116  };
00117  
00122  typedef vector<Position> ScanPoints;
00123  
00124  
00128  class DeployTask : public Task{
00129   private:
00130    
00131    static const TaskPlate _plate = DPL_TASK;
00132    static const long int _maxDurSec  = 0, _maxDurUsec = 700000;
00133    static const long int  _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 250000;
00134    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 100000;
00135    
00136    static const long int DEPLOY_GV_ON_DEFAULT = 0;
00137    static const long int DEPLOY_DW_ON_DEFAULT = 1;
00138    static const long int TRACE_ON_DEFAULT = 1;
00139    
00140    static const int OTHER_POS_RESERV_SIZE = 10;
00141    static const int SETUP_RUNS = 100;
00142    
00143    MobileRob* _mobileRob;
00144    CommModule* _commModule;
00145    
00146    DraWin*   _draWin;
00147    unsigned int _drawList;
00148    bool dwOn;
00149    
00150    CGAL::Geomview_stream* gv;
00151    bool gvOn;
00152    
00153    bool traceOn;
00154    
00155    DeployState state;
00156    
00158    DeployAlgo algo;
00159    
00161    Voronoi voronoi;
00162    
00164    Scan scan;
00165    
00167    int robId;
00169    Position robPosition;
00171    Pose robPose;
00173    Pose lastRobPose;
00175    ScanPoints robScanPoints;
00177    Decimal robTraveledDistance;
00178    
00180    Decimal goalReachedEps;
00182    int goalReachedCnt;
00184    int goalReachedThre;
00185    
00187    Position target;
00189    Position targetAbs;
00190    
00192    Decimal radius;
00193      
00195    bool commOn;
00197    Decimal commRange;
00199    Decimal envMaxDim;
00200    
00201    DeployOptions options;
00202    
00204    PosiFeatures otherRobotPositions;
00206    map<int,Pose> otherRobotPoses;
00207    map<int,Pose>::iterator otherRobotPosesIt;
00209    map<int,Decimal> otherRobotTraveledDistance;
00210    map<int,Decimal>::iterator otherRobotTraveledDistanceIt;
00212    map<int,ScanPoints> otherRobotScanPoints;
00213    map<int,ScanPoints>::iterator otherRobotScanPointsIt;
00215    vector<Polygon_with_holes_2> coveragePolygons;
00216    vector<Polygon_with_holes_2>::const_iterator coveragePolygonsIt;
00217    
00219    Decimal traveledDistance;
00221    Decimal coverageArea;
00222    
00224    Decimal limitedRange;
00225    bool limitedRangeOn;
00227    bool useSectors;
00228    
00229      
00231    void firstRun();
00233    void normalRun();
00235    void getCommPackets();
00237    void sendPoseAndScan();
00239    bool getPoseAndScan();
00241    void getOtherRobPosi();
00243    void computeVoronoiRegion();
00245    void chooseTarget();
00247    void computeTraveledDistance();
00249    void computeCoverage();
00253    Decimal polygonWithHolesArea(const Polygon_with_holes_2 & pwh);
00255    void computeCoverageArea();
00256    
00261    void drawPolygon(const Polygon_2 & p, Color c, int sampling=1);
00266    void drawPolygonWithHoles(const Polygon_with_holes_2 & pwh, Color c, int sampling=1);
00271    void drawCoverage(Color c, int sampling=1);
00273    void draw();
00274    
00275   public:
00277    DeployTask(ResourcePointers resources,int argc, const char* argv[]);
00278    
00280    ~DeployTask(){
00281    }
00282  
00284    TaskPlate getPlate() const {
00285     return _plate;
00286    }  
00288    Time getMaxDuration(){
00289     return Time(_maxDurSec,_maxDurUsec);
00290    }
00292    Time getMaxSamplPeriod(){
00293     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00294    }
00296    Time getMinSamplPeriod(){
00297     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00298    }
00299  
00300    TaskOutputs run(){
00301     static int setupRunCnt = 0;
00302  
00303     switch(state){
00304      case DEPLOY_FIRST_RUN:
00305       firstRun();
00306       state = DEPLOY_SETUP_RUN;
00307       break;
00308      case DEPLOY_SETUP_RUN: {
00309       setupRunCnt++;
00310       if (setupRunCnt>SETUP_RUNS) state = DEPLOY_NORMAL_RUN;
00311       break;
00312      }
00313      case DEPLOY_NORMAL_RUN:
00314       normalRun();
00315       break;
00316     }
00317     return TASK_OUT_GO_ON;
00318    }
00319  
00320  };
00321  
00322  /* @} */
00323  
00324 };//end namespace MipTasks
00325 
00326 #endif
00327 
00328 
00329 

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