region_worker.h 2.8 KB

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