UAVPositioningSystem.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011  Antonio Franchi and Luca Ricci
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 __UAV_POSITIONING_SYSTEM_TASK_H_
00040 #define __UAV_POSITIONING_SYSTEM_TASK_H_
00041 
00042 #include <Task.h>
00043 #include <Resource.h>
00044 #include <VisualOdometryPTAMM.h>
00045 #include <CommonOptions.h>
00046 #include <Time.h>
00047 #include <Camera.h>
00048 #include <Uav.h>
00049 #include "HBstructs.h"
00050 #include <Keyboard.h>
00051 #include <TooN/se3.h>
00052 #include <TooN/TooN.h>
00053 #include <math.h>
00054 #include <Imu_sensor/Imu_sensor.h>
00055 #include <LocUavFilter.h>
00056 
00057 #ifndef MIP_PLATFORM_ARM
00058 #include <DraWin.h>
00059 #endif
00060 
00061 using namespace MipResources;
00062 using namespace MipAlgorithms;
00063 using namespace TooN;
00064 
00065 namespace MipTasks{
00066 
00068  /* @{ */
00069 
00073         enum UAVPositioningSystemTypes{
00074   UAV_POSITIONING_SYSTEM_TYPE,
00075                 UAV_POSITIONING_SYSTEM_TYPE_NUM
00076  };
00077 
00078         static const char * UAVPositioningSystemTypesNames[UAV_POSITIONING_SYSTEM_TYPE_NUM] ={
00079   "type"
00080  };
00081 
00082  enum UAVPositioningSystemStates{
00083   UAV_POSITIONING_SYSTEM_FIRST_RUN,                
00084   UAV_POSITIONING_SYSTEM_NORMAL_RUN,
00085                 UAV_POSITIONING_SYSTEM_PTAMM_FIRST_STATE,
00086                 UAV_POSITIONING_SYSTEM_PTAMM_SECOND_STATE,
00087                 UAV_POSITIONING_SYSTEM_PTAMM_THIRD_STATE,
00088                 UAV_POSITIONING_SYSTEM_PTAMM_FOURTH_STATE,
00089                 UAV_POSITIONING_SYSTEM_PTAMM_FIFTH_STATE,
00090                 UAV_POSITIONING_SYSTEM_PTAMM_NAVIGATION,
00091                 UAV_POSITIONING_SYSTEM_LAST_RUN,
00092   UAV_POSITIONING_SYSTEM_STATES_NUM
00093  };
00094 
00097  static const char* UAVPositioningSystemStatesNames[UAV_POSITIONING_SYSTEM_STATES_NUM] = {
00098   "FirstRun",
00099   "NormalRun",
00100                 "LastRun"
00101  };
00102 
00103 
00107  class UAVPositioningSystemOptions : public Options {
00108   public:
00110    DecimalOption* decimalOption;
00112    IntOption*   intOption;
00113    StringOption* LogFilePathOption;
00114                         //ESEMPIO DA VISUAL HOVERING
00115                         //StringOption    *log_path;          ///< Path top save log file.
00116                         //StringOption    *log_name;          ///< Name of log file.
00118    UAVPositioningSystemOptions();
00119 
00120    string getObjectName() const {
00121     return "UAVPositioningSystemOptions";
00122    }
00123  };
00124 
00125  class UAVPositioningSystemVar{
00126   public:
00127  };
00128 
00132  class UAVPositioningSystem : public Task{
00133   private:
00134 
00135    /* MANDATORY VARIABLES OF MIP TASKS */
00136    static const TaskPlate _plate = UPS_TASK;
00137 
00141    static const long int  _maxDurSec  = 0,      _maxDurUsec = 800000;
00142    static const long int  _maxSamplPeriodSec = 1, _maxSamplPeriodUsec = 800000;
00143    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec = 500;
00144    /* ------------------------------- */
00145 
00146                         /* PRIVATE VARIABLES OF THE TASK */
00147                         UAVPositioningSystemOptions _options;
00148                         UAVPositioningSystemVar*    _var;
00149                         UAVPositioningSystemStates  _state;
00150                         bool _stateTransition;
00151 
00152                         // RESOURCES
00153    Uav  *_uav;          
00154    Camera *_cam;   
00155                         Keyboard* _keyboard;        
00156                         Imu_sensor* _imu;
00157 
00158                         // ALGORITHMS
00159    // Visual Odometry communication module
00160                         VisualOdometryPTAMM* _vOdo;
00161    // Ekf implementation
00162    LocUavFilterVar* filterVars;
00163    LocUavFilterParam* filterParams;
00164    RootEKF*  filter;
00165 
00166                         // MEASUREMENTS
00167                         // Variables for PTAMM's measurements
00168                         Time t;      
00169                         IplImage*_frame;                                
00170                         Pose3DandTime ptammRecData;                     
00171                         Pose3DandTime ptammSndData;                     
00172                         Time ptammMeasTime;
00173                         Decimal ptammDelay;
00174 
00175                         // Variables for Gazebo's measurements
00176                         Decimal uav_acc_x, uav_acc_y, uav_acc_z;   
00177                         Decimal uav_vel_x, uav_vel_y, uav_vel_z;   
00178                         Decimal uav_pos_x, uav_pos_y, uav_pos_z;   
00179                         Decimal uav_roll, uav_pitch, uav_yaw;      
00180                         Decimal uav_omegaX, uav_omegaY, uav_omegaZ;
00181                         // Some variables to compute acceleration from Gazebo
00182                         // previous velocity, previous time, time delta
00183                         Decimal uav_prevVel_x, uav_prevVel_y, uav_prevVel_z;
00184                         Time uav_time;
00185                         Time uav_prevTime;
00186                         Decimal uav_simDeltaTime;
00187                         // Trajectory assigned in GAZEBO
00188                         Decimal traj[3];
00189                         // PTAMM INITIALIZATION
00190                         // Variables to compute PTAMM scale (UAV start position)
00191                         // Variables for realigning PTAMM's frame to Gazebo's frame
00192                         Pose3DandTime uavStart, uavEnd;
00193                         Decimal ptammScale; 
00194                         Decimal diff_x, diff_y, diff_z, diff_roll, diff_pitch, diff_yaw;
00195                         // Rototranslation matrices
00196                         SE3<> GazFrame_T_mipBodyFrame;
00197                         SE3<> mipBodyFrame_T_Cam;           // NOT USED
00198                         SE3<> Cam_T_PtammFrame;             // NOT USED
00199                         SE3<> GazFrame_T_PtammFrame;        // NOT USED
00200 
00201                         // EKF FILTER - DATA FUSION
00202                         vector<Decimal> filterMeas[9];  
00203                         vector<Decimal> refMeas[7];     
00204                        
00205                         // LOG variables
00206                         // text log file
00207                         ofstream uavLogFile_Gazebo;     // log of data from Gazebo
00208       
00209                         bool gazLogAct;
00210                         // Graphical output window
00211                         DraWin*      _draWin;   
00212    unsigned int _drawList; 
00213    bool         dwOn;      
00214                         /* ------------------------------ */
00215 
00216    /* PRIVATE METHODS OF THE TASK */
00217    void _firstRun();                        
00218                         void _ptammFirstState();
00219                         void _ptammSecondState();
00220                         void _ptammThirdState();
00221                         void _ptammFourthState();
00222                         void _ptammNavigation();
00223    void _normalRun();
00224    void _lastRun();
00225                         /* -------------------------- */
00226                         /* ---------UTILITIES-------- */
00227                         inline bool readFromGazebo(Decimal *posX, Decimal *posY, Decimal *posZ,
00228                                                   Decimal *velX, Decimal *velY, Decimal *velZ,
00229                                                   Decimal *accX, Decimal *accY, Decimal *accZ,
00230                                                   Decimal *roll, Decimal *pitch, Decimal *yaw);
00231                         inline SE3<> computeTransMatrix(Decimal roll, Decimal pitch, Decimal yaw,
00232                                                         Decimal trans_x, Decimal trans_y, Decimal trans_z );
00233                         inline void applyTransformToVector(SE3<> transform, Decimal *x, Decimal *y, Decimal *z);
00234                         inline void logGazMeas();
00235                         /* -------------------------- */
00236   public:
00238    UAVPositioningSystem(ResourcePointers resources,int argc, const char* argv[]);
00239 
00241    ~UAVPositioningSystem();
00242 
00243                         /* MANDATORY METHODS OF MIP TASK */
00244    TaskPlate getPlate() const {
00245     return _plate;
00246    }
00249    Time getMaxDuration(){
00250     return Time(_maxDurSec,_maxDurUsec);
00251    }
00254    Time getMaxSamplPeriod(){
00255     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00256    }
00259    Time getMinSamplPeriod(){
00260     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00261    }
00262    TaskOutputs run();
00263  };
00264 };// end namespace MipTasks
00265 
00266 #endif
00267 
00268 
00269 
00270 
00271 

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