hdy 1 год назад
Родитель
Сommit
a1f8abe8d5
2 измененных файлов с 91 добавлено и 15 удалено
  1. 70 0
      README.md
  2. 21 15
      rblidar.py

+ 70 - 0
README.md

@@ -0,0 +1,70 @@
+# LakiBeam SDK - Linux C/Python Hybrid programming radar data interface
+
+## Project profile
+
+LakiBeam SDK is a Linux-based cross-language (C/Python) radar data receiving and processing library designed for real-time radar data acquisition and processing.
+
+## Characteristics
+
+- Low-level implementation of C language in pure Linux environment
+
+- Python dynamic library call mechanism
+
+- UDP receives network data in real time
+
+- Multi-threaded data processing
+
+- Dual buffer design to improve data throughput
+
+## Environmental dependence
+
+- Linux
+- GCC compiler
+- Python 3.x
+
+## Dependency library
+
+- ctypes
+- numpy
+- matplotlib
+
+### Installing
+
+You can install ctypes、numpy and matplotlib using `pip`:
+
+```sh
+$ pip install ctypes numpy matplotlib
+```
+
+Or for Python 3:
+```sh
+$ sudo pip3 install ctypes numpy matplotlib
+```
+
+## Compile and build
+
+### Makefile
+
+The project provides makefiles to simplify the compilation and build process:
+
+# Common command
+make                # 编译C库
+make clean          # 清理编译产生的文件
+python3 rblidar.py  # 编译Python接口测试  
+
+## Troubleshooting
+· Ensure all dependencies are installed
+· Check library path and permissions
+· Verify network configuration for UDP communication
+
+## Usage example
+
+from rblidar import RBLidar
+
+def data_callback(data, length):
+    print(f"Received data, length: {length}")
+
+lidar = RBLidar("192.168.8.1", 2368, frame_callback=data_callback)
+
+
+

+ 21 - 15
rblidar.py

@@ -47,17 +47,17 @@ point_data_dtype = np.dtype([
     ('timestamp', np.uint32)
 ])
 
-# 加载C库
-rblidar_lib = ctypes.CDLL('./rb_lidar.so')  # 确保路径正确
 
-# 定义回调函数类型
+rblidar_lib = ctypes.CDLL('./rb_lidar.so')  
+
+
 CALLBACK_TYPE = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int)
 
 def my_callback(data, length):
     logging.info("Received length: %d", length)
     byte_data = ctypes.string_at(data, length)
 
-    # 将接收到的字节数组转换为 NumPy 数组
+
     point_data_array = np.frombuffer(byte_data, dtype=point_data_dtype)
 
     for point in point_data_array:
@@ -66,28 +66,34 @@ def my_callback(data, length):
     # 绘制点云
     # plot_point_cloud(point_data_array)
 
-        # 在这里添加您的处理逻辑
-        # 例如,您可以将数据存储到文件或数据库中
 
 class RBLidar:
-    def __init__(self, ip: str, port: int):
-        # 初始化日志记录
+    def __init__(self, ip: str, port: int, frame_callback=None):
         logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s')
 
-        # 创建回调函数
-        self.callback = CALLBACK_TYPE(my_callback)
-        # 创建C库中的RBLidar实例
+        # self.callback = CALLBACK_TYPE(my_callback)
+
+        self.frame_callback = frame_callback
+        self.callback = CALLBACK_TYPE(self._callback_wrapper)
+  
         self.lidar = rblidar_lib.rblidar_create(ip.encode('utf-8'), port, self.callback)
 
+    def _callback_wrapper(self,data,length):
+        my_callback(data, length)
+
+        if self.frame_callback:
+            self.frame_callback(data,length)
+
     def __del__(self):
-        # 清理资源
         rblidar_lib.rblidar_destroy(self.lidar)
 
-# 示例使用
+
 if __name__ == "__main__":
-    lidar = RBLidar("192.168.8.1", 2368)  # 替换为实际的IP和端口
+    def my_frame_callback(data, length):
+        logging.info("Frame callback processing data")
+    lidar = RBLidar("192.168.8.1", 2368,frame_callback=my_frame_callback) 
     try:
         while True:
-            pass  # 持续运行以接收数据
+            pass 
     except KeyboardInterrupt:
         logging.info("Stopping...")