00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00115
00116
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
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
00147 UAVPositioningSystemOptions _options;
00148 UAVPositioningSystemVar* _var;
00149 UAVPositioningSystemStates _state;
00150 bool _stateTransition;
00151
00152
00153 Uav *_uav;
00154 Camera *_cam;
00155 Keyboard* _keyboard;
00156 Imu_sensor* _imu;
00157
00158
00159
00160 VisualOdometryPTAMM* _vOdo;
00161
00162 LocUavFilterVar* filterVars;
00163 LocUavFilterParam* filterParams;
00164 RootEKF* filter;
00165
00166
00167
00168 Time t;
00169 IplImage*_frame;
00170 Pose3DandTime ptammRecData;
00171 Pose3DandTime ptammSndData;
00172 Time ptammMeasTime;
00173 Decimal ptammDelay;
00174
00175
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
00182
00183 Decimal uav_prevVel_x, uav_prevVel_y, uav_prevVel_z;
00184 Time uav_time;
00185 Time uav_prevTime;
00186 Decimal uav_simDeltaTime;
00187
00188 Decimal traj[3];
00189
00190
00191
00192 Pose3DandTime uavStart, uavEnd;
00193 Decimal ptammScale;
00194 Decimal diff_x, diff_y, diff_z, diff_roll, diff_pitch, diff_yaw;
00195
00196 SE3<> GazFrame_T_mipBodyFrame;
00197 SE3<> mipBodyFrame_T_Cam;
00198 SE3<> Cam_T_PtammFrame;
00199 SE3<> GazFrame_T_PtammFrame;
00200
00201
00202 vector<Decimal> filterMeas[9];
00203 vector<Decimal> refMeas[7];
00204
00205
00206
00207 ofstream uavLogFile_Gazebo;
00208
00209 bool gazLogAct;
00210
00211 DraWin* _draWin;
00212 unsigned int _drawList;
00213 bool dwOn;
00214
00215
00216
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
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
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 };
00265
00266 #endif
00267
00268
00269
00270
00271