FormControl.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011  Antonio Franchi and Antonio Franchi    
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 __FORM_CONTROL_TASK_H_
00040 #define __FORM_CONTROL_TASK_H_
00041 
00042 #include <Task.h>
00043 #include <Resource.h>
00044 #include <Uav.h>
00045 #include <UavControl.h>
00046 #include <ProtrusionExtr.h>
00047 #include <SharedMem.h>
00048 #include <CommonOptions.h>
00049 
00050 #include <CommModule.h>
00051 
00052 #ifndef MIP_PLATFORM_ARM
00053  #include <DraWin.h>
00054 #endif
00055 
00056 
00057 namespace MipTasks{
00058  
00060  /* @{ */
00061  
00065  enum FormControlTaskStates{
00066   FORM_CONTROL_FIRST_RUN,
00067   FORM_CONTROL_NORMAL_RUN,
00068    FORM_CONTROL_STATES_NUM
00069  };
00070  
00073  static const char* FormControlTaskStatesNames[FORM_CONTROL_STATES_NUM] = {
00074   "FirstRun",
00075   "NormalRun"
00076  };
00077  
00078  
00082  class FormControlTaskOptions : public Options {
00083   public:
00084    DecimalOption  *commPeriod;
00085    
00087    FormControlTaskOptions();
00088 
00089    string getObjectName() const {
00090     return "FormControlTaskOptions";
00091    }
00092  };
00093  
00094  
00098  class FormControlTaskSharedMem : public SharedMem{
00099   public:
00102    void initSharedMem();
00103  };
00104  
00105  
00109  class FormControlTask : public Task{
00110   private:
00111    
00112    static const TaskPlate _plate = FCT_TASK;
00113    
00114    static const long int  _maxDurSec  = 0,      _maxDurUsec = 100000;
00115    static const long int  _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 100000;
00116    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 5000;
00117    
00118    UavControlPar* _controlPar;
00119    UavControl* _uavControl;
00120    
00121    Uav*  _uav;
00122    
00123    CommModule* _commModule;
00124    
00125  #ifndef MIP_PLATFORM_ARM
00126    DraWin*      _draWin;   
00127    unsigned int _drawList; 
00128    bool         dwOn;      
00129  #endif
00130  
00131    FormControlTaskSharedMem* _sharedMem;
00132    
00133    FormControlTaskOptions _options;
00134    
00135    // Define here the local variables of your task.
00136    UavVar* _uavState;
00137    FormControlTaskStates _state;
00138    int _myId;
00139    
00140    stringstream _ssdebug;
00141    
00142    Timer _commSendTimer;
00143    Time _commSendPeriod;
00144    Timer _commRecTimer;
00145    Time _commRecPeriod;
00146    Time _maxPacketLifeTime;
00147    
00148    // associative array indexed by the robots id and containing the poses and
00149    // the ang vel of all the robot in communication range
00150    // maps are necesary because of multiple packets can be received  
00151    map<int,Position3D>      _receivedPositions;  
00152    map<int,Position3D>::iterator _itP; 
00153    map<int,Position3D>      _receivedVelocities; 
00154    map<int,Position3D>::iterator _itA; 
00155    map<int,Time>      _receivedTimeStamps;
00156    map<int,Time>::iterator _itT; 
00157    
00158    vector<Position3D> _otherRobotPosi; 
00159    vector<Position3D>  _otherRobotVel;  
00160    vector<int>     _otherRobotIds;  
00161    
00162    // Define here the private methods of your task.
00163    void _firstRun();
00164    void _normalRun();
00165    
00166    void _sendCommPackets();
00168    void _receiveCommPackets();
00169    bool _getOtherRobotPosi();
00170    
00171    
00172   public:
00174    FormControlTask(ResourcePointers resources,int argc, const char* argv[]);
00175    
00177    ~FormControlTask();
00178    
00180    TaskPlate getPlate() const {
00181     return _plate;
00182    }
00184    Time getMaxDuration(){
00185     return Time(_maxDurSec,_maxDurUsec);
00186    }
00188    Time getMaxSamplPeriod(){
00189     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00190    }
00192    Time getMinSamplPeriod(){
00193     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00194    }
00195    
00197    TaskOutputs run();
00198  };
00199  
00200  /* @} */
00201  
00202 };// end namespace MipTasks
00203 
00204 #endif
00205 
00206 
00207 
00208 
00209 

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