/* * livox_driver 大疆雷达的底层驱动 * * 本模块作为单例模式,全局使用. * 负责通过调用livox sdk,与livox的后台进行进行对接. 直接控制大疆的雷达设备. * * * 注:sn码就是 broadcast_code 广播码, 设备识别码,在链接设备的时候使用. * * */ #ifndef __LIVOX_DRIVER_H #define __LIVOX_DRIVER_H #include "Laser.h" #include "LivoxLaser.h" #include "livox_def.h" #include "livox_sdk.h" #include #include "../tool/singleton.h" #include "../error_code/error_code.h" //livox_driver 大疆雷达的底层驱动 class Livox_driver :public Singleton { // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。 friend class Singleton; private: // 父类的构造函数必须保护,子类的构造函数必须私有。 Livox_driver(); public://API functions Livox_driver(const Livox_driver&)=delete; Livox_driver& operator =(const Livox_driver&)= delete; ~Livox_driver(); //livox雷达驱动初始化. Error_manager Livox_driver_init(bool aoto_create_livox_flag = false); //livox雷达驱动反初始化. Error_manager Livox_driver_uninit(); //插入广播码和雷达实例的映射表 Error_manager Livox_insert_sn_laser(std::string sn, CLivoxLaser* p_livox_laser); //判断 Livox_driver 模块是否正常, 只有正常之后,才能启动或者停止扫描. bool is_ready(); //判断是否自动创建雷达,默认为false bool is_aoto_create_livox(); //雷达驱动层开始取样. Error_manager Livox_driver_start_sample(uint8_t handle); //雷达驱动层停止取样. Error_manager Livox_driver_stop_sample(uint8_t handle); //设备广播的回调函数,在 Livox_driver_init 时使用 SetBroadcastCallback() 进行配置. //局域网内的所有livox雷达在收到广播之后,都会调用本函数. //本函数由livox后台线程来执行. 每个雷达调用一次. static void livox_device_broadcast_callback(const BroadcastDeviceInfo *info); //雷达设备状态改变的回调函数,在 Livox_driver_init 时使用 SetDeviceStateUpdateCallback() 来进行配置 //雷达设备建立连接或者断开连接,都会调用 livox_device_change_callback 来通知我们雷达状态的改变. //本函数由livox后台线程来执行. 每个雷达可能调用多次. static void livox_device_change_callback(const DeviceInfo *info, DeviceEvent type); //获取欧拉角(笛卡尔坐标)的回调函数。在 livox_device_change_callback 连接成功之后使用 LidarGetExtrinsicParameter 来设置回调函数。 //雷达接受到查询指令后,会调用 livox_get_extrinsic_parameter_callback 来返回 LidarGetExtrinsicParameterResponse 的指针. 里面就有 欧拉角(笛卡尔坐标) //本函数由livox后台线程来执行. 每个雷达只需要调用一次. static void livox_get_extrinsic_parameter_callback(uint8_t status, uint8_t handle, LidarGetExtrinsicParameterResponse *response, void *client_data); //雷达设备数据返回 的回调函数. 在 livox_device_broadcast_callback 连接成功之后使用 SetDataCallback 来设置回调函数。 //雷达在调用 LidarStartSampling 开始扫描之后,就一直调用 livox_data_callback 来返回数据. //雷达在调用 LidarStopSampling 停止扫描之后,就停止扫描.本函数也会停止调用. //本函数由livox后台线程来执行. 每帧数据都会调用一次. data里面有多个三维点. static void livox_data_callback(uint8_t handle, LivoxEthPacket *data, uint32_t data_num, void *laser); //雷达设备启动扫描的回调函数, 在 CLivoxLaser::start_scan() 需要启动扫描的时候使用 LidarStartSampling 来设置回调函数。 //调用 LidarStartSampling 之后,livox后台进程就直接开始扫描了. 之后就会一直调用 livox_data_callback 来返回数据 static void livox_start_sample_callback(uint8_t status, uint8_t handle, uint8_t response, void *data); //雷达设备启动扫描的回调函数, 在 CLivoxLaser::stop_scan() 或者其他位置 需要停止的时候使用 LidarStopSampling 来设置回调函数。 //调用 LidarStopSampling 之后,livox后台进程就直接停止扫描了. 也会停止调用 livox_data_callback static void livox_stop_sample_callback(uint8_t status, uint8_t handle, uint8_t response, void *data); public://get or set member variable protected://member variable bool m_init_flag; //是否初始化的标记位. bool m_aoto_create_livox_flag; //自动创建雷达 // 注:livox大疆雷达允许先初始化Livox_driver,然后在局域网连接所有的livox设备之后,再根据连接数量去创建雷达实例对象 std::map m_sn_laser_map; //广播码和雷达实例的映射表. CLivoxLaser*内存由laser_manager管理 std::map m_handle_laser_map; //句柄和雷达实例的映射表. CLivoxLaser*内存由laser_manager管理 private: }; #endif //__LIVOX_DRIVER_H