utility.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #ifndef _UTILITY_LIDAR_ODOMETRY_H_
  2. #define _UTILITY_LIDAR_ODOMETRY_H_
  3. //#include <ros/ros.h>
  4. //#include <sensor_msgs/Imu.h>
  5. //#include <sensor_msgs/PointCloud2.h>
  6. //#include <nav_msgs/Odometry.h>
  7. //#include "cloud_msgs/cloud_info.h"
  8. #include <opencv2/opencv.hpp>
  9. //#include <opencv/cv.h>
  10. #include <pcl/point_cloud.h>
  11. #include <pcl/point_types.h>
  12. //#include <pcl_ros/point_cloud.h>
  13. //#include <pcl_conversions/pcl_conversions.h>
  14. #include <pcl/range_image/range_image.h>
  15. #include <pcl/filters/filter.h>
  16. #include <pcl/filters/voxel_grid.h>
  17. #include <pcl/kdtree/kdtree_flann.h>
  18. #include <pcl/common/common.h>
  19. #include <pcl/registration/icp.h>
  20. //#include <tf/transform_broadcaster.h>
  21. //#include <tf/transform_datatypes.h>
  22. #include <vector>
  23. #include <cmath>
  24. #include <algorithm>
  25. #include <queue>
  26. #include <deque>
  27. #include <iostream>
  28. #include <fstream>
  29. #include <ctime>
  30. #include <cfloat>
  31. #include <iterator>
  32. #include <sstream>
  33. #include <string>
  34. #include <limits>
  35. #include <iomanip>
  36. #include <array>
  37. #include <thread>
  38. #include <mutex>
  39. #define PI 3.14159265
  40. using namespace std;
  41. typedef pcl::PointXYZI PointType;
  42. extern const string pointCloudTopic = "/velodyne_points";
  43. extern const string imuTopic = "/imu/data";
  44. // Save pcd
  45. extern const string fileDirectory = "/tmp/";
  46. // Using velodyne cloud "ring" channel for image projection (other lidar may have different name for this channel, change "PointXYZIR" below)
  47. extern const bool useCloudRing = true; // if true, ang_res_y and ang_bottom are not used
  48. // VLP-16
  49. extern const int N_SCAN = 16;
  50. extern const int Horizon_SCAN = 1800;
  51. extern const float ang_res_x = 0.2;
  52. extern const float ang_res_y = 2.0;
  53. extern const float ang_bottom = 15.0+0.1;
  54. extern const int groundScanInd = 7;
  55. // HDL-32E
  56. // extern const int N_SCAN = 32;
  57. // extern const int Horizon_SCAN = 1800;
  58. // extern const float ang_res_x = 360.0/float(Horizon_SCAN);
  59. // extern const float ang_res_y = 41.33/float(N_SCAN-1);
  60. // extern const float ang_bottom = 30.67;
  61. // extern const int groundScanInd = 20;
  62. // VLS-128
  63. // extern const int N_SCAN = 128;
  64. // extern const int Horizon_SCAN = 1800;
  65. // extern const float ang_res_x = 0.2;
  66. // extern const float ang_res_y = 0.3;
  67. // extern const float ang_bottom = 25.0;
  68. // extern const int groundScanInd = 10;
  69. // Ouster users may need to uncomment line 159 in imageProjection.cpp
  70. // Usage of Ouster imu data is not fully supported yet (LeGO-LOAM needs 9-DOF IMU), please just publish point cloud data
  71. // Ouster OS1-16
  72. // extern const int N_SCAN = 16;
  73. // extern const int Horizon_SCAN = 1024;
  74. // extern const float ang_res_x = 360.0/float(Horizon_SCAN);
  75. // extern const float ang_res_y = 33.2/float(N_SCAN-1);
  76. // extern const float ang_bottom = 16.6+0.1;
  77. // extern const int groundScanInd = 7;
  78. // Ouster OS1-64
  79. // extern const int N_SCAN = 64;
  80. // extern const int Horizon_SCAN = 1024;
  81. // extern const float ang_res_x = 360.0/float(Horizon_SCAN);
  82. // extern const float ang_res_y = 33.2/float(N_SCAN-1);
  83. // extern const float ang_bottom = 16.6+0.1;
  84. // extern const int groundScanInd = 15;
  85. extern const bool loopClosureEnableFlag = false;
  86. extern const double mappingProcessInterval = 0.3;
  87. extern const float scanPeriod = 0.1;
  88. extern const int systemDelay = 0;
  89. extern const int imuQueLength = 200;
  90. extern const float sensorMinimumRange = 1.0;
  91. extern const float sensorMountAngle = 0.0;
  92. extern const float segmentTheta = 60.0/180.0*M_PI; // decrese this value may improve accuracy
  93. extern const int segmentValidPointNum = 5;
  94. extern const int segmentValidLineNum = 3;
  95. extern const float segmentAlphaX = ang_res_x / 180.0 * M_PI;
  96. extern const float segmentAlphaY = ang_res_y / 180.0 * M_PI;
  97. extern const int edgeFeatureNum = 2;
  98. extern const int surfFeatureNum = 4;
  99. extern const int sectionsTotal = 6;
  100. extern const float edgeThreshold = 0.1;
  101. extern const float surfThreshold = 0.1;
  102. extern const float nearestFeatureSearchSqDist = 25;
  103. // Mapping Params
  104. extern const float surroundingKeyframeSearchRadius = 50.0; // key frame that is within n meters from current pose will be considerd for scan-to-map optimization (when loop closure disabled)
  105. extern const int surroundingKeyframeSearchNum = 50; // submap size (when loop closure enabled)
  106. // history key frames (history submap for loop closure)
  107. extern const float historyKeyframeSearchRadius = 7.0; // key frame that is within n meters from current pose will be considerd for loop closure
  108. extern const int historyKeyframeSearchNum = 25; // 2n+1 number of hostory key frames will be fused into a submap for loop closure
  109. extern const float historyKeyframeFitnessScore = 0.3; // the smaller the better alignment
  110. extern const float globalMapVisualizationSearchRadius = 500.0; // key frames with in n meters will be visualized
  111. struct smoothness_t{
  112. float value;
  113. size_t ind;
  114. };
  115. struct by_value{
  116. bool operator()(smoothness_t const &left, smoothness_t const &right) {
  117. return left.value < right.value;
  118. }
  119. };
  120. /*
  121. * A point cloud type that has "ring" channel
  122. */
  123. struct PointXYZIR
  124. {
  125. PCL_ADD_POINT4D
  126. PCL_ADD_INTENSITY;
  127. uint16_t ring;
  128. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  129. } EIGEN_ALIGN16;
  130. POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZIR,
  131. (float, x, x) (float, y, y)
  132. (float, z, z) (float, intensity, intensity)
  133. (uint16_t, ring, ring)
  134. )
  135. /*
  136. * A point cloud type that has 6D pose info ([x,y,z,roll,pitch,yaw] intensity is time stamp)
  137. */
  138. struct PointXYZIRPYT
  139. {
  140. PCL_ADD_POINT4D
  141. PCL_ADD_INTENSITY;
  142. float roll;
  143. float pitch;
  144. float yaw;
  145. double time;
  146. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  147. } EIGEN_ALIGN16;
  148. POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZIRPYT,
  149. (float, x, x) (float, y, y)
  150. (float, z, z) (float, intensity, intensity)
  151. (float, roll, roll) (float, pitch, pitch) (float, yaw, yaw)
  152. (double, time, time)
  153. )
  154. typedef PointXYZIRPYT PointTypePose;
  155. #endif