# cpp_perception_engine **Repository Path**: dfhhdq/cpp_perception_engine ## Basic Information - **Project Name**: cpp_perception_engine - **Description**: 中海油的程序,包含激光雷达采集,模型推理,雷达点云处理,与前端接口对接 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-21 - **Last Updated**: 2026-09-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # C++ Perception Engine README ## 多激光雷达启动方式 当前代码已经按“一个进程、一个 HTTP 服务、多个独立雷达会话”的方式实现多雷达兼容。正常情况下,接入多个激光雷达设备不需要改代码,只需要启动一次 `perception_engine.exe`,然后针对每个物理雷达分别调用一次 `POST /engine/session/start`。 ### 1. 程序启动 进程启动时只加载全局配置并启动 HTTP 服务,不会立刻连接雷达。 ```powershell D:\demo\cpp_perception_engine\build\windows\x64\release\perception_engine.exe D:\demo\cpp_perception_engine\config\engine_config.json ``` 默认 HTTP 地址: ```text http://127.0.0.1:9100 ``` `engine_config.json` 主要用于配置进程级参数,例如 HTTP 端口、日志目录、模型默认路径、全局雷达兜底 IP、碰撞默认阈值等。 ### 2. 启动多个雷达会话 每个雷达启动一个独立 session。`session_id` 必须唯一;`lidar.lidar_id` 也必须唯一。如果没有传 `lidar_id`,程序会用 `lidar.ip` 作为物理雷达唯一键。 示例:启动一号雷达。 ```powershell $body = @' { "request_id": "REQ_LIDAR_01", "session_id": "session_lidar_01", "camera": { "camera_id": "camera_lidar_01", "name": "camera lidar 01", "type": "rtsp", "url": "", "width": 2448, "height": 1736, "fps": 25 }, "lidar": { "lidar_id": "lidar_01", "name": "一号雷达", "type": "3d_lidar", "ip": "192.168.1.64", "port": 2368, "frame_rate": 10 }, "model": { "model_id": "person_seg", "model_path": "D:\\demo\\cpp_perception_engine\\model\\yolov8m-seg.engine", "backend": "tensorrt", "precision": "fp16", "confidence_threshold": 0.45, "nms_threshold": 0.5 }, "collision_config": { "collision_class_pairs": [[0, 1], [0, 2], [1, 2]], "detection_start": "00:00", "detection_end": "23:59", "minimum_alarm_level": "warning", "alarm_interval_sec": 60, "person_person": { "enabled": true, "warning_distance_m": 2.0, "danger_distance_m": 1.2, "emergency_distance_m": 0.6, "ttc_warning_s": 5.0, "ttc_danger_s": 3.0, "ttc_emergency_s": 1.0 } }, "callback": { "backend_ws_url": "ws://127.0.0.1:8000/ws/engine/lidar_01", "backend_event_url": "" } } '@ Invoke-RestMethod -Method Post -Uri http://127.0.0.1:9100/engine/session/start -ContentType "application/json" -Body $body ``` 示例:启动二号雷达。重点是换掉 `session_id`、`camera_id`、`lidar_id`、`lidar.ip` 和回调地址。 ```powershell $body = @' { "request_id": "REQ_LIDAR_02", "session_id": "session_lidar_02", "camera": { "camera_id": "camera_lidar_02", "name": "camera lidar 02", "type": "rtsp", "url": "", "width": 2448, "height": 1736, "fps": 25 }, "lidar": { "lidar_id": "lidar_02", "name": "二号雷达", "type": "3d_lidar", "ip": "192.168.1.65", "port": 2368, "frame_rate": 10 }, "model": { "model_id": "person_seg", "model_path": "D:\\demo\\cpp_perception_engine\\model\\yolov8m-seg.engine", "backend": "tensorrt", "precision": "fp16", "confidence_threshold": 0.45, "nms_threshold": 0.5 }, "collision_config": { "collision_class_pairs": [[0, 1], [0, 2], [1, 2]], "detection_start": "00:00", "detection_end": "23:59", "minimum_alarm_level": "warning", "alarm_interval_sec": 60, "person_person": { "enabled": true, "warning_distance_m": 2.0, "danger_distance_m": 1.2, "emergency_distance_m": 0.6, "ttc_warning_s": 5.0, "ttc_danger_s": 3.0, "ttc_emergency_s": 1.0 } }, "callback": { "backend_ws_url": "ws://127.0.0.1:8000/ws/engine/lidar_02", "backend_event_url": "" } } '@ Invoke-RestMethod -Method Post -Uri http://127.0.0.1:9100/engine/session/start -ContentType "application/json" -Body $body ``` 启动成功后,响应中的 `engine_id` 会带上雷达 ID,例如: ```json { "code": 0, "message": "session started", "data": { "session_id": "session_lidar_02", "engine_id": "engine_01:lidar_02", "status": "running" } } ``` ### 3. 多雷达运行时的隔离关系 每个 session 都会创建一个独立的 `PerceptionEngine` 实例。每个实例拥有自己的: - 雷达采集线程 `lidarCaptureLoop` - 主处理线程 `engineLoop` - 报警素材存储线程 `alarmStorageLoop` - 当前配置快照 - WebSocket 客户端 - 碰撞结果和报警去重缓存 - 报警图片、点云保存队列 多个实例共享的是: - 同一个 HTTP 服务端口 - 同一个 Boost.Asio `io_context` - 同一个进程级日志系统 - 同一个模型文件路径,除非每个 session 在请求里指定不同模型路径 ### 4. 唯一性和防重复启动 `PerceptionEngineManager` 会阻止以下情况: - 同一个 `session_id` 重复启动 - 同一个 `lidar_id` 被多个 session 同时占用 - 没有 `lidar_id` 时,同一个 `lidar.ip` 被多个 session 同时占用 如果重复启动,会返回 `session start failed`,日志里会出现类似: ```text Session session_lidar_01 already exists or is starting LiDAR lidar_01 is already used or starting ``` ### 5. 查询和停止指定雷达 查询指定 session: ```powershell Invoke-RestMethod -Method Get -Uri "http://127.0.0.1:9100/engine/status?session_id=session_lidar_01" ``` 查看进程总状态和当前会话数量: ```powershell Invoke-RestMethod -Method Get -Uri "http://127.0.0.1:9100/engine/health" ``` 停止一号雷达,不影响二号雷达: ```powershell $body = '{"session_id":"session_lidar_01","reason":"manual_stop"}' Invoke-RestMethod -Method Post -Uri http://127.0.0.1:9100/engine/session/stop -ContentType "application/json" -Body $body ``` ### 6. 当前需要注意的限制 一般多雷达不需要改代码,但下面几类场景可能需要扩展代码: - 不同雷达需要不同的标定文件:当前目标点云生成使用的是全局 `global_config_.lidar_calib_xml`,不是每个 session 单独配置。 - 不同雷达深度分辨率不同:当前 `CreateInterface()` 使用全局 `depth_width` 和 `depth_height`。 - 单 GPU 同时跑多个 YOLO/TensorRT 实例时,显存和推理吞吐可能成为瓶颈,需要按实际硬件压测。 - 如果多个雷达回调到同一个后端 WebSocket,后端需要按 `engine_id` 或 `session_id` 区分来源。 如果多个雷达型号、深度尺寸和标定文件完全一致,只是 IP 不同,通常只需要按上面的方式发多次启动请求即可。