region_worker.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "../tool/thread_condition.h"
  16. #include "../tool/common_data.h"
  17. /**
  18. * 区域功能类,负责自动检测区域状态并更新到plc
  19. * */
  20. class Region_worker
  21. {
  22. public:
  23. #define REGION_WORKER_RESULT_DEFAULT 0x0000
  24. //#define REGION_WORKER_VERIFY_OK 0x0001
  25. //#define REGION_WORKER_EMPTY_SPACE 0x0020
  26. //#define REGION_WORKER_CLUSTER_SIZE_ERROR 0x0040
  27. //#define REGION_WORKER_OTHER_ERROR 0x0080
  28. //#define REGION_WORKER_NULL_POINTER 0x0100
  29. #define REGION_WORKER_EMPTY_SPACE 1
  30. #define REGION_WORKER_HAS_CAR 2
  31. #define REGION_WORKER_DETECT_ERROR 3
  32. enum Region_worker_status
  33. {
  34. E_UNKNOW = 0, //未知
  35. E_READY = 1, //准备,待机
  36. E_BUSY = 2, //工作正忙
  37. E_FAULT = 10, //故障
  38. };
  39. public:
  40. Region_worker();
  41. ~Region_worker();
  42. Error_manager init(Point2D_tool::Point2D_box point2D_box, std::mutex* p_cloud_collection_mutex,
  43. pcl::PointCloud<pcl::PointXYZ>::Ptr p_cloud_collection);
  44. //唤醒自动预测的算法线程
  45. Error_manager wake_auto_detect();
  46. // 获得中心点、角度等测量数据
  47. Error_manager get_wheel_result(std::mutex* p_cloud_mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in,
  48. Common_data::Car_wheel_information& car_wheel_information);
  49. // 获得中心点、角度等测量数据, 新算法, 可以测量前轮旋转
  50. Error_manager get_wheel_result_ex(std::mutex* p_cloud_mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in,
  51. Common_data::Car_wheel_information& car_wheel_information);
  52. protected:
  53. static cv::RotatedRect create_rotate_rect(float length,float width,float angle,float x,float y);
  54. //自动预测的线程函数
  55. void auto_detect_thread_fun();
  56. protected:
  57. //状态
  58. Region_worker_status m_region_worker_status; //区域功能的状态
  59. Region_detector m_detector; // 区域检测算法实例
  60. //万集雷达的自动功能, 定时收集所有点云, 然后通知detect去计算车轮信息.
  61. std::mutex* mp_cloud_collection_mutex; // 点云更新互斥锁, 内存由上级管理
  62. pcl::PointCloud<pcl::PointXYZ>::Ptr mp_cloud_collection; //扫描点的点云集合, 内存由上级管理
  63. Common_data::Car_wheel_information m_car_wheel_information; //车轮的定位结果,
  64. std::chrono::system_clock::time_point m_detect_updata_time; //定位结果的更新时间.
  65. std::thread* mp_auto_detect_thread; //自动预测的线程指针,内存由本类管理
  66. Thread_condition m_auto_detect_condition; //自动预测的条件变量
  67. // pcl::PointCloud<pcl::PointXYZ>::Ptr m_cloud; // 自动区域检测用点云
  68. // std::atomic<bool> mb_cloud_updated; // 点云更新指标
  69. ////
  70. //// std::chrono::steady_clock::time_point m_update_plc_time; // 更新plc状态时刻
  71. //// int m_last_sent_code; // 上次写入plc的状态值
  72. //// int m_last_read_code; // 上次检查获得的状态值
  73. //// int m_last_border_status; // 上次超界提示
  74. //// std::atomic<int> m_read_code_count; // 检查后重复获取相同状态值次数
  75. //
  76. // Thread_condition m_cond_exit; // 系统退出标志
  77. // std::thread *m_detect_thread; // 实时检测线程
  78. // std::mutex m_mutex; // 点云互斥锁
  79. //
  80. // Verify_result* mp_verify_handle; // 边缘检测
  81. };
  82. #endif //REGION_WORKER_H