PTAMWrapper.h
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 // this is a wrapper around PTAM, doing the scale estimation etc.
00049 // it runs in its own thread, and has its own window (Camera Image + PTAM points etc.)
00050 // the thread re-renders old images, or (via callback) performs ROS-message handeling (i.e. tracking).
00051 // it then updates the DroneKalmanFilter.
00052 
00053 class PTAMWrapper : private CVD::Thread, private MouseKeyHandler
00054 {
00055 private:
00056         // base window
00057         GLWindow2* myGLWindow;
00058         CVD::ImageRef desiredWindowSize;                // size the window scould get changed to if [changeSizeNextRender]
00059         CVD::ImageRef defaultWindowSize;                // size the window gets opened with
00060         bool changeSizeNextRender;
00061 
00062 
00063         // the associated thread's run function.
00064         // calls HandleFrame() every time a new frame is available.
00065         void run();
00066 
00067         void HandleFrame();
00068 
00069         // references to filter.
00070         DroneKalmanFilter* filter;
00071         EstimationNode* node;
00072 
00073         // -------------------- PTAM related stuff --------------------------------
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         // Map is in my global Coordinate system. keyframes give the front-cam-position, i.e.
00089         // CFromW is "GlobalToFront". this is achieved by aligning the global coordinate systems in the very beginning.
00090         Map *mpMap; 
00091         MapMaker *mpMapMaker; 
00092         Tracker *mpTracker; 
00093         ATANCamera *mpCamera;
00094         Predictor* predConvert;                 // used ONLY to convert from rpy to se3 and back, i.e. never kept in some state.
00095         Predictor* predIMUOnlyForScale; // used for scale calculation. needs to be updated with every new navinfo...
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         //int lastGoodPTAM;     /// approx. timestamp of last good ptam observation... inaccurate!
00117         int lastGoodYawClock;
00118         int isGoodCount;        // number of succ. tracked frames in a row.
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         // keep Running
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         // resets PTAM tracking
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; //pthread_mutex_lock( &cs_mutex );
00146 
00147 public:
00148 
00149         PTAMWrapper(DroneKalmanFilter* dkf, EstimationNode* nde);
00150         ~PTAMWrapper(void);
00151 
00152         // ROS exclusive: called by external thread if a new image/navdata is received.
00153         // takes care of sync etc.
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; //pthread_mutex_lock( &cs_mutex );
00163         static pthread_mutex_t shallowMapCS; //pthread_mutex_lock( &cs_mutex );
00164 
00165         // Event handling routines.
00166         // get called by the myGLWindow on respective event.
00167         virtual void on_key_down(int key);
00168         //virtual void on_mouse_move(CVD::ImageRef where, int state);
00169         virtual void on_mouse_down(CVD::ImageRef where, int state, int button);
00170         //virtual void on_event(int event);
00171         
00172         // resets PTAM tracking
00173         inline void Reset() {resetPTAMRequested = true;};
00174 
00175 
00176         // start and stop system and respective thread.
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         // for map rendering: shallow clone
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 /* __PTAMWRAPPER_H */


tum_ardrone
Author(s):
autogenerated on Sat Jun 8 2019 20:27:23