region_worker.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // Created by zx on 2019/12/9.
  3. //
  4. #ifndef REGION_WORKER_H
  5. #define REGION_WORKER_H
  6. #include "region_detect.h"
  7. #include "../tool/StdCondition.h"
  8. #include <thread>
  9. #include <mutex>
  10. #include <iostream>
  11. #include <atomic>
  12. #include <chrono>
  13. #include "../error_code/error_code.h"
  14. #include "../verify/Verify_result.h"
  15. /**
  16. * 区域功能类,负责自动检测区域状态并更新到plc
  17. * */
  18. class Region_worker
  19. {
  20. public:
  21. #define REGION_WORKER_RESULT_DEFAULT 0x0000
  22. //#define REGION_WORKER_VERIFY_OK 0x0001
  23. //#define REGION_WORKER_EMPTY_SPACE 0x0020
  24. //#define REGION_WORKER_CLUSTER_SIZE_ERROR 0x0040
  25. //#define REGION_WORKER_OTHER_ERROR 0x0080
  26. //#define REGION_WORKER_NULL_POINTER 0x0100
  27. #define REGION_WORKER_EMPTY_SPACE 1
  28. #define REGION_WORKER_HAS_CAR 2
  29. #define REGION_WORKER_DETECT_ERROR 3
  30. public:
  31. // 有参构造
  32. Region_worker(int id, wj::Region region, Verify_result* verify_handle);
  33. // 析构函数
  34. ~Region_worker();
  35. // 外部调用传入新点云
  36. void update_cloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in);
  37. // 实时检测线程函数
  38. static void detect_loop(Region_worker *worker);
  39. // 获取区域id
  40. int get_id();
  41. // 获得中心点、角度等测量数据
  42. Error_manager get_wheel_result(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud_in, double &x, double &y, double &c, double &wheelbase, double &width);
  43. // 获得中心点、角度等测量数据,前轮旋转
  44. Error_manager get_wheel_result(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud_in, double &x, double &y, double &c,
  45. double &wheelbase, double &width,double& front_theta);
  46. private:
  47. static cv::RotatedRect create_rotate_rect(float length,float width,float angle,float x,float y);
  48. private:
  49. Region_detector *m_detector; // 区域检测算法实例
  50. pcl::PointCloud<pcl::PointXYZ>::Ptr m_cloud; // 自动区域检测用点云
  51. std::atomic<bool> mb_cloud_updated; // 点云更新指标
  52. std::chrono::steady_clock::time_point m_update_plc_time; // 更新plc状态时刻
  53. int m_last_sent_code; // 上次写入plc的状态值
  54. int m_last_read_code; // 上次检查获得的状态值
  55. int m_last_border_status; // 上次超界提示
  56. std::atomic<int> m_read_code_count; // 检查后重复获取相同状态值次数
  57. StdCondition m_cond_exit; // 系统退出标志
  58. std::thread *m_detect_thread; // 实时检测线程
  59. std::mutex m_mutex; // 点云互斥锁
  60. Verify_result* mp_verify_handle; // 边缘检测
  61. };
  62. #endif //REGION_WORKER_H