monoslam.hpp
Go to the documentation of this file.
00001 
00005 #ifndef _THERMALVIS_MONOSLAM_H_
00006 #define _THERMALVIS_MONOSLAM_H_
00007         
00008 #include "general_resources.hpp"
00009 #include "ros_resources.hpp"
00010 #include "opencv_resources.hpp"
00011 #include "pcl_resources.hpp"
00012 
00013 #include "improc.hpp"
00014 #include "video.hpp"
00015 #include "features.hpp"
00016 #include "reconstruction.hpp"
00017 #include "sba.hpp"
00018 #include "keyframes.hpp"
00019 #include "geometry.hpp"
00020 
00021 #include "feature_tracks.h"
00022 
00023 #include "monoslamConfig.h"
00024 
00025 typedef dynamic_reconfigure::Server < thermalvis::monoslamConfig > Server;
00026 
00027 // Drawing
00028 #define DEFAULT_DRAWGRAPH_DECIMATION                    1
00029 #define DEFAULT_DRAWGRAPH_BICOLOR                               0
00030 
00031 // Hard Limits
00032 #define MAX_FRAMES                                                              1000
00033 #define MAX_TRACKS                                                              10000
00034 #define SBA_MEMORY                                                              134217728
00035 #define MAX_SEGMENTS                                                    16
00036 #define INITIALIZATION_SCORING_PARAMETERS               5
00037 
00038 typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
00039 
00040 const char __PROGRAM__[] = "THERMALVIS_MONOSLAM";
00041 
00042 bool wantsToShutdown = false;
00043 void mySigintHandler(int sig);
00044 
00046 struct slamData {
00047         
00048         string stream;
00049         
00050         double motionThreshold;
00051         int adjustmentFrames;
00052         int flowback;
00053         double minStartupScore;
00054         cameraParameters cameraData;
00055         bool verboseMode;
00056         bool obtainStartingData(ros::NodeHandle& nh);
00057         
00058         double dataTimeout;
00059         
00060         int keyframeSpacing;
00061         
00062         int maxGuides;
00063         int maxKeyframeSeparation;
00064         
00065         int framesForTriangulation;
00066         
00067         int timeSpacing;
00068         
00069         int minTrackedFeatures;
00070         
00071         int min3dPtsForPnP;
00072         
00073         int maxInitializationFrames;
00074 
00075         
00076         double minGeometryScore;
00077         double minKeyframeScore;
00078         
00079         double requiredTrackFrac;
00080         
00081         int camerasPerSys;
00082         
00083         bool timeDebug;
00084         
00085         bool logErrors;
00086         
00087         int maxTestsPerFrame;
00088         
00089         int initialStructureIterations, poseEstimateIterations, fullSystemIterations, subsequenceIterations, keyframeIterations;
00090         
00091         bool keyframeEvaluationMode; 
00092         
00093         int minStartingSeparation, maxStartingSeparation;
00094         
00095         string read_addr, evaluationFile, errorFile, initializationScorecard;
00096         
00097 };
00098 
00100 struct timeAnalyzer {
00101         
00102         int cycles;
00103         double vals[1024];
00104         double average;
00105         double sigma;
00106         
00107         struct timeval cycle_timer;
00108         
00109         timeAnalyzer();
00110         void calcParameters();
00111         void startRecording();
00112         void stopRecording();
00113         
00114 };
00115 
00117 class slamNode {
00118 private:
00119 
00120         int decimation;
00121         int bicolor;
00122 
00123         bool isTracking;
00124         
00125         bool f1;
00126         
00127         bool evaluationCompleted;
00128 
00129         unsigned int baseConnectionNum;
00130         
00131         double **scorecardParams;
00132 
00133         slamData configData;
00134         
00135         ofstream evaluationStream;
00136         
00137         unsigned int nextFrame;
00138         
00139         unsigned int putativelyEstimatedFrames;
00140         
00141         cv::Mat eye4;
00142         
00143         bool repetitionNoted;
00144         
00145         ofstream error_file;
00146         char error_filename[256];
00147 
00148         ros::Subscriber tracks_sub;
00149         ros::Subscriber info_sub;
00150         
00151         SysSBA sys, display_sys;
00152         ros::Publisher path_pub;
00153         ros::Publisher camera_pub;
00154         ros::Publisher points_pub;
00155         
00156         ros::Timer timer;
00157         
00158         bool firstIteration;
00159         
00160         cv::Mat blank;
00161         
00162         bool structureValid, structureFormed;
00163         
00164         int latestFrame;
00165         
00166         bool infoProcessed;
00167         
00168         struct timeval cycle_timer;
00169         double elapsedTime;
00170         
00171         double distanceConstraint;
00172         
00173         vector<featureTrack> featureTrackVector;
00174         
00175         cv::Point3d cloudCentroid[MAX_SEGMENTS], cloudStdDeviation[MAX_SEGMENTS];
00176         keyframeStore keyframe_store;
00177         cv::Mat F_arr[MAX_FRAMES], H_arr[MAX_FRAMES];
00178         
00179         cv::Mat ACM[MAX_FRAMES], ACM2[MAX_FRAMES];
00180         
00181         cv::Mat keyframeTestScores, keyframeTestFlags;
00182         
00183         char nodeName[256];
00184         
00185         ros::Publisher pose_pub;
00186         char pose_pub_name[256];
00187         
00188         geometry_msgs::PoseStamped currentPose;
00189         
00190         int currentPoseIndex;
00191         
00192         double minimumKeyframeScore;
00193         
00194         vector<unsigned int> framesReceived;
00195         
00196         unsigned int lastBasePose;
00197         
00198         unsigned int startingTracksCount;
00199         
00200         timeAnalyzer trackHandlingTime;
00201         timeAnalyzer triangulationTime;
00202         timeAnalyzer poseEstimationTime;
00203         timeAnalyzer bundleAdjustmentTime;
00204 
00205         // Thread-protection
00206         boost::mutex cam_mutex;
00207         boost::mutex tracks_mutex;
00208         boost::mutex keyframes_mutex;
00209         boost::mutex main_mutex;
00210         
00211         dynamic_reconfigure::Server<thermalvis::monoslamConfig> server;
00212         dynamic_reconfigure::Server<thermalvis::monoslamConfig>::CallbackType f;
00213         
00214 public:
00215 
00216         slamNode(ros::NodeHandle& nh, slamData startupData);
00217         void assignPose(geometry_msgs::PoseStamped& pPose, cv::Mat& C);
00218         
00219         void estimatePose(vector<unsigned int>& basisNodes, unsigned int idx);
00220         
00221         void getBasisNodes(vector<unsigned int>& basisNodes, unsigned int idx);
00222         
00223         // Callbacks
00224         void handle_tracks(const thermalvis::feature_tracksConstPtr& msg);
00225         void handle_info(const sensor_msgs::CameraInfoConstPtr& info_msg);
00226         void main_loop(const ros::TimerEvent& event);
00227         
00228         // Routines
00229         bool formInitialStructure();
00230         bool findStartingFrames();
00231         void refreshPoses();
00232         bool checkForKeyframe();
00233         void processNextFrame();
00234         void update_display();
00235         void show_poses();
00236         void update_cameras_to_pnp();
00237         double assignStartingFrames(unsigned int best_iii, unsigned int best_jjj, double* keyframe_scores, cv::Mat& startingTrans);
00238         
00239         void getGuidingPose(cv::Mat *srcs, cv::Mat& dst, unsigned int idx);
00240         
00241         void clearSystem();
00242         
00243         void processScorecard();
00244         
00245         void serverCallback(thermalvis::monoslamConfig &config, uint32_t level);
00246         
00247         // Misc
00248         bool stillTracking() {
00249                 return isTracking;
00250         }
00251         
00252         void prepareForTermination();
00253         
00254 };
00255 
00256 boost::shared_ptr < slamNode > *globalNodePtr;
00257 
00258 #endif


thermalvis
Author(s): Stephen Vidas
autogenerated on Sun Jan 5 2014 11:38:45