FormUpdate.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 __FORM_UPDATE_H_
00037 #define __FORM_UPDATE_H_
00038 
00039 
00040 #include <Task.h>
00041 #include <Resource.h>
00042 #include <MobileRob.h>
00043 #include <DraWin.h>
00044 #include <SharedMem.h>
00045 #include <Time.h>
00046 
00047 #include <CommonOptions.h>
00048 #include <CommModule.h>
00049 
00050 using namespace MipResources;
00051 
00052 
00053 namespace MipTasks{
00054  
00056  /* @{ */
00057  
00061  class FormUpdateSharedMem : public SharedMem{
00062   public:
00064    void initSharedMem(){
00065     if (formation == NULL){
00066      formation = new PoseFeatures;
00067     }
00068     if (estimates == NULL){
00069      estimates = new PoseFeatures;
00070     }
00071    }
00072    
00074    bool doMloc(){
00075     return _doMloc;
00076    }
00077    
00079    PoseFeatures getEstimates(){
00080     return *estimates;
00081    }
00083    PoseFeatures getFormation(){
00084     return *formation;
00085    }
00087    void setFormation(PoseFeatures &form){
00088     *formation = form;
00089    }
00090  };
00091  
00092  
00096  class FormUpdate : public Task{
00097   private:
00098    static const TaskPlate _plate = FUP_TASK;
00099    static const long int  _maxDurSec  = 0,     _maxDurUsec = 30000;
00100    static const long int  _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 200000;
00101    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 100000;
00102    
00103    MobileRob* _mobileRob;  
00104  //  Position   robPosition; ///TODO
00105  //  Pose       robPose;     ///TODO
00106    
00107    DraWin*      _draWin;   
00108    unsigned int _drawList; 
00109    bool         dwOn;      
00110    
00111    FormUpdateSharedMem*  _sharedMem;
00112    
00113    CommModule* _commModule;
00114    
00115    map<int, Pose> othersPose;
00116  //   map<int, bool> othersPoseActive;
00117    
00118    int myId;
00119    Pose myPose;
00120    
00121    PoseFeatures formation;
00122    
00123   public:
00125    FormUpdate(ResourcePointers resources,int argc, const char* argv[]){
00126     
00127     // richiedi una risorsa di tipo mobileRob
00128     _mobileRob = (MobileRob*) ResourceUtilities::macroResFromPlate(resources,MR_INIT,MR_END);
00129     if(_mobileRob == 0){
00130      fatalResourceNotPresent(MR_INIT);
00131     }
00132     
00133     // richiedi una risorsa di tipo commModule
00134     _commModule = (CommModule*) ResourceUtilities::macroResFromPlate(resources,CM_INIT,CM_END);
00135     if(_commModule == 0){
00136      fatalResourceNotPresent(CM_INIT);
00137     }
00138     // richiedi una box alla risorsa
00139     _commModule->requestBox(getPlate());
00140     
00141     // richiedi una risorsa di tipo SharedMem
00142     _sharedMem = (FormUpdateSharedMem*) ResourceUtilities::resFromPlate(resources,SHMEM_RES);
00143     if(_sharedMem == 0){
00144      fatalResourceNotPresent(SHMEM_RES);
00145     }
00146     _sharedMem->initSharedMem();
00147     
00148     dwOn = false;
00149     // controlla se richiesta la stampa su visualizer
00150     if (commonOptions->embVisOn->getValue() == 1){
00151      // richiedi la risorsa
00152      _draWin = (DraWin*) ResourceUtilities::macroResFromPlate(resources,DW_INIT,DW_END);
00153      // se richiesta ma non presente la risorsa dai un warning
00154      if(_draWin == 0){
00155       warningResourceNotPresent(DW_INIT);
00156      }
00157      // altrimenti attiva il bool di stampa
00158      else{
00159       dwOn = true;
00160      }
00161     }
00162     
00163     // se stampa attiva
00164     if (dwOn){
00165      while(!_draWin->addList(Time(0,1000),_drawList)){
00166       usleep(1000);
00167      };
00168     }
00169     
00170     // mi segno il mio Id
00171     myId = commonOptions->robotId->getValue();
00172     
00173     // inizializzazione della fifo
00174    }
00175  
00176    
00178    ~FormUpdate(){
00179     othersPose.clear();
00180  //    othersPoseActive.clear();
00181    }
00182  
00184    TaskPlate getPlate() const {
00185     return _plate;
00186    }  
00188    Time getMaxDuration(){
00189     return Time(_maxDurSec,_maxDurUsec);
00190    }
00192    Time getMaxSamplPeriod(){
00193     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00194    }
00196    Time getMinSamplPeriod(){
00197     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00198    }
00200    TaskOutputs run();
00201   
00202   private:
00203    
00205    void comunicate();
00206    
00208    void computeFormation();
00209    
00213    void draw();
00214  };
00215  
00216  /* @} */
00217  
00218 };// end namespace MipTasks
00219 
00220 #endif
00221 
00222 
00223 
00224 
00225 

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