LineFollowing.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 __LINE_FOLLOWING_H_
00039 #define __LINE_FOLLOWING_H_
00040 
00041 
00042 #ifdef MIP_HOST_APPLE
00043 #include <applePatch.h>
00044 #endif
00045 
00046 #include <Task.h>
00047 #include <MobileRob.h>
00048 #include <MobileRob3D.h>
00049 // #include <PositionDetector3D.h>
00050 #include <Keyboard.h>
00051 #ifndef MIP_PLATFORM_ARM
00052 #include <DraWin.h>
00053 #endif
00054 #include <string.h>
00055 #include <math.h>
00056 #include <CommonOptions.h>
00057 #include <SharedMem.h>
00058 #include <FirFilter.h>
00059 
00060 using namespace MipResources;
00061 
00062 // #define LINVEL_STEP 0.02
00063 // #define ANGVEL_STEP 0.05
00064 namespace MipTasks{
00065  
00067  /* @{ */
00068  
00070  enum lineFollowingControls{
00071   LINE_FOLLOWING_CTRL_LINEAR,
00072   LINE_FOLLOWING_CTRL_ADAPTIVE,
00073   LINE_FOLLOWING_CTRL_NUM
00074  };
00075 
00076  static const char * lineFollowingControlNames[LINE_FOLLOWING_CTRL_NUM] ={
00077  "linear",
00078  "adaptive"
00079  };
00080  
00081  
00082  class LineFollowingOptions : public Options {
00083   static const Decimal khIIIblackLineValue;
00084   static const Decimal khIIIbwSharpBorderSlope; // line slope for Graduated Line
00085  //  static const Decimal khIIIbwSharpBorderSlope = 666666.666666; //line slope for black line
00086   
00087   public:
00088    IntOption* cmdType;
00089    DecimalOption* lineSlope;
00090    DecimalOption* colorValue;
00091    DecimalOption* gain;
00092    DecimalOption* cruiseSpeed;
00093    DecimalOption* cruiseControlPower;
00094    DecimalOption* timeFilter;
00095    DecimalOption* markUpGain;
00096    IntOption* fileFlag;
00097    IntOption* controlType;
00098    StringOption *fileName;
00099    DecimalOption* maxPolSpeed;
00100    DecimalOption* minCurvature;  
00101    DecimalOption* maxCurvature;
00102    DecimalOption* initSpeed;
00103    DecimalOption* minSpeed;
00104    DecimalOption* initTime;
00105    DecimalOption* irToAxisDistance;
00106    DecimalOption* maxEstimatedDistance;
00107 
00108    string getObjectName() const {
00109     return "LineFollowingOptions";
00110    }
00111  
00112    LineFollowingOptions(){
00113     cmdType       = createIntOption("lineFollowingCmdType",  "se 0 comanda veloGoal, se 1 comanda velo", 0);
00114     lineSlope      = createDecimalOption("lineFollowingLineSlope",  "Characteristic slope of the borders of the line to follow.", khIIIbwSharpBorderSlope);
00115     colorValue     = createDecimalOption("lineFollowingColorValue", "Value returned by the sensor when it is put on the line.", khIIIblackLineValue);
00116     gain         = createDecimalOption("lineFollowingGain", "Controller gain only for Linear Control.", 200.0);
00117     cruiseSpeed     = createDecimalOption("lineFollowingCruiseSpeed", "Cruise Speed.", 0.1);
00118     cruiseControlPower = createDecimalOption("lineFollowingControlPower", "ControlPower.", 4.0);
00119     timeFilter      = createDecimalOption("lineFollowingTimeFilter", "Time Filter.", 1.0);
00120     fileFlag       = createIntOption("lineFollowingFileFlag", "File Flag.", 0);
00121     markUpGain      = createDecimalOption("lineFollowingMarkUpGain", "Mark-Up Gain.", 30);
00122     controlType     = createIntOption("lineFollowingControlType", "Control Type.", 0);
00123     fileName      = createStringOption("lineFollowingFileName","","lineFollLog.dat");
00124     maxPolSpeed     = createDecimalOption("lineFollowingMaxPolSpeed","MaxPolSpeed",0.06);
00125     minCurvature    = createDecimalOption("lineFollowingMinCurvature","MinCurvature",2);
00126     maxCurvature    = createDecimalOption("lineFollowingMaxCurvature","MinCurvature",16);
00127     initSpeed      = createDecimalOption("lineFollowingInitSpeed","InitSpeed",0.02);
00128     minSpeed      = createDecimalOption("lineFollowingMinSpeed","MinSpeed",0.01);
00129     initTime      = createDecimalOption("lineFollowingInitTime","InitTime",6);
00130     irToAxisDistance  = createDecimalOption("lineFollowingIrToAxisDistance","irToAxisDistance",0.05784);
00131     maxEstimatedDistance= createDecimalOption("lineFollowingMaxEstimatedDistance","maxEstimatedDistance",0.006);
00132     
00133     updateValues();
00134    }
00135    
00136  };
00137  
00138  
00142  class LineFollowingSharedMem : public SharedMem{
00143   public:
00145    void initSharedMem(){
00146    }
00147    
00149    void togglePrintPose(){
00150     _printPose = !_printPose;
00151    }
00153    void togglePrintScan(){
00154     _printScan = !_printScan;
00155    }
00157    void togglePrintFeat(){
00158     _printFeat = !_printFeat;
00159    }
00161    void togglePrintFormation(){
00162     _printFormation = !_printFormation;
00163    }
00165    void togglePrintFormationDetails(){
00166     _printFormationDetails = !_printFormationDetails;
00167    }
00169    void togglePrintTarget(){
00170     _printTarget = !_printTarget;
00171    }
00173    void toggleDoMloc(){
00174     _doMloc = !_doMloc;
00175    }
00177    void toggleDoAutoNavigation(){
00178     _doAutoNavigation = !_doAutoNavigation;
00179    }
00180    
00181    
00182    
00183    bool printPose(){
00184     return _printPose;
00185    }
00186    bool printScan(){
00187     return _printScan;
00188    }
00189    bool doMloc(){
00190     return _doMloc;
00191    }
00192    bool doAutoNavigation(){
00193     return _doAutoNavigation;
00194    }
00195    
00196  };
00197  
00198  
00202  enum LineFollowingPhases{
00203   LINEFOLLOW_INIT,
00204   LINEFOLLOW_CONTROL,
00205   LINEFOLLOW_EXIT,
00206   LINEFOLLOW_NUM
00207   
00208  };
00209  
00210  
00213  class LFDistanceEstimator {
00214   private:
00215    Decimal _lineValue;
00216    Decimal _lineSlope;
00217   public:
00218    LFDistanceEstimator(Decimal lineValue=0.0, Decimal lineSlope=1.0){
00219     _lineValue =  lineValue;
00220     _lineSlope = lineSlope;
00221    }
00222  
00223    
00228    Decimal estimate(Decimal _leftReading,Decimal _rightReading){
00229     Decimal leftDistance = (_leftReading - _lineValue) / _lineSlope;
00230     Decimal rightDistance = -(_rightReading - _lineValue) / _lineSlope;
00231     return leftDistance + rightDistance;
00232    }
00233  
00234  
00235  };
00236  
00237  
00268  class LineFollowing : public Task{
00269  
00270   private:
00271    static const TaskPlate _plate = LNF_TASK;
00272    static const long int  _maxDurSec  = 0,    _maxDurUsec   = 300000;
00273    static const long int  _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 300000;
00274    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 10000;
00275   
00276  
00277    Keyboard*  _keyboard; 
00278    MobileRob*   _mobileRob; 
00279    MobileRob3D*   _mobileRob3D; 
00280    //PositionDetector3D*  _positionDetector3D; ///<
00281    MotionModule*  _motionModule; 
00282    LineFollowingSharedMem*   _sharedMem;
00283  
00284    LineFollowingPhases _status;
00285    LineFollowingOptions _options;
00286    
00287    LFDistanceEstimator* distanceEstimator;
00288    string _String;
00289    
00290    int _fileFlag;
00291    int _controlType;
00292    Decimal _gain;
00293    Decimal _cruiseSpeed;
00294    Decimal _maxPolSpeed;
00295    Decimal _lineSlope;
00296    Decimal _cruiseControlPower;
00297    Decimal _timeFilter;
00298    Decimal _markUpGain;
00299    Decimal _leftReading;
00300    Decimal _rightReading;
00301    vector<int> _infraredMeasures;
00302    ofstream _myfile;
00303    Pose _pose;
00304    Decimal _linVel;
00305    Decimal _angVel;
00306    Decimal _velOpt;
00307    Decimal _curvature;
00308    Decimal _curvatureFiltered;
00309    Decimal _alpha;
00310    Decimal _drive;
00311    Decimal _turnrate;
00312    Decimal _minCurvature;
00313    Decimal _maxCurvature;
00314    Decimal _initSpeed;
00315    Decimal _minSpeed;
00316    Decimal _initTime;
00317    Decimal _irToAxisDistance;
00318    Decimal _maxEstimatedDistance;
00319  
00320    
00321    Timer _timer;
00322    bool _curvatureFlag;
00323    bool _doControl;
00324    bool _useMobileRob;
00325    bool _useMotionModule;
00326    bool _useMobileRob3D;
00327    
00328    lineFollowingControls  _controlType1;
00329  //   bool usePositionDetector3D;
00330  
00331  #ifndef MIP_PLATFORM_ARM
00332    DraWin* _draWin;
00333    unsigned int _drawList; 
00334    bool         dwOn;
00335  #endif
00336  
00337    bool rangeSensOn;
00338    bool rangeSensPrint;
00339    
00340    FirFilter *curvatureFilter;
00341    
00342    void _lineFollowingInit();
00343    void _lineFollowingControl();
00344    void _recovery();
00345    
00346   public:
00351    LineFollowing(ResourcePointers resources,int argc, const char* argv[]);
00352    
00354    ~LineFollowing(){
00355     cout << "destr LineFollowingTask" << endl;
00356    }
00357    
00359    TaskPlate getPlate() const {
00360     return _plate;
00361    }  
00363    Time getMaxDuration(){
00364     return Time(_maxDurSec,_maxDurUsec);
00365    }
00367    Time getMaxSamplPeriod(){
00368     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00369    }
00371    Time getMinSamplPeriod(){
00372     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00373    }
00374    
00375    
00376    
00378    TaskOutputs run();
00379  };
00380  
00381  /* @} */
00382  
00383 };// end namespace MipTasks
00384 
00385 #endif
00386 
00387 
00388 
00389 
00390 

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