VisualHovering.h
Go to the documentation of this file.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
00026
00027
00028 #ifndef __VISUAL_HOVERING_H_
00029 #define __VISUAL_HOVERING_H_
00030
00031
00032 #ifdef MIP_HOST_APPLE
00033 #include <applePatch.h>
00034 #endif
00035
00036 #include <Uav.h>
00037 #include "HBstructs.h"
00038 #include <Time.h>
00039 #include <Camera.h>
00040 #include <VisualTracking.h>
00041
00042 #include <Task.h>
00043 #include <CommonOptions.h>
00044 #ifdef FOUND_VISP_LIBS
00045 #include <VisTrackVisp.h>
00046 #else
00047 #include <VisTrackCamshift.h>
00048 #endif
00049
00050 #include <armadillo>
00051
00052 using namespace MipResources;
00053 using namespace MipAlgorithms;
00054
00055 namespace MipTasks{
00059
00060
00064
00065
00068
00069
00073 enum visualHoveringTypes{
00074 VISUAL_HOVERING_CAMSHIFT,
00075 VISUAL_HOVERING_TYPES_NUM
00076 };
00077
00080 static const char * visualHoveringTypesNames[VISUAL_HOVERING_TYPES_NUM] ={
00081 "Camshift"
00082 };
00083
00087 enum VisualHoveringStates{
00088 VISUAL_OVERING_FIRST_RUN,
00089 VISUAL_OVERING_NORMAL_RUN,
00090 VISUAL_OVERING_LAST_RUN,
00091 VISUAL_OVERING_STATES_NUM
00092 };
00093
00096 static const char* VisualHoveringStatesNames[VISUAL_OVERING_STATES_NUM] = {
00097 "FirstRun",
00098 "NormalRun",
00099 "LastRun"
00100 };
00101
00102 class VisualHoveringOptions : public Options {
00103 public:
00104
00105 DecimalOption *trimRoll;
00106 DecimalOption *trimPitch;
00107 DecimalOption *trimYaw;
00108 IntOption *heightCtrlType;
00109
00110
00111 IntOption *algoType;
00112
00113 IntOption *visDepth;
00114
00115
00116 DecimalOption *inKAngle;
00117 DecimalOption *inKfeatErr;
00118 DecimalOption *inKintegral;
00119 BoolOption *use_omega;
00120
00121 StringOption *log_path;
00122 StringOption *log_name;
00123 BoolOption *make_log;
00124 BoolOption *make_video_log;
00125
00127 VisualHoveringOptions();
00128
00129 string getObjectName() const{
00130 return "VisualHoveringOptions";
00131 }
00132 };
00133
00134
00135 class VisualHoveringVar{
00136 public:
00137 Decimal ControlAngles[2];
00138 short ctrlEnable;
00139 ofstream _logFile;
00140 int _numrow;
00141 };
00142
00153 class VisualHovering : public Task {
00154 private:
00155 static const TaskPlate _plate = VHO_TASK;
00156
00157
00158 static const long int _maxDurSec = 0, _maxDurUsec = 50000;
00159 static const long int _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 35000;
00160 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 25000;
00161
00162
00163 Uav *_uav;
00164 Camera *_cam;
00165
00166
00167 #ifdef FOUND_VISP_LIBS
00168 VisTrackVisp* _visTrack;
00169 #else
00170 VisTrackCamshift* _visTrack;
00171 #endif
00172
00173
00174
00175 arma::Col<Decimal>::fixed<2> error_arma;
00176 arma::Col<Decimal>::fixed<2> des_angles_arma;
00177
00178 arma::Col<Decimal>::fixed<2> feat_arma;
00179 arma::Col<Decimal>::fixed<2> feat_dot_arma;
00180
00181 arma::Col<Decimal>::fixed<2> V_est_arma;
00182 arma::Col<Decimal>::fixed<2> V_des_arma;
00183 arma::Col<Decimal>::fixed<2> V_des_yaw_arma;
00184
00185 arma::Col<Decimal>::fixed<3> Omega_arma;
00186
00187 arma::Mat<Decimal>::fixed<2,2> J_V_arma;
00188 arma::Mat<Decimal>::fixed<2,3> J_Omega_arma;
00189 arma::Mat<Decimal>::fixed<2,2> J_V_pinv_arma;
00190 arma::Mat<Decimal>::fixed<2,2> yaw_rotation_arma;
00191
00192
00193
00194
00195 CvMat *cv_Omega;
00196
00197 IplImage* _frame;
00198 ImageFeature imgFeat;
00199 Time t;
00200
00201 VisualHoveringOptions _options;
00202 VisualHoveringVar* _var;
00203 VisualHoveringStates _state;
00204 visualHoveringTypes _types;
00205
00206 Decimal Kangle;
00207 Decimal KfeatureError;
00208 Decimal KfeatureError_old;
00209 Decimal Ki;
00210 Decimal error[2];
00211 Decimal cRoll, cPitch, cYaw, cPan, cTilt, sRoll, sPitch, sYaw, sPan, sTilt;
00212 Decimal Jv[4];
00213 Decimal mass;
00214
00215 Decimal A;
00216 Decimal B;
00217 Decimal C;
00218 Decimal f;
00219
00220 Decimal u;
00221 Decimal v;
00222 Decimal uDot;
00223 Decimal vDot;
00224 Decimal uInt;
00225 Decimal vInt;
00226
00227 Decimal thrustControl;
00228
00229 Decimal pan;
00230 Decimal tilt;
00231
00232 Decimal roll;
00233 Decimal pitch;
00234 Decimal yaw;
00235
00236
00237 Decimal rollTrim;
00238 Decimal pitchTrim;
00239 Decimal yawTrim;
00240
00241
00242 Pose3D tmpPose;
00243 Orientation3D tmpO;
00244 Position3D tmpP;
00245
00246 Decimal Omega[3];
00247 Decimal Jomega[6];
00248 Decimal pitchDes, rollDes;
00249 Decimal CommandAngle[2];
00250
00251 Decimal Z;
00252
00254 void _firstRun();
00255
00257 void _normalRun();
00258
00260 void _lastRun();
00261
00263 void ComputeControl();
00264 public:
00266 VisualHovering(ResourcePointers resources, int argc, const char* argv[]);
00267
00269 ~VisualHovering();
00270
00272 TaskPlate getPlate() const {
00273 return _plate;
00274 }
00275
00278 Time getMaxDuration(){
00279 return Time(_maxDurSec,_maxDurUsec);
00280 }
00282 Time getMaxSamplPeriod(){
00283 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00284 }
00286 Time getMinSamplPeriod(){
00287 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00288 }
00289
00291 TaskOutputs run();
00292 };
00293 };
00294
00295
00296
00297
00298
00299
00300 #endif
00301
00302
00303
00304
00305
00306
00307