import rplidar import numpy as np import pyqtgraph.opengl as gl import sys from PyQt5.QtWidgets import * class LidarScanner(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): # Lidar cihazını başlat self.lidar = rplidar.RPLidar('/dev/ttyUSB0') # OpenGL grafik arayüzünü oluştur self.view = gl.GLViewWidget() self.view.opts['distance'] = 40 self.view.show() # Veri dizisi self.pos = np.zeros((360, 3)) # 3D eksenlerini çiz glAxis = gl.GLAxisItem() self.view.addItem(glAxis) # Tarama döngüsü for scan in self.lidar.iter_scans(): # Veri al for (_, angle, distance) in scan: # Veriyi dönüştür x = distance * np.cos(np.radians(angle)) y = distance * np.sin(np.radians(angle)) z = 0 # Veriyi güncelle self.pos[angle] = [x, y, z] # Veriyi görselleştir self.view.addItem(gl.GLLinePlotItem(pos=self.pos, mode='line_strip')) QApplication.processEvents() def closeEvent(self, event): self.lidar.stop() self.lidar.stop_motor() self.lidar.disconnect() event.accept() if __name__ == '__main__': app = QApplication(sys.argv) ex = LidarScanner() sys.exit(app.exec_())