GrabBag/Device/RsLidarDevice/Inc/IRsLidarDevice.h

129 lines
4.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef IRSLIDARDEVICE_H
#define IRSLIDARDEVICE_H
#include <functional>
#include <string>
#include "RsLidarDevice_global.h"
// ============================================================
// 自定义数据类型 — 完全不依赖 rs_driver SDK
// 使用内置类型(unsigned char/short/int)替代 stdint.h
// 以避免跨编译器的头文件兼容性问题
// ============================================================
/// 单个点 (x/y/z/intensity),与 SDK PointXYZI 内存布局一致
/// SDK 使用 #pragma pack(1)sizeof=13此处必须严格对齐
#pragma pack(push, 1)
struct RsPointXYZI
{
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
unsigned char intensity = 0;
};
#pragma pack(pop)
/// 一帧完整点云数据(指针指向内部缓冲区,仅在回调期间有效)
struct RsPointCloudData
{
unsigned int seq = 0; ///< 帧序号(单调递增)
double timestamp = 0.0; ///< 帧时间戳(秒)
unsigned int height = 0; ///< 激光线数
unsigned int width = 0; ///< 每线点数
bool isDense = false; ///< 是否丢弃了 NaN 点
std::string frameId; ///< 帧标识
unsigned int pointCount = 0; ///< 点数
const RsPointXYZI* points; ///< 指向内部点数组,回调返回后失效
};
/// 原始数据包信息is_frame_begin=1 表示新一圈扫描起始)
struct RsPacketInfo
{
double timestamp = 0.0;
unsigned int seq = 0;
unsigned char is_difop = 0;
unsigned char is_frame_begin = 0; ///< =1 新一帧扫描开始
std::string frameId;
unsigned int dataSize = 0; ///< 原始数据字节数
};
/// 异常/错误信息
struct RsExceptionInfo
{
int code = 0;
std::string message;
};
/// LiDAR 配置参数
struct RsLidarConfig
{
std::string lidarType = "RSEM4"; ///< 雷达型号
std::string hostAddress = "0.0.0.0"; ///< 主机地址
unsigned short msopPort = 6699; ///< MSOP 数据端口
unsigned short difopPort = 7788; ///< DIFOP 数据端口
unsigned short imuPort = 0; ///< IMU 端口 (0=禁用)
float minDistance = 0.0f; ///< 最小距离(米) 0=不限
float maxDistance = 0.0f; ///< 最大距离(米) 0=不限
bool densePoints = false; ///< 丢弃 NaN 点
bool useLidarClock = false; ///< 使用雷达内部时钟
bool tsFirstPoint = false; ///< 时间戳取首点时刻
bool waitForDifop = false; ///< 等待 DIFOP 包
float startAngle = 0.0f; ///< 有效角度起始(度)
float endAngle = 360.0f; ///< 有效角度结束(度)
float splitAngle = 0.0f; ///< 帧分割角度(度)
std::string frameId = "rslidar"; ///< 帧标识字符串
};
// ============================================================
// 抽象接口
// ============================================================
class RSLIDARDEVICE_EXPORT IRsLidarDevice
{
public:
using PointCloudCallback = std::function<void(const RsPointCloudData&)>;
using PacketCallback = std::function<void(const RsPacketInfo&)>;
using ExceptionCallback = std::function<void(const RsExceptionInfo&)>;
virtual ~IRsLidarDevice() = default;
/// 工厂方法
static int CreateObject(IRsLidarDevice** ppDevice);
/// 初始化 SDK 环境WSAStartup 等)
virtual int InitDevice() = 0;
/// 配置并打开设备
virtual int OpenDevice(const RsLidarConfig& config) = 0;
/// 关闭设备
virtual int CloseDevice() = 0;
/// 设备是否已打开
virtual bool IsOpened() const = 0;
/// 开始接收数据
virtual int Start() = 0;
/// 停止接收数据
virtual int Stop() = 0;
/// 是否正在运行
virtual bool IsRunning() const = 0;
/// 注册点云回调(每次回调 = 完整一圈扫描)
virtual int SetPointCloudCallback(PointCloudCallback callback) = 0;
/// 注册数据包回调is_frame_begin 标记帧起始)
virtual int SetPacketCallback(PacketCallback callback) = 0;
/// 注册异常回调
virtual int SetExceptionCallback(ExceptionCallback callback) = 0;
/// 获取驱动版本
virtual std::string GetVersion() = 0;
};
#endif // IRSLIDARDEVICE_H