clamp_safety_detect.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // Created by zx on 22-8-30.
  3. //
  4. #ifndef SHUTTER_VERIFY_DETECT_CLAMP_SAFETY_DETECT_H_
  5. #define SHUTTER_VERIFY_DETECT_CLAMP_SAFETY_DETECT_H_
  6. #define PCL_NO_PRECOMPILE
  7. #include <pcl/point_types.h>
  8. #include <pcl/point_cloud.h>
  9. #include <pcl/io/pcd_io.h>
  10. #include <pcl/segmentation/sac_segmentation.h>
  11. #include <pcl/ModelCoefficients.h>
  12. #include <pcl/filters/extract_indices.h>
  13. #include <pcl/segmentation/extract_clusters.h>
  14. #include <pcl/point_representation.h>
  15. #if __VIEW__PCL
  16. #include <pcl/visualization/pcl_visualizer.h>
  17. #endif
  18. class Safety_status
  19. {
  20. public:
  21. Safety_status(){
  22. clamp_completed=false;
  23. wheel_exist=false;
  24. cx=0;
  25. gap=0;
  26. time_point=std::chrono::steady_clock::now();
  27. timeout_s=0.5;
  28. };
  29. ~Safety_status(){}
  30. Safety_status(const Safety_status& other)
  31. {
  32. clamp_completed=other.clamp_completed;
  33. wheel_exist=other.wheel_exist;
  34. cx=other.cx;
  35. gap=other.gap;
  36. time_point=other.time_point;
  37. timeout_s=other.timeout_s;
  38. }
  39. Safety_status& operator=(const Safety_status& other)
  40. {
  41. clamp_completed=other.clamp_completed;
  42. wheel_exist=other.wheel_exist;
  43. cx=other.cx;
  44. gap=other.gap;
  45. time_point=other.time_point;
  46. timeout_s=other.timeout_s;
  47. return *this;
  48. }
  49. void set_timeout(float s){
  50. timeout_s=s;
  51. }
  52. bool is_timeout(){
  53. auto t2 = std::chrono::steady_clock::now();
  54. auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - time_point);
  55. double time = double(duration.count()) * std::chrono::microseconds::period::num /
  56. std::chrono::microseconds::period::den;
  57. return time>timeout_s;
  58. }
  59. bool clamp_completed;
  60. bool wheel_exist; //点云直线是否是轮子
  61. float cx;
  62. float gap; //轮子距离雷达
  63. std::chrono::steady_clock::time_point time_point;
  64. float timeout_s;
  65. std::mutex mutex_;
  66. };
  67. //ax+by+c=0
  68. typedef struct {
  69. float a;
  70. float b;
  71. float c;
  72. float cx;
  73. float cy;
  74. float theta_by_x;
  75. float cov;
  76. pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;
  77. }Line;
  78. class clamp_safety_detect
  79. {
  80. public:
  81. clamp_safety_detect();
  82. ~clamp_safety_detect();
  83. #if __VIEW__PCL
  84. void set_viewer(pcl::visualization::PCLVisualizer* m_viewer,int port);
  85. #endif
  86. bool detect(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,Safety_status& safety);
  87. bool fit_line(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,Line& line);
  88. bool check_wheel_line(const Line& line,Safety_status& safety);
  89. protected:
  90. std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> classify_cloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud);
  91. // bool check_wheel_line(const Line& line,Safety_status& safety);
  92. bool check_clamp_lines(const Line& line1,const Line& line2,Safety_status& safety);
  93. #if __VIEW__PCL
  94. void view_cloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,std::string name,int r,int g,int b);
  95. pcl::visualization::PCLVisualizer* m_viewer;
  96. int m_port;
  97. #endif
  98. };
  99. #endif //SHUTTER_VERIFY_DETECT_CLAMP_SAFETY_DETECT_H_