コード例 #1
0
def start(port):
    global x, y
    for _ in range(360):
        x.append(0)
        y.append(0)

    Obj = PyLidar3.YdLidarG4(port)
    if (Obj.Connect()):
        print(Obj.GetDeviceInfo())
        gen = Obj.StartScanning()
        t = time.time()  # start time
        while (time.time() - t) < 30:  # scan for 30 seconds
            data = next(gen)
            for angle in range(0, 360):
                if (data[angle] > 1000):
                    x[angle] = data[angle] * math.cos(math.radians(angle))
                    y[angle] = data[angle] * math.sin(math.radians(angle))
            draw()
        plt.show()
        Obj.StopScanning()
        Obj.Disconnect()
    else:
        print("Error connecting to device")
コード例 #2
0
def runLidar(t_max):
    """
    Description: Establishes a serial connection with the LiDAR, starts scanning and returns the data

    :param t_max: Maximum run time
    :return raw_data: The raw data
    """
    lidar = PyLidar3.YdLidarG4(port)
    if lidar.Connect():
        print(lidar.GetDeviceInfo())
        gen = lidar.StartScanning()
        t1 = time.time()  # start time
        t2 = t1
        raw_data = []
        while t2 - t1 < t_max:
            d = next(gen)
            t2 = time.time()
            raw_data.append([t2, d])
        lidar.StopScanning()
        lidar.Disconnect()
        return raw_data
    else:
        print("Error connecting to device")
        return 0
コード例 #3
0
        plt.ylim(-9000, 9000)
        plt.xlim(-9000, 9000)
        plt.scatter(x, y, c='r', s=8)
        plt.pause(0.001)
    plt.close("all")


is_plot = True
x = []
y = []
for _ in range(360):
    x.append(0)
    y.append(0)

port = "/dev/ttyACM0"  #linux
Obj = PyLidar3.YdLidarG4(port)
threading.Thread(target=draw).start()
if (Obj.Connect()):
    print(Obj.GetDeviceInfo())
    gen = Obj.StartScanning()
    t = time.time()  # start time
    while (time.time() - t) < 30:  #scan for 30 seconds
        data = next(gen)
        for angle in range(0, 360):
            if (data[angle] > 1000):
                x[angle] = data[angle] * math.cos(math.radians(angle))
                y[angle] = data[angle] * math.sin(math.radians(angle))
    is_plot = False
    Obj.StopScanning()
    Obj.Disconnect()
else:
コード例 #4
0
        plt.ylim(-9000, 9000)
        plt.xlim(-9000, 9000)
        plt.scatter(x, y, c='r', s=8)
        plt.pause(0.001)
    plt.close("all")


is_plot = True
x = []
y = []
for _ in range(360):
    x.append(0)
    y.append(0)
port = "/dev/ttyUSB0"
#port =  input("Enter port name which lidar is connected:") #windows
Obj = PyLidar3.YdLidarG4(
    port)  #PyLidar3.your_version_of_lidar(port,chunk_size)
threading.Thread(target=draw).start()
if (Obj.Connect()):
    print(Obj.GetDeviceInfo())
    gen = Obj.StartScanning()
    t = time.time()  # start time
    while (time.time() - t) < 60:  #scan for 30 seconds
        data = next(gen)
        for angle in range(0, 360):
            if (data[angle] > 1000):
                x[angle] = data[angle] * math.cos(math.radians(angle))
                y[angle] = data[angle] * math.sin(math.radians(angle))
    is_plot = False
    Obj.StopScanning()
    Obj.Disconnect()
else: