python - 使用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 端口。如何解决这个错误?
解决方案
显然,激光雷达连接到的 COM 端口与本示例中的端口不同。您需要更改此行中的第一个参数:
lidar = RPLidar('COM5', baudrate=115200)
您可以在 Windows 设备管理器中找到它使用的端口。
推荐阅读
- ios - 我的视频离开屏幕,但留在它的 UIView
- incoming-mail - Google 使用哪些国家/地区发送 Google Mail?
- angular - @Input 父子组件绑定
- python - 将 numpy 数组转换为迭代器
- java - Android 在后台使用字符串压缩吗?
- pyspark-sql - 在 Pyspark SQL 中执行多个 SQL 代码
- reactjs - 错误:纱线启动 - 错误命令“start”未找到
- javascript - 如果条件没有给出预期的结果
- haskell - 如何在具有自定义类型类约束的 GADT 上实现 fromJSON?
- dataset - 如何将数据从每 10 行移动到单行?