Go to the documentation of this file.00001 #pragma once
00002
00021 #ifndef __PTAMWRAPPER_H
00022 #define __PTAMWRAPPER_H
00023
00024 #include "GLWindow2.h"
00025 #include "TooN/se3.h"
00026 #include <deque>
00027 #include "sensor_msgs/Image.h"
00028 #include "ardrone_autonomy/Navdata.h"
00029 #include "cvd/thread.h"
00030 #include "cvd/image.h"
00031 #include "cvd/byte.h"
00032 #include "MouseKeyHandler.h"
00033 #include "boost/thread.hpp"
00034
00035 class Map;
00036 class MapMaker;
00037 class Tracker;
00038 class ATANCamera;
00039 class Predictor;
00040 class DroneKalmanFilter;
00041 class DroneFlightModule;
00042 class EstimationNode;
00043
00044
00045 typedef TooN::Vector<3> tvec3;
00046 typedef TooN::SE3<> tse3;
00047
00048
00049
00050
00051
00052
00053 class PTAMWrapper : private CVD::Thread, private MouseKeyHandler
00054 {
00055 private:
00056
00057 GLWindow2* myGLWindow;
00058 CVD::ImageRef desiredWindowSize;
00059 CVD::ImageRef defaultWindowSize;
00060 bool changeSizeNextRender;
00061
00062
00063
00064
00065 void run();
00066
00067 void HandleFrame();
00068
00069
00070 DroneKalmanFilter* filter;
00071 EstimationNode* node;
00072
00073
00074 char charBuf[1000];
00075 std::string msg;
00076
00077 CVD::Image<CVD::byte> mimFrameBW;
00078 CVD::Image<CVD::byte> mimFrameBW_workingCopy;
00079 int mimFrameTime;
00080 int mimFrameTime_workingCopy;
00081 unsigned int mimFrameSEQ;
00082 unsigned int mimFrameSEQ_workingCopy;
00083 ros::Time mimFrameTimeRos;
00084 ros::Time mimFrameTimeRos_workingCopy;
00085 int frameWidth, frameHeight;
00086
00087
00088
00089
00090 Map *mpMap;
00091 MapMaker *mpMapMaker;
00092 Tracker *mpTracker;
00093 ATANCamera *mpCamera;
00094 Predictor* predConvert;
00095 Predictor* predIMUOnlyForScale;
00096
00097 double minKFTimeDist;
00098 double minKFWiggleDist;
00099 double minKFDist;
00100
00101
00102 Predictor* imuOnlyPred;
00103 int lastScaleEKFtimestamp;
00104
00105 bool resetPTAMRequested;
00106 enum {UI_NONE = 0, UI_DEBUG = 1, UI_PRES = 2} drawUI;
00107
00108
00109 bool forceKF;
00110
00111 bool flushMapKeypoints;
00112
00113 int lastAnimSentClock;
00114 enum {ANIM_NONE, ANIM_TOOKKF, ANIM_GOOD, ANIM_INIT, ANIM_LOST, ANIM_FALSEPOS} lastAnimSent;
00115
00116
00117 int lastGoodYawClock;
00118 int isGoodCount;
00119
00120 TooN::Vector<3> PTAMPositionForScale;
00121 int ptamPositionForScaleTakenTimestamp;
00122 int framesIncludedForScaleXYZ;
00123 std::deque<ardrone_autonomy::Navdata> navInfoQueue;
00124 bool navQueueOverflown;
00125 TooN::Vector<3> evalNavQue(unsigned int from, unsigned int to, bool* zCorrupted, bool* allCorrupted, float* out_start_pressure, float* out_end_pressure);
00126
00127
00128
00129 bool keepRunning;
00130
00131 bool lockNextFrame;
00132
00133 boost::condition_variable new_frame_signal;
00134 boost::mutex new_frame_signal_mutex;
00135
00136
00137
00138 void ResetInternal();
00139
00140 void renderGrid(TooN::SE3<> camFromWorld);
00141
00142 int videoFramePing;
00143
00144 std::ofstream* logfileScalePairs;
00145 static pthread_mutex_t logScalePairs_CS;
00146
00147 public:
00148
00149 PTAMWrapper(DroneKalmanFilter* dkf, EstimationNode* nde);
00150 ~PTAMWrapper(void);
00151
00152
00153
00154 void newImage(sensor_msgs::ImageConstPtr img);
00155 void newNavdata(ardrone_autonomy::Navdata* nav);
00156 bool newImageAvailable;
00157 void setPTAMPars(double minKFTimeDist, double minKFWiggleDist, double minKFDist);
00158
00159 bool handleCommand(std::string s);
00160 bool mapLocked;
00161 int maxKF;
00162 static pthread_mutex_t navInfoQueueCS;
00163 static pthread_mutex_t shallowMapCS;
00164
00165
00166
00167 virtual void on_key_down(int key);
00168
00169 virtual void on_mouse_down(CVD::ImageRef where, int state, int button);
00170
00171
00172
00173 inline void Reset() {resetPTAMRequested = true;};
00174
00175
00176
00177 void startSystem();
00178 void stopSystem();
00179
00180
00181
00182 enum {PTAM_IDLE = 0, PTAM_INITIALIZING = 1, PTAM_LOST = 2, PTAM_GOOD = 3, PTAM_BEST = 4, PTAM_TOOKKF = 5, PTAM_FALSEPOSITIVE = 6} PTAMStatus;
00183 TooN::SE3<> lastPTAMResultRaw;
00184 std::string lastPTAMMessage;
00185
00186
00187 std::vector<tvec3> mapPointsTransformed;
00188 std::vector<tse3> keyFramesTransformed;
00189
00190 ardrone_autonomy::Navdata lastNavinfoReceived;
00191
00192 int PTAMInitializedClock;
00193
00194 };
00195
00196 #endif