videoslam.hpp
Go to the documentation of this file.
00001 
00005 #ifndef _THERMALVIS_VIDEOSLAM_H_
00006 #define _THERMALVIS_VIDEOSLAM_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 <cv_bridge/CvBridge.h>
00014 
00015 #include "improc.hpp"
00016 #include "video.hpp"
00017 #include "features.hpp"
00018 #include "reconstruction.hpp"
00019 #include "sba.hpp"
00020 #include "keyframes.hpp"
00021 #include "geometry.hpp"
00022 
00023 #include "feature_tracks.h"
00024 #include "pose_confidence.h"
00025 
00026 #include "videoslamConfig.h"
00027 
00028 #include <std_msgs/Float32.h>
00029 
00030 typedef Eigen::Quaternion<double>   QuaternionDbl;
00031 typedef dynamic_reconfigure::Server < thermalvis::videoslamConfig > Server;
00032 
00033 // Drawing
00034 #define DEFAULT_DRAWGRAPH_DECIMATION                    1
00035 #define DEFAULT_DRAWGRAPH_BICOLOR                               0
00036 
00037 // Hard Limits
00038 #define MAX_HISTORY                                                             10
00039 #define MAX_POSES_TO_STORE                                              100
00040 #define MAX_FRAMES                                                              1000
00041 #define MAX_TRACKS                                                              10000
00042 #define SBA_MEMORY                                                              134217728
00043 #define MAX_TIME_GAP_FOR_INTERP                                 0.5
00044 
00045 typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
00046 
00047 const char __PROGRAM__[] = "THERMALVIS_ODOMETRY";
00048 
00049 bool wantsToShutdown = false;
00050 void mySigintHandler(int sig);
00051 bool interpolatePose(const geometry_msgs::Pose& pose1, ros::Time time1, const geometry_msgs::Pose& pose2, ros::Time time2, geometry_msgs::Pose& finalPose, ros::Time time3);
00052 void shiftPose(const geometry_msgs::Pose& pose_src, geometry_msgs::Pose& pose_dst, cv::Mat transformation);
00053 
00055 struct videoslamData {
00056         
00057         string read_addr;
00058         string flowSource, mapperSource;
00059         
00060         bool writePoses;
00061         
00062         int baMode;
00063         
00064         //bool evaluationMode;
00065         
00066         double baStep;
00067         
00068         double terminationTime, restartTime;
00069         
00070         double maxPoseDelay;
00071         
00072         bool clearTriangulations;
00073         
00074         cameraParameters cameraData;
00075         string extrinsicsFile;
00076         double cameraLatency;
00077         
00078         int evaluateParameters;
00079         
00080         double maxAllowableError;
00081         
00082         int pnpIterations;
00083         double inliersPercentage;
00084         
00085         bool trimFeatureTracks;
00086         int pairsForTriangulation, adjustmentFrames, adjustmentIterations;
00087         double maxReprojectionDisparity, maxDistance, minSeparation, maxSeparation, maxStandardDev;
00088         
00089         bool debugSBA, debugTriangulation, debugMode, verboseMode, publishPoints, publishKeyframes;
00090         
00091         double dataTimeout;
00092         
00093         bool obtainStartingData(ros::NodeHandle& nh);
00094         
00095 };
00096 
00098 class videoslamNode {
00099 private:
00100 
00101         videoslamData configData;
00102         
00103         int decimation, bicolor;
00104         
00105         std::ofstream lStream;
00106         std::streambuf* lBufferOld;
00107         
00108         cv::Mat extrinsicCalib_T, extrinsicCalib_R, extrinsicCalib_P;
00109         //QuaternionDbl extrinsicCalib_quat;
00110         
00111         unsigned int frameProcessedCounter;
00112         
00113         bool hasTerminatedFeed;
00114         
00115         cv::Mat blank, eye4;
00116         
00117         double distanceTravelled;
00118         
00119         int framesArrived, framesProcessed, pnpSuccesses, baSuccesses;
00120         double baAverage, dsAverage;
00121         
00122         ros::Subscriber tracks_sub;
00123         ros::Subscriber info_sub;
00124         ros::Subscriber pose_sub;
00125         
00126         SysSBA sys;
00127         
00128         //std_msgs::Float32 confidence_msg;
00129         
00130         
00131         ros::Publisher path_pub, camera_pub, points_pub, confidence_pub;
00132         
00133         pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr_;
00134         
00135         unsigned int frameHeaderHistoryCounter, poseHistoryCounter;
00136         std_msgs::Header frameHeaderHistoryBuffer[MAX_HISTORY];
00137         geometry_msgs::PoseStamped poseHistoryBuffer[MAX_HISTORY];
00138         
00139         geometry_msgs::PoseStamped keyframePoses[MAX_POSES_TO_STORE];
00140         bool keyframeTypes[MAX_POSES_TO_STORE];
00141         unsigned int storedPosesCount;
00142         
00143         ros::Timer timer;
00144         
00145         double latestTracksTime, pointShift, pnpError, pnpInlierProp;
00146         
00147         int lastTestedFrame, usedTriangulations;
00148         
00149         bool infoProcessed;
00150         
00151         vector<featureTrack> featureTrackVector;
00152         
00153         keyframeStore keyframe_store;
00154         cv::Mat F_arr[MAX_FRAMES], H_arr[MAX_FRAMES];
00155         
00156         cv::Mat ACM[MAX_FRAMES];
00157         
00158         double predictiveError, bundleTransShift, bundleRotShift;
00159         
00160         char nodeName[256];
00161         
00162         ros::Publisher pose_pub;
00163         char pose_pub_name[256];
00164         
00165         /*
00166         ros::Publisher points_pub;
00167         char points_pub_name[256];
00168         */
00169         sensor_msgs::PointCloud2 pointCloud_message;
00170         
00171         
00172         geometry_msgs::PoseStamped savedPose, currentPose, pnpPose;
00173         
00174         int currentPoseIndex;
00175         
00176         bool latestReceivedPoseProcessed;
00177         
00178         vector<unsigned int> framesReceived;
00179         
00180         // Thread-protection
00181         boost::mutex main_mutex;
00182         
00183         dynamic_reconfigure::Server<thermalvis::videoslamConfig> server;
00184         dynamic_reconfigure::Server<thermalvis::videoslamConfig>::CallbackType f;
00185         
00186 public:
00187 
00188         videoslamNode(ros::NodeHandle& nh, videoslamData startupData);
00189         
00190         // Callbacks
00191         void handle_tracks(const thermalvis::feature_tracksConstPtr& msg);
00192         void handle_info(const sensor_msgs::CameraInfoConstPtr& info_msg);
00193         void handle_pose(const geometry_msgs::PoseStamped& pose_msg);
00194         void main_loop(const ros::TimerEvent& event);
00195         
00196         bool updateLocalPoseEstimates();
00197         
00198         //void publishPoints(const geometry_msgs::PoseStamped& pose_msg);
00199         void publishPoints(ros::Time stamp, unsigned int seq);
00200         bool determinePose();
00201         
00202         void publishPose();
00203         
00204         bool findNearestPoses(int& index1, int& index2, const ros::Time& targetTime);
00205         
00206         void prepareForTermination();
00207         
00208         void triangulatePoints();
00209         
00210         void integrateNewTrackMessage(const thermalvis::feature_tracksConstPtr& msg);
00211         
00212         bool checkConnectivity(unsigned int seq);
00213         
00214         bool updateKeyframePoses(const geometry_msgs::PoseStamped& pose_msg, bool fromICP = true);
00215         
00216         void trimFeatureTrackVector();
00217         
00218         void serverCallback(thermalvis::videoslamConfig &config, uint32_t level);
00219         
00220 };
00221 
00222 // dummy callbacks // http://answers.ros.org/question/55126/why-does-ros-overwrite-my-sequence-number/
00223 void connected(const ros::SingleSubscriberPublisher&) {}
00224 void disconnected(const ros::SingleSubscriberPublisher&) {}
00225 
00226 boost::shared_ptr < videoslamNode > *globalNodePtr;
00227 
00228 #endif


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