1、Preparation

1、Install SDK

Extract the YDLidar-SDK.rar file in the folder to get a file YDLidar-SDK. Copy the file to your own file directory.

Take the installation in the/home directory as an example, and then enter it in sequence.

2、Compile ROS function package

ROS1

Extract the ydlidar in the folder_ ros_ Driver.rar file, get a file ydlidar_ ros_ Driver, copy the function package to the src directory of the created workspace, open the terminal in the workspace, and enter the following command.

For ROS1:

ROS2

Extract the ydlidar in the folder_ ros2_ Driver.rar file, get a file ydlidar_ ros2_ Driver, copy the function package to the src directory of the created workspace, open the terminal in the workspace, and enter the following command.

For ROS2:

3、Create a serial port alias

In order to prevent identification errors when multiple USB devices are connected. We create a module serial port alias.

~/catkin_ ws/src/ydlidar_ ros_ The driver is the location where the function package is installed, which needs to be modified according to the actual situation. Note: After completing the previous operation, please re-insert the module . Input the following command to check whether the recognition is created successfully,

If the following screen appears, it means success.

image-20230218123235670

Note: This is not necessarily ttyUSB0, but the serial number assigned by the system identification

4、Run code

Enter the following command.

ROS1

After successful operation, the terminal displays as follows.

image-20230218122612156

Enter the following command to view the specific data.

image-20230218122744990

The data in ranges is the actual measured distance, in meters.

ROS2

After successful operation, the terminal displays as follows.

image-20230220165201352

Enter the following command to view the specific data.

image-20230220165704549

The data in ranges is the actual measured distance, in meters.