0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

YDLidar GS5をUbuntuで使用する

Posted at

はじめに

YDLidarを貸していただく機会があり、はじめてLidarに触れたためその手順を覚書としてまとめてみた。

環境

OS: Ubuntu 22.04.5 LTS
Python: Python 3.10.12

構築

ドライバのインストール

Esp32用のライブラリをインストールするのと同様の手順でインストールする。
認識しているか確認する際は、以下のコマンドを実行すれば良い。

$ lsusb -t
(前略)
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/9p, 480M
    |__ Port 2: Dev 2, If 2, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 2: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 2: Dev 2, If 1, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 3: Dev 5, If 0, Class=Vendor Specific Class, Driver=cp210x, 12M
    |__ Port 4: Dev 3, If 0, Class=Wireless, Driver=btusb, 12M
    |__ Port 4: Dev 3, If 1, Class=Wireless, Driver=btusb, 12M
    |__ Port 5: Dev 4, If 0, Class=Video, Driver=uvcvideo, 480M
    |__ Port 5: Dev 4, If 1, Class=Video, Driver=uvcvideo, 480M
(後略)

(Port 3がYDLidar GS5)

ファイルの入手

まず、cmakeをインストールする。

$ sudo apt install cmake pkg-config

次にpipをインストールする。

sudo apt install python3-pip

そして、SDKをダウンロードする。
今回はDcumentフォルダ直下に作成した。

$ cd ~/Document
$ git clone https://github.com/YDLIDAR/YDLidar-SDK.git

するとDocumentフォルダー直下にYDLidar-SDKというフォルダーが作成される。
以下のコマンドを実行していく。

$ cd ./YDLidar-SDK
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install

最後のコマンドでエラーが出力されなければ成功である。

動作テスト

このSDKにはテスト用のプログラムもあるので試してみよう。
以下のコマンドを実行するとテストできる。

$ cd YDLidar-SDK/build
$ ./gs_test

以下の出力を得る。

__   ______  _     ___ ____    _    ____  
\ \ / /  _ \| |   |_ _|  _ \  / \  |  _ \ 
 \ V /| | | | |    | || | | |/ _ \ | |_) | 
  | | | |_| | |___ | || |_| / ___ \|  _ <  
  |_| |____/|_____|___|____/_/   \_\_| \_\ 

[0] IP1 192.168.1.200
[1] ydlidar /dev/ttyS9
[2] ydlidar3 /dev/ttyUSB0
Please select the lidar port:2
Baudrate:
[0] 8000
[1] 921600
[2] 951600
Please select the lidar baudrate:1
[2025-08-01 10:20:19][info] SDK initializing
[2025-08-01 10:20:19][info] SDK has been initialized
[2025-08-01 10:20:19][info] SDK Version: 1.2.17
[2025-08-01 10:20:19][debug] [send] A5A5A5A500640000
[2025-08-01 10:20:19][debug] [send] 64
[2025-08-01 10:20:19][debug] [recv] A5A5A5A501640000
[2025-08-01 10:20:19][debug] [send] A5A5A5A500600000
[2025-08-01 10:20:19][debug] [send] 60
[2025-08-01 10:20:19][debug] [recv] A5A5A5A501600000
[2025-08-01 10:20:19][info] GS lidar count 1
[2025-08-01 10:20:19][info] Connect elapsed time 35 ms
[2025-08-01 10:20:19][info] Lidar successfully connected [/dev/ttyUSB0:921600]
[2025-08-01 10:20:19][info] Lidar running correctly! The health status good
[2025-08-01 10:20:19][debug] [send] A5A5A5A5006B0000
[2025-08-01 10:20:19][debug] [send] 6B
[2025-08-01 10:20:19][debug] [recv] 61A5A5A5A5016B14
[2025-08-01 10:20:19][debug] [recv] 00
[2025-08-01 10:20:19][debug] [recv] 0001003502000204010101010000000000000006
[2025-08-01 10:20:19][info] Get Module[0] Lidar model[53]
[2025-08-01 10:20:19][info] Current Lidar Model Code 53
[2025-08-01 10:20:19][info] Baseplate device info
Firmware version: 1.0
Hardware version: 0
Model: GS5
Serial: 2024111100000006
[2025-08-01 10:20:19][info] Check status, Elapsed time 1 ms
[2025-08-01 10:20:19][info] Lidar init success, Elapsed time [36]ms
[2025-08-01 10:20:19][debug] [send] A5A5A5A500640000
[2025-08-01 10:20:19][debug] [send] 64
[2025-08-01 10:20:19][debug] [recv] C8A5A5A5A5016400
[2025-08-01 10:20:19][debug] [recv] 00
[2025-08-01 10:20:19][debug] [send] A5A5A5A500610000
[2025-08-01 10:20:19][debug] [send] 61
[2025-08-01 10:20:19][debug] [recv] A5A5A5A501610900
[2025-08-01 10:20:19][debug] [recv] 8D00F8158D004B16F7EA
[2025-08-01 10:20:19][debug] [send] A5A5A5A500630000
[2025-08-01 10:20:19][debug] [send] 63
[2025-08-01 10:20:19][debug] [recv] A5A5A5A501630000
[2025-08-01 10:20:19][info] Create GS thread 0x63FF640
[2025-08-01 10:20:19][info] Successed to start scan mode, Elapsed time 78 ms
[2025-08-01 10:20:20][debug] [recv] 64A5A5A5A5016342
[2025-08-01 10:20:20][debug] [recv] 01
[2025-08-01 10:20:20][debug] [recv] 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000A7
[2025-08-01 10:20:20][debug] GS lidar module[0] model[53]
[2025-08-01 10:20:20][info] Scan Frequency: 8.00Hz
[2025-08-01 10:20:20][info] Fixed Size: 512
[2025-08-01 10:20:20][info] Sample Rate: 4.00K
[2025-08-01 10:20:20][info] Successed to check the lidar, Elapsed time 308 ms
(後略)

ydlidarの導入

ここからの手順が問題である。
私の環境では、公式の手順に従ってもうまく行かなかった。
以下の手順を踏むと成功したので紹介する。

まず、venvコマンドで仮想環境を作成する。

$ cd YDLidar-SDK
$ python3 -m venv venv_ydlidar
$ source venv_ydlidar/bin/activate

次にchownコマンドでファイルのオーナーとグループを変更する。

$ sudo chown (オーナー名):(グループ名) (ファイル名)

最後に以下のコマンドを実行し導入する。

$ python setup.py build
$ python setup.py install

最後のコマンドで、以下の出力があれば成功である。

(前略)
Installed /home/(ユーザー名)/Documents/YDLidar-SDK/venv_ydlidar/lib/python3.10/site-packages/ydlidar-1.2.4-py3.10-linux-x86_64.egg
Processing dependencies for ydlidar==1.2.4
Finished processing dependencies for ydlidar==1.2.4

動作テスト

以下のテスト要プログラムがあるので試してみよう。

$ cd ./python/examples/
$ python3 ./gs_test.py

以下の出力を得る。

/dev/ttyS9
/dev/ttyUSB0
[2025-08-01 10:25:35][info] SDK initializing
[2025-08-01 10:25:35][info] SDK has been initialized
[2025-08-01 10:25:35][info] SDK Version: 1.2.17
[2025-08-01 10:25:35][info] GS lidar count 1
[2025-08-01 10:25:35][info] Connect elapsed time 33 ms
[2025-08-01 10:25:35][info] Lidar successfully connected [/dev/ttyUSB0:921600]
[2025-08-01 10:25:35][info] Lidar running correctly! The health status good
[2025-08-01 10:25:35][info] Get Module[0] Lidar model[53]
[2025-08-01 10:25:35][info] Current Lidar Model Code 53
[2025-08-01 10:25:35][info] Baseplate device info
Firmware version: 1.0
Hardware version: 0
Model: GS5
Serial: 2024111100000006
[2025-08-01 10:25:35][info] Check status, Elapsed time 1 ms
[2025-08-01 10:25:35][info] Lidar init success, Elapsed time [34]ms
[2025-08-01 10:25:35][info] Create GS thread 0xCD7FF640
[2025-08-01 10:25:35][info] Successed to start scan mode, Elapsed time 78 ms
[2025-08-01 10:25:35][info] Scan Frequency: 30.00Hz
[2025-08-01 10:25:35][info] Fixed Size: 136
[2025-08-01 10:25:35][info] Sample Rate: 4.00K
[2025-08-01 10:25:35][info] Successed to check the lidar, Elapsed time 84 ms
[2025-08-01 10:25:35][info] Now lidar is scanning...
Scan received[ 1754011535980062000 ]: 160
(後略)

プログラムを作成してみる

GS5用のプロットプログラムがなかったため、作成してみた。

$ cd YDLidar-SDK/python
$ touch plot_gs_test.py
$ pip3 install matplotlib
plot_gs_test.py
import os
import ydlidar
import time
import sys
from matplotlib.patches import Arc
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np

RMAX = 32.0

fig = plt.figure()
fig.canvas.manager.set_window_title('YDLidar LIDAR Monitor')
lidar_polar = plt.subplot(polar=True)
lidar_polar.autoscale_view(True,True,True)
lidar_polar.set_rmax(RMAX)
lidar_polar.grid(True)

ydlidar.os_init();
ports = ydlidar.lidarPortList();
port = "/dev/ydlidar";
for key, value in ports.items():
    port = value;
    print(port);
laser = ydlidar.CYdLidar();
laser.setlidaropt(ydlidar.LidarPropSerialPort, port);
laser.setlidaropt(ydlidar.LidarPropSerialBaudrate, 921600);
laser.setlidaropt(ydlidar.LidarPropLidarType, ydlidar.TYPE_GS);
laser.setlidaropt(ydlidar.LidarPropDeviceType, ydlidar.YDLIDAR_TYPE_SERIAL);
laser.setlidaropt(ydlidar.LidarPropScanFrequency, 30.0);
laser.setlidaropt(ydlidar.LidarPropSampleRate, 20);
laser.setlidaropt(ydlidar.LidarPropSingleChannel, False);
laser.setlidaropt(ydlidar.LidarPropIntenstiy, True);
laser.setlidaropt(ydlidar.LidarPropMaxAngle, 180.0);
laser.setlidaropt(ydlidar.LidarPropMinAngle, -180.0);
laser.setlidaropt(ydlidar.LidarPropMaxRange, 50.0);
laser.setlidaropt(ydlidar.LidarPropMinRange, 0.01);
scan = ydlidar.LaserScan()

def animate(num):
    r = laser.doProcessSimple(scan);
    if r:
        angle = []
        ran = []
        intensity = []
        for point in scan.points:
            angle.append(point.angle);
            ran.append(point.range);
            intensity.append(point.intensity);
        lidar_polar.clear()
        lidar_polar.scatter(angle, ran, c=intensity, cmap='hsv', alpha=0.95)

ret = laser.initialize();
if ret:
    ret = laser.turnOn();
    if ret:
        ani = animation.FuncAnimation(fig, animate, interval=50)
        plt.show()
    laser.turnOff();
laser.disconnecting();
plt.close();

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?