首页 > 解决方案 > 使用python获取实时激光雷达数据

问题描述

我尝试了此代码以供参考。我从 stackoverflow 中提出的问题中得到了这段代码。我使用了 RPLIDAR A1M8 传感器。

import numpy as np    
import matplotlib.pyplot as plt      
from rplidar import RPLidar

def get_data():    
    lidar = RPLidar('COM5', baudrate=115200)
    for scan in lidar.iter_scans(max_buf_meas=500):    
        break    
        lidar.stop()    
    return scan

for i in range(1000000):    
    if(i%7==0):    
        x = np.radians([])   
        y = []    
    print(i)    
    current_data=get_data()    
    for point in current_data:    
        if point[0]==15:    
            x.append(point[2]*np.sin(point[1]))    
            y.append(point[2]*np.cos(point[1]))    
    plt.clf()    
    plt.scatter(x, y)    
    plt.pause(.1)    
plt.show()

当我运行代码时,它显示:无法连接到 com 端口。如何解决这个错误?

标签: pythonmatplotlibreal-timesensorslidar

解决方案


显然,激光雷达连接到的 COM 端口与本示例中的端口不同。您需要更改此行中的第一个参数:

lidar = RPLidar('COM5', baudrate=115200)

您可以在 Windows 设备管理器中找到它使用的端口。


推荐阅读