LivoxLaser.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef __LIVOX_MID_40_LIDAR__H
  2. #define __LIVOX_MID_40_LIDAR__H
  3. #include "Laser.h"
  4. #include "livox_def.h"
  5. #include "livox_sdk.h"
  6. #include <map>
  7. //大疆livox雷达,从Laser_base继承。
  8. class CLivoxLaser :public Laser_base
  9. {
  10. protected:
  11. //雷达设备状态,livox管理底层sdk,后台线程的工作状态
  12. typedef enum
  13. {
  14. kDeviceStateDisconnect = 0, //雷达设备状态 断开连接
  15. kDeviceStateConnect = 1, //雷达设备状态 连接正常
  16. kDeviceStateSampling = 2, //雷达设备状态 正在扫描
  17. } DeviceState;
  18. //雷达设备信息,
  19. typedef struct
  20. {
  21. uint8_t handle; //雷达控制句柄
  22. DeviceState device_state; //雷达设备状态
  23. DeviceInfo info; //雷达基本信息
  24. } DeviceItem;
  25. public:
  26. CLivoxLaser() = delete;
  27. CLivoxLaser(const CLivoxLaser& other) = delete;
  28. //唯一的构造函数,按照设备名称和雷达参数来创建实例。
  29. //input:id: 雷达设备的id,(唯一索引)
  30. //input:laser_param:雷达的参数,
  31. //注:利用protobuf创建 laser_parameter 类,然后从文件读取参数
  32. CLivoxLaser(int id, Laser_proto::laser_parameter laser_param);
  33. ~CLivoxLaser();
  34. //雷达链接设备,为3个线程添加线程执行函数。
  35. virtual Error_manager connect_laser();
  36. //雷达断开链接,释放3个线程
  37. virtual Error_manager disconnect_laser();
  38. //对外的接口函数,负责接受并处理任务单,
  39. //input:p_laser_task 雷达任务单,基类的指针,指向子类的实例,(多态)
  40. //注:这个函数为虚函数,实际的处理任务的代码由子类重载并实现。
  41. virtual Error_manager execute_task(Task_Base* p_laser_task);
  42. //检查雷达状态,是否正常运行
  43. virtual Error_manager check_laser();
  44. //雷达的启动接口函数, 让雷达进行扫描,一般需要子类重载,不同的雷达开始方式不同。
  45. virtual Error_manager start_scan();
  46. //雷达的停止接口函数, 让雷达停止扫描,一般需要子类重载,不同的雷达结束方式不同。
  47. virtual Error_manager stop_scan();
  48. //结束任务单,stop之后,要检查线程状态和数据结果,然后才能 end_task
  49. virtual Error_manager end_task();
  50. //取消任务单,由发送方提前取消任务单
  51. virtual Error_manager cancel_task();
  52. //判断雷达状态是否为待机,如果已经准备好,则可以执行任务。
  53. //子类重载 is_ready(),里面增加livox sdk后台线程状态的判断。
  54. virtual bool is_ready();
  55. protected:
  56. //接受二进制消息的功能函数,每次只接受一个CBinaryData
  57. // 纯虚函数,必须由子类重载,
  58. virtual bool receive_buf_to_queue(Binary_buf& binary_buf);
  59. //将二进制消息转化为三维点云的功能函数,每次只转化一个CBinaryData,
  60. // 纯虚函数,必须由子类重载,
  61. virtual Buf_type transform_buf_to_points(Binary_buf* p_binary_buf, std::vector<CPoint3D>& point3D_cloud);
  62. protected:
  63. static void InitLivox();
  64. virtual bool IsScanComplete();
  65. virtual void UpdataHandle();
  66. static void LidarDataCallback(uint8_t handle, LivoxEthPacket *data, uint32_t data_num, void *laser);
  67. static void OnDeviceChange(const DeviceInfo *info, DeviceEvent type);
  68. static void OnDeviceBroadcast(const BroadcastDeviceInfo *info);
  69. static void OnSampleCallback(uint8_t status, uint8_t handle, uint8_t response, void *data);
  70. protected:
  71. uint8_t m_handle;
  72. unsigned int m_frame_maxnum;
  73. Thread_safe_queue<Binary_buf*> m_queue_livox_data;
  74. static DeviceItem g_devices[kMaxLidarCount];
  75. static std::map<uint8_t,std::string> g_handle_sn;
  76. static std::map<std::string, uint8_t> g_sn_handle;
  77. static std::map<std::string, CLivoxLaser*> g_sn_laser;
  78. static CLivoxLaser* g_all_laser[kMaxLidarCount];
  79. static unsigned int g_count[kMaxLidarCount];
  80. };
  81. #endif