livox_driver.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * livox_driver 大疆雷达的底层驱动
  3. *
  4. * 本模块作为单例模式,全局使用.
  5. * 负责通过调用livox sdk,与livox的后台进行进行对接. 直接控制大疆的雷达设备.
  6. *
  7. *
  8. * 注:sn码就是 broadcast_code 广播码, 设备识别码,在链接设备的时候使用.
  9. *
  10. *
  11. */
  12. #ifndef __LIVOX_DRIVER_H
  13. #define __LIVOX_DRIVER_H
  14. #include "Laser.h"
  15. #include "LivoxLaser.h"
  16. #include "livox_def.h"
  17. #include "livox_sdk.h"
  18. #include <map>
  19. #include "../tool/singleton.h"
  20. #include "../error_code/error_code.h"
  21. //livox_driver 大疆雷达的底层驱动
  22. class Livox_driver :public Singleton<Livox_driver>
  23. {
  24. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  25. friend class Singleton<Livox_driver>;
  26. private:
  27. // 父类的构造函数必须保护,子类的构造函数必须私有。
  28. Livox_driver();
  29. public://API functions
  30. Livox_driver(const Livox_driver&)=delete;
  31. Livox_driver& operator =(const Livox_driver&)= delete;
  32. ~Livox_driver();
  33. //livox雷达驱动初始化.
  34. Error_manager Livox_driver_init(bool aoto_create_livox_flag = false);
  35. //livox雷达驱动反初始化.
  36. Error_manager Livox_driver_uninit();
  37. //插入广播码和雷达实例的映射表
  38. Error_manager Livox_insert_sn_laser(std::string sn, CLivoxLaser* p_livox_laser);
  39. //判断 Livox_driver 模块是否正常, 只有正常之后,才能启动或者停止扫描.
  40. bool is_ready();
  41. //判断是否自动创建雷达,默认为false
  42. bool is_aoto_create_livox();
  43. //雷达驱动层开始取样.
  44. Error_manager Livox_driver_start_sample(uint8_t handle);
  45. //雷达驱动层停止取样.
  46. Error_manager Livox_driver_stop_sample(uint8_t handle);
  47. //设备广播的回调函数,在 Livox_driver_init 时使用 SetBroadcastCallback() 进行配置.
  48. //局域网内的所有livox雷达在收到广播之后,都会调用本函数.
  49. //本函数由livox后台线程来执行. 每个雷达调用一次.
  50. static void livox_device_broadcast_callback(const BroadcastDeviceInfo *info);
  51. //雷达设备状态改变的回调函数,在 Livox_driver_init 时使用 SetDeviceStateUpdateCallback() 来进行配置
  52. //雷达设备建立连接或者断开连接,都会调用 livox_device_change_callback 来通知我们雷达状态的改变.
  53. //本函数由livox后台线程来执行. 每个雷达可能调用多次.
  54. static void livox_device_change_callback(const DeviceInfo *info, DeviceEvent type);
  55. //获取欧拉角(笛卡尔坐标)的回调函数。在 livox_device_change_callback 连接成功之后使用 LidarGetExtrinsicParameter 来设置回调函数。
  56. //雷达接受到查询指令后,会调用 livox_get_extrinsic_parameter_callback 来返回 LidarGetExtrinsicParameterResponse 的指针. 里面就有 欧拉角(笛卡尔坐标)
  57. //本函数由livox后台线程来执行. 每个雷达只需要调用一次.
  58. static void livox_get_extrinsic_parameter_callback(uint8_t status,
  59. uint8_t handle,
  60. LidarGetExtrinsicParameterResponse *response,
  61. void *client_data);
  62. //雷达设备数据返回 的回调函数. 在 livox_device_broadcast_callback 连接成功之后使用 SetDataCallback 来设置回调函数。
  63. //雷达在调用 LidarStartSampling 开始扫描之后,就一直调用 livox_data_callback 来返回数据.
  64. //雷达在调用 LidarStopSampling 停止扫描之后,就停止扫描.本函数也会停止调用.
  65. //本函数由livox后台线程来执行. 每帧数据都会调用一次. data里面有多个三维点.
  66. static void livox_data_callback(uint8_t handle, LivoxEthPacket *data, uint32_t data_num, void *laser);
  67. //雷达设备启动扫描的回调函数, 在 CLivoxLaser::start_scan() 需要启动扫描的时候使用 LidarStartSampling 来设置回调函数。
  68. //调用 LidarStartSampling 之后,livox后台进程就直接开始扫描了. 之后就会一直调用 livox_data_callback 来返回数据
  69. static void livox_start_sample_callback(uint8_t status, uint8_t handle, uint8_t response, void *data);
  70. //雷达设备启动扫描的回调函数, 在 CLivoxLaser::stop_scan() 或者其他位置 需要停止的时候使用 LidarStopSampling 来设置回调函数。
  71. //调用 LidarStopSampling 之后,livox后台进程就直接停止扫描了. 也会停止调用 livox_data_callback
  72. static void livox_stop_sample_callback(uint8_t status, uint8_t handle, uint8_t response, void *data);
  73. public://get or set member variable
  74. protected://member variable
  75. bool m_init_flag; //是否初始化的标记位.
  76. bool m_aoto_create_livox_flag; //自动创建雷达
  77. // 注:livox大疆雷达允许先初始化Livox_driver,然后在局域网连接所有的livox设备之后,再根据连接数量去创建雷达实例对象
  78. std::map<std::string, CLivoxLaser*> m_sn_laser_map; //广播码和雷达实例的映射表. CLivoxLaser*内存由laser_manager管理
  79. std::map<uint8_t, CLivoxLaser*> m_handle_laser_map; //句柄和雷达实例的映射表. CLivoxLaser*内存由laser_manager管理
  80. private:
  81. };
  82. #endif //__LIVOX_DRIVER_H